API to create and delete devices in Iot hub?

Category: azure iot hub


Prasant K2 on Tue, 22 Aug 2017 07:23:46

Is it possible to create/delete Iot devices by invoking an API from third party application. If so could you please share me the steps.
Also is there any other alternative methods we could create/delete devices without manual intervention?


Gary Bushey on Tue, 22 Aug 2017 11:15:28

There are REST APIs you can call to perform these actions.  See 


for more information.  I have not used these so I have no actual code examples but they look pretty straight forward.

Roman Kiss on Tue, 22 Aug 2017 15:10:02


- the following screen snippets show the examples of the REST APIs for Create/Update/Delete Device:



Prasant K2 on Wed, 23 Aug 2017 11:36:08

Hi Roman, 

Thanks for your information.

I am able to post messages to device and delete a device created manually in Iot hub, but not able to create/enable/disable devices. Could you please help me to achieve the same.

I am using postman as rest client.

Method: PUT

URL: https://ConnectedCars.azure-devices.net/devices/My_New_Device?api-version=2016-11-14


Authorization - SharedAccessSignature sr=Connect.......

Content-Type - application/json

Accept - application/json

Accept-Encoding - deflate,json

Accept-Language - en-US, en;q=0.8


    "Message": "ErrorCode:ArgumentNull;BadRequest",
    "ExceptionMessage": "Tracking ID:183342f61f8343758d5d8165aec09d19-G:4-TimeStamp:08/23/2017 10:18:26"

Actually it says bad request, any other inputs missing?



Roman Kiss on Wed, 23 Aug 2017 12:03:07

Hi Prasant,

- you didn't show your payload for PUT request to create the device. It should be look like the following:

   "deviceId": "My_New_Device",
   "status": "enabled",
   "statusReason": null,
        "primaryKey": null,
        "secondaryKey": null
     "x509Thumbprint": null



Prasant K2 on Wed, 23 Aug 2017 12:33:41

Hi Roman, 

The payload worked. Thanks

Roman Kiss on Wed, 23 Aug 2017 13:13:59

- keep in mind, that the Update Device will need to use the actually values of the authentication keys. If the primaryKey/secondaryKey are null, the Azure IoT Hub will regenerate them.