0
votes

I'm trying to update Iothub device status using Rest API. Link: https://docs.microsoft.com/en-us/rest/api/iothub/service/createorupdatedevice

I was able to create a new device using it but not able to update anything.

Request:

{
    "eTag": "NTkyMDYyMzsSU2",
    "status": "disabled",
    "deviceId": "xyz"
}

Response:

{
    "Message": "ErrorCode:DeviceAlreadyExists;A device with ID 'xyz' is already registered.",
    "ExceptionMessage": "Tracking ID:8a748b37ssda964671a75f0a3fb1ba5a7b-G:8-TimeStamp:04/29/2019 14:53:52"
}
1
I think this would as well be affected by the api request mode(put, post etc.). I guess in this case, get is required and the response seems to be from a put request.naman1994

1 Answers

1
votes

Add the following header:

if-match:*

also, in the payload must be added a device authentication property otherwise the service will be auto regenerated for them. The following example is using the symmetricKey:

{
    "status": "disabled",
    "deviceId": "xyz",
    "authentication": {
      "symmetricKey": {
        "primaryKey": "******",
        "secondaryKey": "*****"
        }
      }
}