问题
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://docs.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
回答1:
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:
- Install Python 2.7+
- Install Azure CLI 2.0+
- Login to CLI
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.
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.
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:-
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.
来源:https://stackoverflow.com/questions/64237640/delete-device-using-rest-api-of-azure-device-provisioning-service