Skip to content

Commit 21ebeb6

Browse files
committed
Integrated Kelly's suggestions
1 parent 15668ee commit 21ebeb6

File tree

1 file changed

+34
-46
lines changed

1 file changed

+34
-46
lines changed

articles/iot-hub/iot-hub-rm-rest.md

Lines changed: 34 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -25,46 +25,44 @@ You can use the [IoT Hub Resource](/rest/api/iothub/iothubresource) REST API to
2525

2626
## Get an Azure access token
2727

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.
2929

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):
34-
35-
```json
36-
{
37-
"accessToken": "eyJ ... pZA",
38-
"expiresOn": "2022-09-16 20:57:52.000000",
39-
"subscription": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
40-
"tenant": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
41-
"tokenType": "Bearer"
42-
}
43-
```
44-
45-
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):
34+
35+
```json
36+
{
37+
"accessToken": "eyJ ... pZA",
38+
"expiresOn": "2022-09-16 20:57:52.000000",
39+
"subscription": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
40+
"tenant": "XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX",
41+
"tokenType": "Bearer"
42+
}
43+
```
5044

5145
1. In a new **Postman** request, from the **Auth** tab, select the **Type** dropdown list and choose **Bearer Token**.
5246

5347
:::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**.":::
5448

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.
5654

57-
### Create a new IoT hub
55+
### Create an IoT hub
5856

5957
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.
6058

6159
```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
6361
```
6462

6563
:::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.":::
6664

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).
6866

6967
1. From the **Body** tab, select the **raw** and **JSON** from the dropdown lists.
7068

@@ -86,21 +84,21 @@ Open **Postman** and follow the order of REST commands below to create your IoT
8684

8785
:::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.":::
8886

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).
9088

9189
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**.
9290

93-
## Confirm your IoT hub is in the Azure portal
91+
## View / show an IoT hub
9492

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:
9694

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
9997
```
10098

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).
102100

103-
### Update your IoT hub
101+
### Update an IoT hub
104102

105103
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.
106104

@@ -126,29 +124,19 @@ PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{
126124

127125
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.
128126

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).
140128

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.
142130

143-
## Remove your IoT hub from the Azure portal
131+
## Delete an IoT hub
144132

145133
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.
146134

147135
```rest
148136
DELETE https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Devices/IotHubs/{resourceName}?api-version=2018-04-01
149137
```
150138

151-
See the DELETE command from the [IoT Hub Resource](/rest/api/iothub/iot-hub-resource/delete?tabs=HTTP).
139+
See the [DELETE command in the IoT Hub Resource](/rest/api/iothub/iot-hub-resource/delete?tabs=HTTP).
152140

153141
## Next steps
154142

0 commit comments

Comments
 (0)