How to get the specific ID of an Operation via SmartRest

Hello Cumulocity Community,

I have a question regarding SmartRest: It is possible to directly set the status (EXECUTING, SUCCESSFUL, FAILED) of an operation using its ID. Is there a way to transmit this ID to ThinEdge using SmartRest without making an additional request? The edge device should be able to set the status itself, but for that to work, the operation ID needs to be sent to ThinEdge.

I have already found the following information on this topic:

Thank you in advance!

Standard static response templates do not contain operation IDs because they are mostly designed for simplicity that doesn’t require devices to handle Cumulocity internal IDs.

If you want to receive IDs of operations via SmartREST you will have to register a custom response template that contains this ID and potentially any other information you need from that operation.

2 Likes

If you’re using thin-edge.io (>= 1.4.x), then you don’t have to worry about any of this. By default thin-edge.io subscribes to the devicecontrol/notifications topic which is the Cumulocity operations in JSON format.

On a device, you can checkout the MQTT message being received and sent to the server by just subscribing to the local MQTT broker. The exert below shows the configuration snapshot operation being received by thin-edge.io, the mapper converts the message to a thin-edge.io message, the tedge-agent processes the message (using a workflow), whilst the mapper will translate the operation’s status update back to Cumulocity.

$ tedge mqtt sub '#'

[c8y/devicecontrol/notifications] {"delivery":{"log":[],"time":"2025-01-21T16:36:33.604Z","status":"PENDING"},"agentId":"5733465816","creationTime":"2025-01-21T16:36:33.551Z","deviceId":"5733465816","id":"43639315","status":"PENDING","description":"Retrieve tedge-configuration-plugin configuration snapshot from device rpi5-d83addab8e9f","c8y_UploadConfigFile":{"type":"tedge-configuration-plugin"},"externalSource":{"externalId":"rpi5-d83addab8e9f","type":"c8y_Serial"}}

[c8y/s/ds] 526,rpi5-d83addab8e9f,tedge-configuration-plugin

[te/device/main///cmd/config_snapshot/c8y-mapper-43639315] {"status":"init","tedgeUrl":"http://127.0.0.1:8000/tedge/file-transfer/rpi5-d83addab8e9f/config_snapshot/tedge-configuration-plugin-c8y-mapper-43639315","type":"tedge-configuration-plugin"}

[te/device/main///cmd/config_snapshot/c8y-mapper-43639315] {"@version":"builtin","logPath":"/var/log/tedge/agent/workflow-config_snapshot-c8y-mapper-43639315.log","status":"scheduled","tedgeUrl":"http://127.0.0.1:8000/tedge/file-transfer/rpi5-d83addab8e9f/config_snapshot/tedge-configuration-plugin-c8y-mapper-43639315","type":"tedge-configuration-plugin"}

[te/device/main///cmd/config_snapshot/c8y-mapper-43639315] {"@version":"builtin","logPath":"/var/log/tedge/agent/workflow-config_snapshot-c8y-mapper-43639315.log","status":"executing","tedgeUrl":"http://127.0.0.1:8000/tedge/file-transfer/rpi5-d83addab8e9f/config_snapshot/tedge-configuration-plugin-c8y-mapper-43639315","type":"tedge-configuration-plugin"}

[te/device/main///cmd/config_snapshot/c8y-mapper-43639315] {"@version":"builtin","logPath":"/var/log/tedge/agent/workflow-config_snapshot-c8y-mapper-43639315.log","path":"/etc/tedge/plugins/tedge-configuration-plugin.toml","status":"successful","tedgeUrl":"http://127.0.0.1:8000/tedge/file-transfer/rpi5-d83addab8e9f/config_snapshot/tedge-configuration-plugin-c8y-mapper-43639315","type":"tedge-configuration-plugin"}

[c8y/s/us] 504,43639315
[c8y/s/us] 506,43639315,https://thin-edge-io.eu-latest.cumulocity.com/event/events/43640330/binaries

The SmartREST 2.0 static templates, 504 - 506 are used so that the operation can be updated via the operation id.

But as a thin-edge.io user you don’t need to worry about the ins-and-outs of the Cumulocity interface, it does all the heavy lifting for you. And since thin-edge.io 1.4.2, you can even write a custom operation handler using the powerful workflow model. The tedge-command-plugin contains an example of this already how to map a Cumulocity json message to a thin-edge.io workflow.

3 Likes

Thank you for your replies.

I will discuss this within our team and then try to figure out the best way. Currently we are using thinEdge 1.3.x so the newest features are not available to us yet.

I will reply / mark as solution at a later time if we have a solution.