Call "canister_status" from Rust agent

Hi, I would like to gather info from my canisters using the Rust agent by calling canister_status using the management canister but here is what I get as a response :

`The replica returned an HTTP Error: Http Error: status 404 Not Found, content type “text/html”, content:

404 Not Found

404 Not Found


nginx/1.21.3 `

Using the interface spec from here :

canister_status : (record {canister_id : principal}) → (record {
status : variant { running; stopping; stopped };
settings: definite_canister_settings;
module_hash: opt blob;
memory_size: nat;
cycles: nat;
});

let management_canister_id = Principal::from_text("aaaaa-aa")?;
// Address is actually a different valid one on the ic.
let arg = Encode!( &Canister { canister_id: Principal::from_text("rrkah-fqaaa-aaaaa-aaaaq-cai") } )?;

agent
    .update(&management_canister_id, "canister_status")
     .with_arg(&arg)
     .call_and_wait(self.waiter.clone())
     .await?;

I’ve seen an example using JS, but does anyone managed to make it work with the Rust agent ?

(Sorry for the formatting, I have no idea to make it pretty looking for code snippet)

1 Like

OK, I managed to get one step further by using the method with_effective_canister_id while building my update call using the agent and now I get this in return :

The replica returned an HTTP Error: Http Error: status 403 Forbidden, content type “application/cbor”, content: Only controllers of canister *****-taaaa-aaaae-aag7a-cai can call ic00 method canister_status

I am the controller of this one. I wonder what I’m missing here :thinking:

hummm I’ve tried with canister_status from ic_utils but I get the same error message about not being a controller.

So, I got it working !!

In order to work, the canister needs to have the principal-id as a controller and not only the wallet-id as needed with dfx 0.8.4.

I hope it will help someone else :sweat_smile:

1 Like