Skip to content

Commit 6c110ed

Browse files
committed
Clarity edits
1 parent 03fc640 commit 6c110ed

File tree

3 files changed

+46
-27
lines changed

3 files changed

+46
-27
lines changed

articles/digital-twins/how-to-use-apis.md

Lines changed: 46 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,33 +12,33 @@ ms.date: 08/07/2024
1212

1313
# How to send requests to the Azure Digital Twins APIs using Visual Studio
1414

15-
[Visual Studio 2022](https://visualstudio.microsoft.com/vs/preview/) has support for `.http` files, which can be used to structure, store, and directly send HTTP requests from the application. Using this functionality of Visual Studio is one way to craft HTTP requests and submit them to the [Azure Digital Twins REST APIs](/rest/api/azure-digitaltwins/). This article describes how to set up an `.http file` in Visual Studio that can interface with the Azure Digital Twins APIs. This information is specific to the Azure Digital Twins service.
15+
[Visual Studio 2022](https://visualstudio.microsoft.com/vs/preview/) has support for `.http` files, which can be used to structure, store, and directly send HTTP requests from the application. Using this functionality of Visual Studio is one way to craft HTTP requests and submit them to the [Azure Digital Twins REST APIs](/rest/api/azure-digitaltwins/). This article describes how to set up an `.http` file in Visual Studio that can interface with the Azure Digital Twins APIs.
1616

1717
This article contains information about the following steps:
1818

1919
1. Set up a Visual Studio project and `.http` file, with variables that represent your Azure Digital Twins instance.
20-
1. Use the Azure CLI to [get a bearer token](#add-bearer-token) that you'll use to make API requests in Visual Studio.
20+
1. Use the Azure CLI to [get a bearer token](#add-bearer-token) that you can use to make API requests in Visual Studio.
2121
1. Use the [Azure Digital Twins REST API documentation](/rest/api/azure-digitaltwins/) as a resource to craft requests in the `.http` file, and send them to the Azure Digital Twins APIs.
2222

23-
Azure Digital Twins has two sets of APIs that you can work with: data plane and control plane. For more about the difference between these API sets, see [Azure Digital Twins APIs and SDKs](concepts-apis-sdks.md). This article contains information for both API sets.
23+
Azure Digital Twins has two sets of APIs that you can work with: *data plane* and *control plane*. For more information about the difference between these API sets, see [Azure Digital Twins APIs and SDKs](concepts-apis-sdks.md). This article contains instructions for both API sets.
2424

2525
For more information about `.http` file support in Visual Studio, see [Use .http files in Visual Studio 2022](/aspnet/core/test/http-files).
2626

2727
## Prerequisites
2828

29-
To make requests to the Azure Digital Twins APIs using Visual Studio, you need to set up an Azure Digital Twins instance and download Visual Studio 2022. The rest of this section walks you through these steps.
29+
To make requests to the Azure Digital Twins APIs using Visual Studio, you need to set up an Azure Digital Twins instance and download Visual Studio 2022. This section is for these steps.
3030

3131
### Set up Azure Digital Twins instance
3232

3333
[!INCLUDE [digital-twins-prereq-instance.md](../../includes/digital-twins-prereq-instance.md)]
3434

3535
### Download Visual Studio 2022
3636

37-
First, [download Visual Studio 2022](https://visualstudio.microsoft.com/vs/preview/). Make sure to include the **ASP.NET and web development** workload in your installation.
37+
Next, [download Visual Studio 2022](https://visualstudio.microsoft.com/vs/preview/). Make sure to include the **ASP.NET and web development** workload in your installation.
3838

3939
## Set up Visual Studio project
4040

41-
Next, set up the project in Visual Studio that you'll use to craft HTTP requests.
41+
In this section, you set up the project in Visual Studio that will be used to craft HTTP requests.
4242

4343
Open Visual Studio on your machine, and create a new project. Use the **ASP.NET Core Empty** project template.
4444

@@ -48,13 +48,13 @@ Follow the instructions in [Create an .http file](/aspnet/core/test/http-files#c
4848

4949
### Add variables
5050

51-
Next, add some variables at the top of your 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 will be used to connect to your Azure Digital Twins resource.
5252

53-
The set of variables you'll 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-apis) and [control plane](concepts-apis-sdks.md#control-plane-apis) APIs.
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-apis) and [control plane](concepts-apis-sdks.md#control-plane-apis) APIs.
5454

5555
# [Data plane](#tab/data-plane)
5656

57-
Add the following variables for data plane requests. There's one placeholder for the host name of your Azure Digital Twins instance, which ends in *digitaltwins.azure.net* and can be found in the Azure portal for your instance.
57+
Add the following variables for data plane requests. There's one placeholder for the host name of your Azure Digital Twins instance (it ends in *digitaltwins.azure.net*).
5858

5959
```http
6060
@hostName=<host-name-of-your-Azure-Digital-Twins-instance>
@@ -75,9 +75,9 @@ Add the following variables for control plane requests. They contain placeholder
7575

7676
## Add bearer token
7777

78-
Now that you've set up your Azure Digital Twins instance and Visual Studio, you'll need to get a bearer token that HTTP requests can use to authorize against the Azure Digital Twins APIs.
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.
7979

80-
There are several possible 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.
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.
8181

8282
If you have an [Azure CLI installed locally](/cli/azure/install-azure-cli), you can start a command prompt on your machine to run the following commands.
8383
Otherwise, you can open an [Azure Cloud Shell](https://shell.azure.com) window in your browser and run the commands there.
@@ -88,9 +88,9 @@ Otherwise, you can open an [Azure Cloud Shell](https://shell.azure.com) window i
8888
az login
8989
```
9090
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'll 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.
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.
9292
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-apis) and [control plane](concepts-apis-sdks.md#control-plane-apis) APIs.
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-apis) and [control plane](concepts-apis-sdks.md#control-plane-apis) APIs.
9494
9595
# [Data plane](#tab/data-plane)
9696
@@ -110,9 +110,9 @@ Otherwise, you can open an [Azure Cloud Shell](https://shell.azure.com) window i
110110
---
111111
112112
>[!NOTE]
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'll 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).
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).
114114
115-
3. Copy the value of `accessToken` in the result. This value is your **token value** that you'll provide to Visual Studio to authorize your requests.
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.
116116
117117
:::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":::
118118
@@ -129,48 +129,67 @@ In your `.http` file in Visual Studio, add another variable that holds the value
129129
@token=<paste-data-plane-token>
130130
```
131131

132+
Your variables should now look something like this:
133+
134+
:::image type="content" source="media/how-to-use-apis/variables-token-data.png" alt-text="Screenshot of the data plane variables, including a token." lightbox="media/how-to-use-apis/variables-token-data.png":::
135+
132136
# [Control plane](#tab/control-plane)
133137

134138
```http
135139
@token=<paste-control-plane-token>
136140
```
141+
142+
Your variables should now look something like this:
143+
144+
:::image type="content" source="media/how-to-use-apis/variables-token-control.png" alt-text="Screenshot of the control plane variables, including a token." lightbox="media/how-to-use-apis/variables-token-control.png":::
145+
137146
---
138147

139148
## Add requests
140149

141150
Now that your `.http` file is set up, you can add requests to the Azure Digital Twin APIs.
142151

143-
1. 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. This article will use the [DigitalTwins Update API](/rest/api/digital-twins/dataplane/twins/digital-twins-update) from the data plane as an example.
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.
144153

145-
1. **Add request template**: Copy the HTTP request shown in the documentation.
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.
146155

147-
:::image type="content" source="media/how-to-use-apis/copy-request.png" alt-text="Screenshot of the HTTP request in the digitaltwins API documentation." lightbox="media/how-to-use-apis/copy-request.png":::
156+
1. **Add request template**: Copy the HTTP request shown in the reference documentation.
157+
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":::
148159

149-
In Visual Studio, paste the request into your `.http` file.
150-
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 these with the [variables](#add-variables) you created earlier, or fill in other details 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).
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).
151162

152163
>[!NOTE]
153-
>For data plane requests, `digitaltwins-hostname` is also a parameter. Replace this with `{{hostName}}` to use the value of your variable.
164+
>For data plane requests, `digitaltwins-hostname` is also a parameter. Replace this with `{{hostName}}` to use the value of your host name variable.
165+
166+
Here's how this step looks in an example request:
167+
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":::
154169

155-
:::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":::
170+
1. **Add authorization**: Add the following line (exactly as written) directly underneath the request, to specify authentication with your bearer token variable.
156171

157-
1. **Add authorization**: Add the following line directly underneath the request to specify authentication with your bearer token variable.
158172
```http
159173
Authorization: Bearer {{token}}
160174
```
161175
176+
Here's how this step looks in an example request:
177+
162178
:::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":::
163179
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).
164180
165-
:::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":::
181+
Here's how this step looks in an example request:
182+
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":::
166184
167-
1. **Add body**: Look at the **Request Body** section of the reference documentation to see what body value 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 details, see [Request body](/aspnet/core/test/http-files#request-body).
168186
169-
:::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":::
187+
Here's how this step looks in an example request:
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":::
170189
171190
1. When the request is ready, select **Send request** above the request to send it.
172191
173-
:::image type="content" source="media/how-to-use-apis/send.png" alt-text="Screenshot of Send request in Visual Studio." lightbox="media/how-to-use-apis/send.png":::
192+
:::image type="content" source="media/how-to-use-apis/send.png" alt-text="Screenshot of Send request in Visual Studio." lightbox="media/how-to-use-apis/send.png":::
174193
175194
Visual Studio brings up a pane with the details of the response. Look at the **Responses** section of the reference documentation to interpret the status code and any data in the response body.
176195
75.8 KB
Loading
57.2 KB
Loading

0 commit comments

Comments
 (0)