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/digital-twins/how-to-use-apis.md
+15-15Lines changed: 15 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -7,7 +7,7 @@ author: baanders
7
7
ms.service: azure-digital-twins
8
8
services: digital-twins
9
9
ms.topic: how-to
10
-
ms.date: 08/07/2024
10
+
ms.date: 03/10/2025
11
11
---
12
12
13
13
# How to send requests to the Azure Digital Twins APIs using Visual Studio
@@ -38,7 +38,7 @@ Next, [download Visual Studio 2022](https://visualstudio.microsoft.com/vs/previe
38
38
39
39
## Set up Visual Studio project
40
40
41
-
In this section, you set up the project in Visual Studio that will be used to craft HTTP requests.
41
+
In this section, you set up the project in Visual Studio that is used to craft HTTP requests.
42
42
43
43
Open Visual Studio on your machine, and create a new project. Use the **ASP.NET Core Empty** project template.
44
44
@@ -48,9 +48,9 @@ Follow the instructions in [Create an .http file](/aspnet/core/test/http-files#c
48
48
49
49
### Add variables
50
50
51
-
Next, add some variables at the top of your `.http` file that will be used to connect to your Azure Digital Twins resource.
51
+
Next, add some variables at the top of your `.http` file that are used to connect to your Azure Digital Twins resource.
52
52
53
-
The set of variables you need depends on which set of APIs you're using, so use the tabs below to select between [data plane](concepts-apis-sdks.md#data-plane-overview) and [control plane](concepts-apis-sdks.md#control-plane-overview) APIs.
53
+
The set of variables you need depends on which set of APIs you're using, so use the following tabs to select between [data plane](concepts-apis-sdks.md#data-plane-overview) and [control plane](concepts-apis-sdks.md#control-plane-overview) APIs.
54
54
55
55
# [Data plane](#tab/data-plane)
56
56
@@ -75,7 +75,7 @@ Add the following variables for control plane requests. They contain placeholder
75
75
76
76
## Add bearer token
77
77
78
-
Now that you've set up your Azure Digital Twins instance and Visual Studio project, you need to get a bearer token that HTTP requests can use to authorize against the Azure Digital Twins APIs.
78
+
Now that you set up your Azure Digital Twins instance and Visual Studio project, you need to get a bearer token that HTTP requests can use to authorize against the Azure Digital Twins APIs.
79
79
80
80
There are multiple ways to obtain this token. This article uses the [Azure CLI](/cli/azure/install-azure-cli) to sign into your Azure account and obtain a token that way.
81
81
@@ -90,7 +90,7 @@ Otherwise, you can open an [Azure Cloud Shell](https://shell.azure.com) window i
90
90
91
91
2. Next, use the [az account get-access-token](/cli/azure/account#az-account-get-access-token()) command to get a bearer token with access to the Azure Digital Twins service. In this command, you pass in the resource ID for the Azure Digital Twins service endpoint, in order to get an access token that can access Azure Digital Twins resources.
92
92
93
-
The required context for the token depends on which set of APIs you're using, so use the tabs below to select between [data plane](concepts-apis-sdks.md#data-plane-overview) and [control plane](concepts-apis-sdks.md#control-plane-overview) APIs.
93
+
The required context for the token depends on which set of APIs you're using, so use the following tabs to select between [data plane](concepts-apis-sdks.md#data-plane-overview) and [control plane](concepts-apis-sdks.md#control-plane-overview) APIs.
94
94
95
95
# [Data plane](#tab/data-plane)
96
96
@@ -112,7 +112,7 @@ Otherwise, you can open an [Azure Cloud Shell](https://shell.azure.com) window i
112
112
>[!NOTE]
113
113
> If you need to access your Azure Digital Twins instance using a service principal or user account that belongs to a different Microsoft Entra tenant from the instance, you need to request a token from the Azure Digital Twins instance's "home" tenant. For more information on this process, see [Write app authentication code](how-to-authenticate-client.md#authenticate-across-tenants).
114
114
115
-
3. Copy the value of `accessToken` in the result. This value is your **token value** that you'll paste into Visual Studio to authorize your requests.
115
+
3. Copy the value of `accessToken` in the result. This value is your **token value** that you paste into Visual Studio to authorize your requests.
116
116
117
117
:::image type="content" source="media/how-to-use-apis/console-access-token.png" alt-text="Screenshot of the console showing the result of the az account get-access-token command. The accessToken field with a sample value is highlighted." lightbox="media/how-to-use-apis/console-access-token.png":::
118
118
@@ -151,23 +151,23 @@ Now that your `.http` file is set up, you can add requests to the Azure Digital
151
151
152
152
Start by opening the [Azure Digital Twins REST API reference](/rest/api/azure-digitaltwins/). This documentation contains details of all the operations covered by the APIs. Navigate to the reference page of the request you want to run.
153
153
154
-
This article will use the [DigitalTwins Update API](/rest/api/digital-twins/dataplane/twins/digital-twins-update) from the data plane as an example.
154
+
This article uses the [DigitalTwins Update API](/rest/api/digital-twins/dataplane/twins/digital-twins-update) from the data plane as an example.
155
155
156
156
1.**Add request template**: Copy the HTTP request shown in the reference documentation.
157
157
158
158
:::image type="content" source="media/how-to-use-apis/copy-request.png" alt-text="Screenshot of the HTTP request in the Digital Twins API documentation." lightbox="media/how-to-use-apis/copy-request.png":::
159
159
160
160
In Visual Studio, paste the request in a new line below the variables in your `.http` file.
161
-
1.**Add parameters**: Look at the **URI Parameters** section of the reference documentation to see which parameter values are needed by the request. You can replace some with the [variables](#add-variables) you created earlier, and fill in other parameter values as appropriate. To reference a variable, put the variable name in double curly braces, like `{{variable}}`. For more details, see [Variables](/aspnet/core/test/http-files#variables).
161
+
1.**Add parameters**: Look at the **URI Parameters** section of the reference documentation to see which parameter values are needed by the request. You can replace some with the [variables](#add-variables) you created earlier, and fill in other parameter values as appropriate. To reference a variable, put the variable name in double curly braces, like `{{variable}}`. For more information, see [Variables](/aspnet/core/test/http-files#variables).
162
162
163
163
>[!NOTE]
164
-
>For data plane requests, `digitaltwins-hostname` is also a parameter. Replace this with `{{hostName}}` to use the value of your host name variable.
164
+
>For data plane requests, `digitaltwins-hostname` is also a parameter. Replace this parameter value with `{{hostName}}` to use the value of your host name variable.
165
165
166
166
Here's how this step looks in an example request:
167
167
168
168
:::image type="content" source="media/how-to-use-apis/add-parameters.png" alt-text="Screenshot of the request with parameters in Visual Studio." lightbox="media/how-to-use-apis/add-parameters.png":::
169
169
170
-
1.**Add authorization**: Add the following line (exactly as written) directly underneath the request, to specify authentication with your bearer token variable.
170
+
1.**Add authorization**: To specify authentication with your bearer token variable, add the following line (exactly as written) directly underneath the request.
171
171
172
172
```http
173
173
Authorization: Bearer {{token}}
@@ -176,13 +176,13 @@ This article will use the [DigitalTwins Update API](/rest/api/digital-twins/data
176
176
Here's how this step looks in an example request:
177
177
178
178
:::image type="content" source="media/how-to-use-apis/add-authorization.png" alt-text="Screenshot of the request with authorization line in Visual Studio." lightbox="media/how-to-use-apis/add-authorization.png":::
179
-
1. **Add additional headers**: Look at the **Request Header** section of the reference documentation to see which header values can accompany the request. You may also want to include traditional HTTP headers like `Content-Type`. Add each header on its own line in the format `HeaderName: Value`. For more details, see [Request headers](/aspnet/core/test/http-files#request-headers).
179
+
1. **Add additional headers**: Look at the **Request Header** section of the reference documentation to see which header values can accompany the request. You might also want to include traditional HTTP headers like `Content-Type`. Add each header on its own line in the format `HeaderName: Value`. For more information, see [Request headers](/aspnet/core/test/http-files#request-headers).
180
180
181
181
Here's how this step looks in an example request:
182
182
183
183
:::image type="content" source="media/how-to-use-apis/add-header.png" alt-text="Screenshot of the request with another header in Visual Studio." lightbox="media/how-to-use-apis/add-header.png":::
184
184
185
-
1. **Add body**: Look at the **Request Body** section of the reference documentation to see what body information might be needed by the request. Add the request body after a blank line. For more details, see [Request body](/aspnet/core/test/http-files#request-body).
185
+
1. **Add body**: Look at the **Request Body** section of the reference documentation to see what body information might be needed by the request. Add the request body after a blank line. For more information, see [Request body](/aspnet/core/test/http-files#request-body).
186
186
187
187
Here's how this step looks in an example request:
188
188
:::image type="content" source="media/how-to-use-apis/add-body.png" alt-text="Screenshot of the request with a body in Visual Studio." lightbox="media/how-to-use-apis/add-body.png":::
@@ -195,14 +195,14 @@ Visual Studio brings up a pane with the details of the response. Look at the **R
195
195
196
196
:::image type="content" source="media/how-to-use-apis/response.png" alt-text="Screenshot of the response in Visual Studio." lightbox="media/how-to-use-apis/response.png":::
197
197
198
-
### Add additional requests
198
+
### Add more requests
199
199
200
200
To add more requests to the `.http` file, separate them with `###` as a delimiter.
201
201
202
202
:::image type="content" source="media/how-to-use-apis/multiple-requests.png" alt-text="Screenshot of multiple requests in one file in Visual Studio." lightbox="media/how-to-use-apis/multiple-requests.png":::
203
203
204
204
## Next steps
205
205
206
-
For more details about sending requests with `.http` files in Visual Studio, including syntax details and advanced scenarios, see [Use .http files in Visual Studio 2022](/aspnet/core/test/http-files).
206
+
For more information about sending requests with `.http` files in Visual Studio, including syntax details and advanced scenarios, see [Use .http files in Visual Studio 2022](/aspnet/core/test/http-files).
207
207
208
208
To learn more about the Digital Twins APIs, read [Azure Digital Twins APIs and SDKs](concepts-apis-sdks.md), or view the [reference documentation for the REST APIs](/rest/api/azure-digitaltwins/).
0 commit comments