Liverpool
Liverpool

Reputation: 275

Delete Device using rest API of Azure device provisioning service?

What is the format of the url needed to delete an already registered device in azure IoT hub using device provisioning service...

I read this article but it throws me 404

https://learn.microsoft.com/en-us/rest/api/iot-dps/deletedeviceregistrationstate/deletedeviceregistrationstate

In the request header I added If-Match tag but do I need to add Authorization tag with the SaS token and if I need the SaS token will be the one which I used for registering device using Device Provisioning Service

Upvotes: 1

Views: 449

Answers (1)

iAviator
iAviator

Reputation: 1447

if I need the SaS token will be the one which I used for registering device using Device Provisioning Service

There are some steps that you need to follow to generate the access_token that will be used in the Authorization header of the request.

Prerequisites:

Below are the steps:

Login with Azure CLI

az login

Set Active Subscription

az account set --subscription "your subscription name or id"

Create Service Principal

az ad sp create-for-rbac -n "your service principal name. Can be like 'jongpostman7'"

The output of above command will be something like below image. enter image description here

Copy this output to a temp location, you will need the values in a minute.

Coming to the Postman request now. You need to first call the AAD Token request whose response will provide you with the access_token. This access token you can use in the DPS delete device request. The AAD request will be like below:-

POST https://login.microsoftonline.com/{{tenantId}}/oauth2/token Refer image below for the request body.

enter image description here

grant_type is client_credentials client_id is the appId received in above command output client_secret is the password received in above command output tenant_id is the tenant received in above command output resource is https://management.azure.com/

The response of above request will be like below:- enter image description here

Now, you have the access_token that can be used in the DPS delete device REST API. The Authorization header be like below:

Authorization: Bearer <access_token_received_above>

Reference link here.

Upvotes: 0

Related Questions