What product/components do you use and which version/fix level?
Cumulocity 1010.0.12
Are you using a free trial or a product with a customer license?
Customer License
What are trying to achieve? Please describe in detail.
We have build a widget, Where we are calling GET device control operation API (https://test.cumulocity.com/devicecontrol/operations/{operation ID}) and the API is in pending status on server but in my local it runs after multiple try and give me successful status.
There is two part first I post an operation API then that API successfully gives me operation ID but when I try to run GET API using the operation ID from post API, I got pending status in my browser network and in my widget even though the operation is successful in device management control section.
I believe the server is to fast and it didn’t give much time to GET API to completes.
I’m wondering what could be the possible reason and any help much appreciated.
as a general remark, if you communicate with Cumulocity’s API you can use the @c8y/client instead of the FetchClient. For the Operation API it is the OperationService.
For your issue, I think you shouldn’t simply poll the operation and its status using a GET request as it will result in multiple requests to check whether the status of the operation has been updated to successful. I suggest to use the Realtime API and subscribe for updates for your operations.
Realtime service needs to be injected into your service/component and then you can subscribe to different channels:
Thanks for the quick response, I changed the FetchClient API to OperationService and the response is quite same. The issue is on server deployment the response I get from the operation API is pending but in reality the operation is successful, The server doesn’t give much time to load.
The Realtime service is injected as a dependency. In the onInit method the component subscribes for notifications on operations using the Realtime service and the channel /operations/. In this case, the component subscribes for operations of a particular device: private readonly DEVICE_ID = '701'; via /operations/${this.DEVICE_ID}. Using this subscription, the component only receives notifications, which have been created/updated for this specific device. If you want to receive operations for all devices, you can set up a subscription and use the * as a wildcard: /operations/*.
By using this approach you will be informed about every operation status updates.