# MQTT c8y\_LogfileRequest 522 - how to answer with 502 or 503

**URL:** <https://community.cumulocity.com/t/mqtt-c8y-logfilerequest-522-how-to-answer-with-502-or-503/5546>\
**Category:** Forum\
**Tags:** mqtt, cumulocity\
**Created:** [August 23, 2021, 1:28pm UTC](https://community.cumulocity.com/t/mqtt-c8y-logfilerequest-522-how-to-answer-with-502-or-503/5546 "2021-08-23T13:28:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![gruberm](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@gruberm](https://community.cumulocity.com/u/gruberm)\
**Post date:** [August 23, 2021, 1:28pm UTC](https://community.cumulocity.com/t/mqtt-c8y-logfilerequest-522-how-to-answer-with-502-or-503/5546/1 "2021-08-23T13:28:37Z")

</div>

Hello!

I try to find out, how to answer a  
522,serial,logFileToBeSend,start,stop,searchText,maxLines  
mqtt command?

I successfully get the 522 command in mqtt client  
I successfully send 501,c8y\_LogfileRequest, in the cumulocity gui the command is now running.  
I successfully upload the File with Binary-API, i can see the file in:  
https://\< Tenant\>.eu-latest.cumulocity.com/inventory/binaries

But how should I answer with mqtt with 502 or 503 on error or on success ? I can’t find any docs for that…

thanks a lot for help, regards manfred

---

<div class="post-metadata">

**Author:** ![Philipp\_Emmel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/philipp_emmel/32/19455_2.png) [@Philipp\_Emmel](https://community.cumulocity.com/u/Philipp_Emmel)\
**Post date:** [August 23, 2021, 3:10pm UTC](https://community.cumulocity.com/t/mqtt-c8y-logfilerequest-522-how-to-answer-with-502-or-503/5546/2 "2021-08-23T15:10:48Z")

</div>

Hello Manfred,

In error cases you can always use the 502 static template to fail the operation (see [https://cumulocity.com/guides/reference/smartrest-two/](https://cumulocity.com/guides/device-sdk/mqtt/#set-operation-to-failed-502)). As third parameter you can specify an error reason. Here is an example:

```auto
502,c8y_LogfileRequest,"Log file missing"

```

In successful cases you can use the 503 template and its implicit internal functionality. As part of completing a c8y\_LogfileRequest the device should also add the link to the uploaded binary into the operation object. You can use the additional parameters in the 503 template to supply this url (see [https://cumulocity.com/guides/reference/smartrest-two/](https://cumulocity.com/guides/device-sdk/mqtt/#set-operation-to-successful-503)). Here is an example:

```auto
503,c8y_LogfileRequest,"https://demos.cumulocity.com/event/events/12345/binaries"

```

We usually recommend to upload log files as event binaries instead of inventory binaries (see [Cumulocity - OpenAPI Specifications](https://cumulocity.com/api/#operation/postEventBinaryResource)). Then they are stored directly attached to the device object and not loosely in the inventory. They can also be cleaned up automatically using retention rules if desired.

---

<div class="post-metadata">

**Author:** ![gruberm](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@gruberm](https://community.cumulocity.com/u/gruberm)\
**Post date:** [August 23, 2021, 3:50pm UTC](https://community.cumulocity.com/t/mqtt-c8y-logfilerequest-522-how-to-answer-with-502-or-503/5546/3 "2021-08-23T15:50:48Z")

</div>

Hello Philipp!

Thank you very much, i will try.

What I do not understand, how do I get the event-id, with mqtt?

As I know now, after short reading, I have to send the file to the event binaries, like:  
POST /event/events/{id}/binaries, but how do i get this id, when i get the command via mqtt ?

Sorry for asking so much questions, but I am a little bit lost 😉

Regards, manfred

---

<div class="post-metadata">

**Author:** ![Philipp\_Emmel](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/philipp_emmel/32/19455_2.png) [@Philipp\_Emmel](https://community.cumulocity.com/u/Philipp_Emmel)\
**Post date:** [August 24, 2021, 7:47am UTC](https://community.cumulocity.com/t/mqtt-c8y-logfilerequest-522-how-to-answer-with-502-or-503/5546/4 "2021-08-24T07:47:00Z")

</div>

Hello Manfred,

The event isn’t created implicitly in the process. Your device must create it. You can either do this using HTTP since you are required to attach the file using HTTP afterwards (see: [Cumulocity - OpenAPI Specifications](https://cumulocity.com/api/#operation/postEventCollectionResource)). Then you’ll receive a HTTP response containing the created event including its ID.

You can also create this event using MQTT. Then you’ll have to create a custom template collection that creates the event as desired and receives its ID upon creation. An example for this custom template collection could look like this:

```auto
10,100,POST,EVENT,true,c8y_LogFileEvent,,,c8y_LogType,STRING,
11,101,,c8y_LogType,id

```

Then you can subscribe to this template’s return channel, create the event with 100 request template like this:

```auto
100,"syslog log file requested",,syslog

```

An receive the created event’s ID with the 101 response template like this:

```auto
101,23456

```

For reference, here is our documentation for custom template collections: [https://cumulocity.com/guides/reference/smartrest-two/](https://cumulocity.com/guides/device-sdk/mqtt/#template-collections)

---

<div class="post-metadata">

**Author:** ![gruberm](https://avatars.discourse-cdn.com/v4/letter/g/bbe5ce/32.png) [@gruberm](https://community.cumulocity.com/u/gruberm)\
**Post date:** [August 26, 2021, 7:38am UTC](https://community.cumulocity.com/t/mqtt-c8y-logfilerequest-522-how-to-answer-with-502-or-503/5546/5 "2021-08-26T07:38:02Z")

</div>

Hello Philipp!

Thank you very much, works as suggested!

Regards manfred

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/flex005/user_avatar/community.cumulocity.com/system/32/31990_2.png) [@system](https://community.cumulocity.com/u/system)\
**Post date:** [November 24, 2021, 7:38am UTC](https://community.cumulocity.com/t/mqtt-c8y-logfilerequest-522-how-to-answer-with-502-or-503/5546/6 "2021-11-24T07:38:24Z")

</div>

Closed on November 24, 2021, 7:38am UTC

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.
