# How to receive response on cumulocity of a api

**URL:** <https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941>\
**Category:** Forum\
**Tags:** cumulocity\
**Created:** [May 19, 2022, 5:36am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941 "2022-05-19T05:36:29Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 19, 2022, 5:36am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/1 "2022-05-19T05:36:29Z")

</div>

#### 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

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [May 19, 2022, 9:04am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/2 "2022-05-19T09:04:04Z")

</div>

Hi Sumit,

have a look here: [SmartREST - Cumulocity IoT Guides](https://cumulocity.com/guides/reference/smartrest-two/#operation-templates)  
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.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/4/9/4938e3e8106be0e5f383e7a63ba0a8a136ebb1e2.png)

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

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/8/e/8e0cbfa03f2e81a92193d25c8ec73cdc4d9ab7f7.png)

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 19, 2022, 12:05pm UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/3 "2022-05-19T12:05:01Z")

</div>

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

 ![cumulocity1](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/f/2/f2cccbcee8a126c1439575819e7d985775ff7c78.png)

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [May 19, 2022, 1:41pm UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/4 "2022-05-19T13:41:42Z")

</div>

Hi Sumit,

because your device/application is not subscribed to the “s/ds” topic ([SmartREST - Cumulocity IoT Guides](https://cumulocity.com/guides/reference/smartrest-two/#overview)) and/or the device is not handling the message [SmartREST - Cumulocity IoT Guides](https://cumulocity.com/guides/reference/smartrest-two/#command-511).  
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.

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 20, 2022, 9:07am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/5 "2022-05-20T09:07:51Z")

</div>

thank for your support  
I will follow the Guide

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 26, 2022, 10:20am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/6 "2022-05-26T10:20:46Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 26, 2022, 11:18am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/7 "2022-05-26T11:18:28Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 26, 2022, 1:28pm UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/8 "2022-05-26T13:28:45Z")

</div>

![cumulocity](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/9/3/933daaa88defbb5be091b5fa221665444fb7f104.png)  
i want to show some response in response section how i can show it via mqtt?

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 27, 2022, 7:26am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/9 "2022-05-27T07:26:22Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 30, 2022, 6:14am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/10 "2022-05-30T06:14:17Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [May 30, 2022, 7:04am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/11 "2022-05-30T07:04:41Z")

</div>

> [@sumit.singh](#):
>
> this.\_client.publish( “s/us”, “503,c8y\_Command”, “SUCCESSFUL”);

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

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

```

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 30, 2022, 7:07am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/12 "2022-05-30T07:07:16Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 30, 2022, 7:30am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/13 "2022-05-30T07:30:20Z")

</div>

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"”);

 ![shell1](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/b/3/b3577e5daece4c69668a3b35c3438e54c560f317.png)  
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?

---

<div class="post-metadata">

**Author:** ![Tristan\_Bastian](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/tristan_bastian/32/18259_2.png) [@Tristan\_Bastian](https://community.cumulocity.com/u/Tristan_Bastian)\
**Post date:** [May 30, 2022, 8:52am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/14 "2022-05-30T08:52:40Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 30, 2022, 9:52am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/15 "2022-05-30T09:52:20Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [May 30, 2022, 10:25am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/16 "2022-05-30T10:25:42Z")

</div>

> [@Tristan\_Bastian](#):
>
> 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.

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.

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

```

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 30, 2022, 11:44am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/17 "2022-05-30T11:44:13Z")

</div>

hello @Stefan_Witschel

 ![shell2](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/0/f/0fe8ab40965e061157546fa9df601999c46a36f8.png)  
Owner of this device is [sumit.singh@softdel.com](mailto: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

 ![shell3](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/d/d/dd45c740c9212b977bbf22f95290244e167ea2ab.png)  
you can see here device is in pending and you can see mqttfx image to how i am sending from mqttfx  
 ![fx2](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/f/d/fdd255499f2b31be564975c2c5d7e151a50abeed.png)  
 ![fx1](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/b/5/b5be6b3441a8441909c82622e17a3354503fb832.png)

please guide me where I am going wrong

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [May 30, 2022, 1:26pm UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/18 "2022-05-30T13:26:35Z")

</div>

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](http://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)  
 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/8/1/810bd2fe52a62c7f9d08d1d905674b51fea616a9.png)
6. Send on “s/us” the message “501,c8y\_Command”
7. See the result in the screen above.

 ![image](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/1/8/18fc5660949836e8ef287104af682784fcb11862.png)

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

---

<div class="post-metadata">

**Author:** ![sumit.singh](https://avatars.discourse-cdn.com/v4/letter/s/e9c0ed/32.png) [@sumit.singh](https://community.cumulocity.com/u/sumit.singh)\
**Post date:** [May 31, 2022, 5:47am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/19 "2022-05-31T05:47:45Z")

</div>

@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

 ![failresponse](https://europe1.discourse-cdn.com/flex005/uploads/cumulocity/original/3X/3/4/34f28a0829c9d84e784c2dff66f4790cb9c1f6f2.png)

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

---

<div class="post-metadata">

**Author:** ![Stefan\_Witschel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/stefan_witschel/32/31955_2.png) [@Stefan\_Witschel](https://community.cumulocity.com/u/Stefan_Witschel)\
**Post date:** [May 31, 2022, 8:13am UTC](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941/20 "2022-05-31T08:13:37Z")

</div>

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”.

[Next page](https://community.cumulocity.com/t/how-to-receive-response-on-cumulocity-of-a-api/941.md?page=2)
