How to receive response on cumulocity of a api

What product/components do you use and which version/fix level?

1011.0.12

Are you using a free trial or a product with a customer license?

What are trying to achieve? Please describe in detail.

Using shell i am sending string and receiving this string on my application via mqtt after receiving string on my application i want to see a response on cumulocity whether
like success response or any error.
please guid me with some example how can i see any api response on cumulocity ?

Do you get any error messages? Please provide a full error message screenshot and log file.

Have you installed latest fixes for the products

Hi Sumit,

have a look here: SmartREST - Cumulocity IoT Guides
You receive a messsage/Operation via MQTT so what you have to do is actually setting the status to EXECUTING, FAILED, SUCCESSUFL by sending 501 (Executing), 502 (Failed) or 503 (Successful)

All of them must contain the Fragment of the Operation you’ve created in Cumulocity. So if you use Remote Shell this is ‘c8y_Command’
As an example for Shell Command the messages should look like:

  • 501,c8y_Command
  • 502,c8y_Commands,Failed because of unknown command
  • 503,c8y_Command,{{result of you command}} → in my example the show help response text.

The result is shown in the shell tab of Device Management.

In Device Control in Device Management Application you can see the lifecycle of all operations.

1 Like

take a look of attached image here why status showing in pending and device is offline and nothing is in response?

Hi Sumit,

because your device/application is not subscribed to the “s/ds” topic (SmartREST - Cumulocity IoT Guides) and/or the device is not handling the message SmartREST - Cumulocity IoT Guides.
So it doesn’t send 501, 502 or 503 back to the platform. The Operation will always be “PENDING” when created in the platform but not handled by any device.

As soon the device comes back online (connect via MQTT and subscribe to topic s/ds) it will receive the message “511,c8y_Command,command” which then can be handled and send back one of the above lifecycle messages to the platform.

thank for your support
I will follow the Guide

1 Like

for using templates 501,502,503
can you provide me some example for these how response will look like with these templates in cumulocity , please guide me with some example

how i can send response using these templates on that perticular device .
i am sending some msg from cumulocity shell and then receiving thse msg at my application and calling api from that application now i want to send some to cumulocity Either success or fail but am confused how i can send this api response on at perticular device in cumulocity help me with some example or guide?


i want to show some response in response section how i can show it via mqtt?

which topic i have to use for publishing response to templates 501,502,503
i had tried like this but not success
this._client.publish( “s/ds”, “503,c8y_Command”, “SUCCESSFUL”);
or
this._client.publish( “s/us”, “503,c8y_Command”, “SUCCESSFUL”);

am i doing correct or wrong ?
if it is wrong then what is correct approch

any update regarding this @Stefan_Witschel i am not able to send response to cumulocity of success or failur via mtqq using template 503,502…so please guid me regarding this?

Your MQTT payload looks wrong. It should probably look something like this:

this._client.publish( "s/us", "503,c8y_Command,\"Put your response here\"");

okay I will follow it and get back to you if feel any difficulties Thanks @Tristan_Bastian

Hello @Tristan_Bastian my problem is not resolved , not able to send response .
i had tried as you suggested .
tried like this this._client.publish( “s/us”, “503,c8y_Command,"SUCCESSFUL"”);


i am sending some data using this shell and then receiving msg at subscribed topic s/ds now i want to send response to cumulocity Either success or failled but it’s showing pending take look of attached image .
please gyuid me where i am going wrong?

Can you actually try using the sample I provided above?
It seems like you have added spaces to your payload and are using different kinds of quotation marks within the CSV payload. The quotation marks probably also need to be escaped.

hello @Tristan_Bastian
tried as per your suggestion like this this._client.publish( “s/us”, “503,c8y_Command,success”);
this._client.publish( “s/us”, “503,c8y_Command,"success"”);

i was tried both ways and removed all the spaces but didn’t working

Hi Sumit,

is the assumption is correct that you use the same client instance for subscription and publishing messages? Can you please check the owner in the info tab of device “apama123456”?
The lifecycle of operations is the following: Set it to Pending → Executing → Successful/Failed. So try to send the 501 first before sending 503:
For debugging you can also subscribe on “s/e” to receive potential errors.

this._client.publish("s/us", "501,c8y_Command");
this._client.publish("s/us", "503,c8y_Command,success");

hello @Stefan_Witschel


Owner of this device is sumit.singh@softdel.com

and as per your suggestion i tried this._client.publish(“s/us”, “501,c8y_Command”);
this first but its not change status from pending to Executing
then tried this._client.publish(“s/us”, “503,c8y_Command,success”); but not working for me

i tried for other device to but status is not changing from pending i also tried with mqttfx tool but didn’t work


you can see here device is in pending and you can see mqttfx image to how i am sending from mqttfx

please guide me where I am going wrong

Hi Sumit,

Not sure what is going wrong for you. It could be an issue with the client_id, wrong instance or even missing permissions maybe.

I just tried the following flow and it is working fine on my tenant at eu-latest.com:

  1. Connect with a client ID and MQTT
  2. Send on “s/us” the message “100,myPrettyDevice” (check that the device has been created)
  3. Send on “s/us” the message “114,c8y_Command”
  4. Subscribe on “s/ds”
  5. Create a command in the UI for that device. (Check if the command is received in the MQTT Client)
  6. Send on “s/us” the message “501,c8y_Command”
  7. See the result in the screen above.

BTW: By sending “501,c8y_Command” only the OLDEST Operation will be updated so avoid having many pending operations.

@Stefan_Witschel Thanks for your support it worked
now i have one last question when we used 502 for failed then in cumulocity response we not get anything right? only status will change and failure reason.
like this image just want confirmation i am doing in correct manner or not

And it will work with child device also or not ?when sending something from child device shell .

Hi @sumit.singh,

correct, but you can of course append any error message to the failure reason string e.g. “out of disk space” or “command not found”.