Interact with ADT using Postman
Tags: digitaltwin, postman, beginners, api
Published: 2022-08-01 21:14:04

> ADT: Azure Digital Twins

Postman is a REST testing tool that provides key HTTP request functionalities in a desktop and plugin-based GUI. You can craft HTTP requests and submit them to the Azure Digital Twins (ADT) REST APIs.

> This blog describes how to configure the Postman REST client to interact with the ADT APIs (creating a request collection).

### Prerequisites

- [knowledge](https://docs.microsoft.com/en-us/azure/digital-twins/overview) about ADT

- [Postman](https://www.postman.com/) installed

- [.NET Core](https://dotnet.microsoft.com/) installed (optional)

- Azure DT [instance](https://docs.microsoft.com/en-us/azure/digital-twins/quickstart-azure-digital-twins-explorer) created
- Azure DT [test models and graphs](https://docs.microsoft.com/en-us/azure/digital-twins/how-to-manage-model) created and uploaded

### Table of content

Using Azure CLI
Using Postman
  Create your own ADT collection
  Add an individual request
  Set request details

## Getting Started

### Using Azure CLI

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mnbjt3dumfi0m0wocimy.png)
 

**1**. Run the following command to access Azure credentials:

```linux
az login
```
**2**. Run the following command to get a bearer token with access to the ADT service.

using data plane APIs:
```linux
az account get-access-token --resource 0b07f429-9f4b-4714-9392-cc5e8e80c8b0
```
using control plane APIs:
```linux
az account get-access-token --resource https://management.azure.com/
```
result example:
`"accessToken": "eyJ0eXAiOiJ..."
"expiresOn": "2022-07-2...",
"subscription": "907b0d06-a...",
"tenant": "24ab6cd0-487e-...",
"tokenType": "Bearer"`

> Save the value of the accessToken and we will use it later on.

### Using Postman

We can either create our own collection of ADT APIs or import [an existing one](https://github.com/microsoft/azure-digital-twins-postman-samples). This article will be talking about creating one from scratch.

#### Create your own ADT collection

1. In `My Workspace` click `new` to create a new `Collection` in Building Blocks. Change the collection name if you like.

2. In the `Authorization` tag, set the `Type` to OAuth2.0 and paste your access token into the Token box. Click save.

#### Add an individual request

1. In `My Workspace` click `new` to create a new `Request` in Building Blocks. 

2. By clicking the `Save` button, you can name the new request and select a collection to save it. Click save again.

> The new request `Query twins` was saved in `ADT Custom Collection` directory.

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/3stebm6z8eyyelgdj1m5.png)
 

#### Set request details

Change the type from GET to POST, and paste the URL below:

```html
https://digitaltwins-host-name/query?api-version=2020-10-31.
```
> Using your own digital-twins-host-name

In the Authorization tab, set the Type to `Inherit auth from parent`. 

Check that the body shown for the request in the Body tab matches the needs described below:

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cidg1mo8747fusytk37b.png)

 
Use `send` button to send the request.


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6rj0sqi74vzete8mmnx3.png)

OK! All set.

### References
https://docs.microsoft.com/en-us/azure/digital-twins/how-to-use-postman?tabs=data-plane
Cover image from this link
https://aithority.com/computing/5-exciting-applications-of-digital-twin-technology/