You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/iot-hub/iot-hub-rm-rest.md
+34-46Lines changed: 34 additions & 46 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,46 +25,44 @@ You can use the [IoT Hub Resource](/rest/api/iothub/iothubresource) REST API to
25
25
26
26
## Get an Azure access token
27
27
28
-
In the Azure PowerShell cmdlet or Azure Cloud Shell, sign in and then retrieve a token with this command:
28
+
1.In the Azure PowerShell cmdlet or Azure Cloud Shell, sign in and then retrieve a token with the following command. If you're using Cloud Shell you are already signed in, so skip this step.
29
29
30
-
```azurecli-interactive
31
-
az account get-access-token --resource https://management.azure.com
32
-
```
33
-
You should see a response in the console similar to this JSON (except the access token is long):
Save your access token (the string without quotes) for later.
46
-
47
-
## Use the resource provider REST API to create an IoT hub
48
-
49
-
Open **Postman** and follow the order of REST commands below to create your IoT hub. These commands are from the [IoT Hub Resource](/rest/api/iothub/iot-hub-resource) reference. If any of these REST commands fail, find help with the [IoT Hub API common error codes](/rest/api/iothub/common-error-codes). Keep in mind the access token expires after 5-60 minutes, so you may need to generate another one.
30
+
```azurecli-interactive
31
+
az account get-access-token --resource https://management.azure.com
32
+
```
33
+
You should see a response in the console similar to this JSON (except the access token is long):
1. In a new **Postman** request, from the **Auth** tab, select the **Type** dropdown list and choose **Bearer Token**.
52
46
53
47
:::image type="content" source="media/iot-hub-rm-rest/select-bearer-token.png" alt-text="Screenshot that shows how to select the Bearer Token type of authorization in **Postman**.":::
54
48
55
-
1. Retrieve and copy the access token you saved previously and paste it into the field labeled **Token**.
49
+
1. Paste the access token into the field labeled **Token**.
50
+
51
+
## Use the REST API to create, view, update, or delete an IoT hub
52
+
53
+
The following commands are from the [IoT Hub Resource](/rest/api/iothub/iot-hub-resource) reference. If any of these REST commands fail, find help with the [IoT Hub API common error codes](/rest/api/iothub/common-error-codes). Keep in mind the access token expires after 5-60 minutes, so you may need to generate another one.
56
54
57
-
### Create a new IoT hub
55
+
### Create an IoT hub
58
56
59
57
1. Select the REST command dropdown list and choose the PUT command. Copy the URL below, replacing the values in the `{}` with your own values. The `{resourceName}` value is the name you'd like for your new IoT hub. Paste the URL into the field next to the PUT command.
60
58
61
59
```rest
62
-
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}?api-version=2018-04-01
60
+
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}?api-version=2021-04-12
63
61
```
64
62
65
63
:::image type="content" source="media/iot-hub-rm-rest/paste-put-command.png" alt-text="Screenshot that shows how to add a PUT command in Postman.":::
66
64
67
-
For more information about the PUT command, see [Iot Hub Resource - Create Or Update](/rest/api/iothub/iot-hub-resource/create-or-update?tabs=HTTP).
65
+
See the [PUT command in the IoT Hub Resource](/rest/api/iothub/iot-hub-resource/create-or-update?tabs=HTTP).
68
66
69
67
1. From the **Body** tab, select the **raw** and **JSON** from the dropdown lists.
70
68
@@ -86,21 +84,21 @@ Open **Postman** and follow the order of REST commands below to create your IoT
86
84
87
85
:::image type="content" source="media/iot-hub-rm-rest/add-body-for-put.png" alt-text="Screenshot that shows how to add JSON to the body of your request in Postman.":::
88
86
89
-
See the PUT command in the [IoT Hub Resource](/rest/api/iothub/iot-hub-resource/create-or-update?tabs=HTTP).
87
+
See the [PUT command in the IoT Hub Resource](/rest/api/iothub/iot-hub-resource/create-or-update?tabs=HTTP).
90
88
91
89
1. Select **Send** to send your request and create a new IoT hub. A successful request will return a **201 Created** response with a JSON printout of your IoT hub specifications. You can save your request if you're using **Postman**.
92
90
93
-
## Confirm your IoT hub is in the Azure portal
91
+
## View / show an IoT hub
94
92
95
-
You can confirm your IoT hub is now in the Azure portal with the following command in your Azure CLI. Replace **my-iot-hub** with the name of the IoT hub you created. A successful response shows your IoT hub specifications in JSON.
93
+
To see all the specifications of your new IoT hub, use a GET request. You can use the same URL that you used with the PUT request, but must erase the **Body** of that request (if not already blank) because a GET request can't have a body. Here's the GET request template:
96
94
97
-
```azurecli-interactive
98
-
az iot hub show --name my-iot-hub
95
+
```rest
96
+
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}?api-version=2018-04-01
99
97
```
100
98
101
-
Explore more Azure CLI commands for IoT Hub in the [az iot hub](/cli/azure/iot/hub) reference.
99
+
See the [GET command in the IoT Hub Resource](/rest/api/iothub/iot-hub-resource/get?tabs=HTTP).
102
100
103
-
### Update your IoT hub
101
+
### Update an IoT hub
104
102
105
103
Updating is as simple as using the same PUT request from when we created the IoT hub and editing the JSON body to contain parameters of your choosing. Edit the body of the request by adding a **tags** property, then run the PUT request.
106
104
@@ -126,29 +124,19 @@ PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{
126
124
127
125
The response will show the new tag added in the console. Remember, you may need to refresh your access token if too much time has passed since the last time you generated one.
128
126
129
-
See the PUT command in the [IoT Hub Resource](/rest/api/iothub/iot-hub-resource/create-or-update?tabs=HTTP).
130
-
131
-
Alternatively, use the PATCH command from the IoT Hub Resource(/rest/api/iothub/iot-hub-resource/update?tabs=HTTP) to update tags.
132
-
133
-
## Show all details of your IoT hub
134
-
135
-
To see all the specifications of your new IoT hub, use a GET request. You can use the same URL that you used with the PUT request, but must erase the **Body** of that request (if not already blank) because a GET request can't have a body. Here's the GET request template:
136
-
137
-
```rest
138
-
GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}?api-version=2018-04-01
139
-
```
127
+
See the [PUT command in the IoT Hub Resource](/rest/api/iothub/iot-hub-resource/create-or-update?tabs=HTTP).
140
128
141
-
See the GET command in the [IoT Hub Resource](/rest/api/iothub/iot-hub-resource/get?tabs=HTTP).
129
+
Alternatively, use the [PATCH command in the IoT Hub Resource](/rest/api/iothub/iot-hub-resource/update?tabs=HTTP) to update tags.
142
130
143
-
## Remove your IoT hub from the Azure portal
131
+
## Delete an IoT hub
144
132
145
133
If you're only testing, you might want to clean up your resources and delete your new IoT hub, by sending a DELETE request. be sure to replace the values in `{}` with your own values. The `{resourceName}` value is the name of your IoT hub.
0 commit comments