Debugging Using Postman
Overview
Postman is a visual editing tool for building and testing API requests. It provides an easy-to-use UI to send HTTP requests, including GET, PUT, POST, and DELETE requests, and modify parameters in HTTP requests. Postman also returns response to your requests.
To fully understand APIs, read API Reference on the Application Side in advance. The Postman Collection is already available, in which the structure of API call requests are ready for use.
This topic uses Postman as an example to describe how to debug the following APIs to connect an application to the IoT platform using HTTPS:
Prerequisites
- You have installed Postman. If Postman is not installed, install it by following the instructions provided in Installing and Configuring Postman.
- You have downloaded the Collection.
- You have developed a product model and codec on the IoTDA console.
Installing and Configuring Postman
- Install Postman.
- Visit the Postman website to download and install Postman. (Postman 7.17.0 is used as an example.)

- Postman requires the .NET Framework 4.5 component. If you do not have this component, click .NET Framework 4.5 to download and install it.
- To ensure successful API calls, you are advised to download Postman 7.17.0.
- Enter the email address, username, and password to register Postman.
- Visit the Postman website to download and install Postman. (Postman 7.17.0 is used as an example.)
- Import the Postman environment variables.
- Click
in the upper right corner. The MANAGE ENVIRONMENTS window is displayed.

- Click Import to import the IoTDA.postman_environment.json file (obtained after the Collection package is decompressed).

- Click Manage Environments and select the imported IoTDA environment.


- Change the values of IAMEndpoint, IOTDAEndpoint, IAMUserName, IAMPassword, IAMDoaminId, and region.

- IAMEndpoint: Obtain the IAM endpoint from IAM Regions and Endpoints.
- IOTDAEndpoint: Obtain the IAM endpoint from IoT Platform Endpoints.
- If you have subscribed to IoTDA in CN North-Beijing4, change the IAM user name, login password, and account name by following the instructions provided in My Credentials.
- Return to the home page and set the environment variable to the imported IoTDA.
- Click
- Upload the API call (V5 version).postman_collection.json file.

After the file is uploaded, the dialog box shown in the following figure is displayed.

Debugging the API Used to Obtain the Token for an IAM User
Before accessing platform APIs, an application must call the API Obtaining the Token for an IAM User for authentication. After the authentication is successful, HUAWEI CLOUD returns the authentication token X-Subject-Token to the application.
To call this API, the application constructs an HTTP request. An example request is as follows:
POST https://iam.cn-north-4.myhuaweicloud.com/v3/auth/tokens
Content-Type: application/json
{
"auth": {
"identity": {
"methods": [
"password"
],
"password": {
"user": {
"name": "username",
"password": "********",
"domain": {
"name": "domainname"
}
}
}
},
"scope": {
"project": {
"name": "xxxxxxxx"
}
}
}
}
Note: username indicates the IAM user name, password indicates the password for logging in to HUAWEI CLOUD, domainname indicates the account name, and projectname indicates the project name. You can obtain them from the My Credentials page.

Debug the API by following the instructions provided in Obtaining a User Token Through Password Authentication.
- Configure the HTTP method, URL, and headers of the API.

- Configure the body of the API.

- Click Send. The returned code and response are displayed in the lower part of the page.

- Use the returned X-Subject-Token value in the header field to update X-Auth-Token in the IoTDA environment so that it can be used in other API calls. If the token expires, the Authentication API must be called again to obtain a new token.

The X-Auth-Token parameter is automatically updated in Postman. You do not need to manually update it.

Debugging the API Listing Projects Accessible to an IAM User
Before accessing platform APIs, the application must call the API Listing Projects Accessible to an IAM User to obtain the project ID of the user.
To call this API, the application constructs an HTTP request. An example request is as follows:
GET https://iam.cn-north-4.myhuaweicloud.com/v3/auth/projects Content-Type: application/json X-Auth-Token: ********
Debug the API by following the instructions provided in Listing Projects Accessible to an IAM User.
- Configure the HTTP method, URL, and headers of the API.

- Click Send. The returned code and response are displayed in the lower part of the page.

- The returned body contains a list of projects. Search for the item whose name is the same as the value of region in the IoTDA environment, and use the id value to update project_id in the IoTDA environment so that it can be used in other API calls.


In this example, the project_id parameter is automatically updated in Postman. You do not need to manually update it.

Debugging the API Used to Create a Product
Before connecting a device to the platform, an application must call the API Creating a Product. The product created will be used during device registration.
To call this API, the application constructs an HTTP request. An example request is as follows:
POST https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/{project_id}/products
Content-Type: application/json
X-Auth-Token: ********
{
"name" : "Thermometer",
"device_type" : "Thermometer",
"protocol_type" : "MQTT",
"data_format" : "binary",
"manufacturer_name" : "ABC",
"industry" : "smartCity",
"description" : "this is a thermometer produced by Huawei",
"service_capabilities" : [ {
"service_type" : "temperature",
"service_id" : "temperature",
"description" : "temperature",
"properties" : [ {
"unit" : "centigrade",
"min" : "1",
"method" : "R",
"max" : "100",
"data_type" : "decimal",
"description" : "force",
"step" : 0.1,
"enum_list" : [ "string" ],
"required" : true,
"property_name" : "temperature",
"max_length" : 100
} ],
"commands" : [ {
"command_name" : "reboot",
"responses" : [ {
"response_name" : "ACK",
"paras" : [ {
"unit" : "km/h",
"min" : "1",
"max" : "100",
"para_name" : "force",
"data_type" : "string",
"description" : "force",
"step" : 0.1,
"enum_list" : [ "string" ],
"required" : false,
"max_length" : 100
} ]
} ],
"paras" : [ {
"unit" : "km/h",
"min" : "1",
"max" : "100",
"para_name" : "force",
"data_type" : "string",
"description" : "force",
"step" : 0.1,
"enum_list" : [ "string" ],
"required" : false,
"max_length" : 100
} ]
} ],
"option" : "Mandatory"
} ],
"app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka"
}
Debug the API by following the instructions provided in Creating a Product.
Note: Only the parameters used in the debugging example are described in the following steps.
- Configure the HTTP method, URL, and headers of the API.

- Configure the body of the API.

- Click Send. The returned code and response are displayed in the lower part of the page.

- Use the returned product_id value to update the product_id parameter in the IoTDA environment so that it can be used in other API calls.

Note: The product_id parameter is automatically updated in Postman. You do not need to manually update it.

Debugging the API Querying a Product
An application can call the API Querying a Product to query details about a product.
To call this API, the application constructs an HTTP request. An example request is as follows:
GET https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/{project_id}/products/{product_id}
Content-Type: application/json
X-Auth-Token: ********
Debug the API by following the instructions provided in Querying a Product.
Note: Only the parameters used in the debugging example are described in the following steps.
- Configure the HTTP method, URL, and headers of the API.

- Click Send. The returned code and response are displayed in the lower part of the page.

Debugging the API Creating a Device
Before connecting a device to the platform, an application must call the API Registering a Device. Then, the device can use the unique identification code to get authenticated and connect to the platform.
To call this API, the application constructs an HTTP request. An example request is as follows:
POST https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/{project_id}/devices
Content-Type: application/json
X-Auth-Token: ********
{
"node_id" : "ABC123456789",
"device_name" : "dianadevice",
"product_id" : "b640f4c203b7910fc3cbd446ed437cbd",
"auth_info" : {
"auth_type" : "SECRET",
"secure_access" : true,
"fingerprint" : "dc0f1016f495157344ac5f1296335cff725ef22f",
"secret" : "3b935a250c50dc2c6d481d048cefdc3c",
"timeout" : 300
},
"description" : "watermeter device"
}
Debug the API by following the instructions provided in Creating a Device.
Note: Only the parameters used in the debugging example are described in the following steps.
- Configure the HTTP method, URL, and headers of the API.

- Configure the body of the API.

- Click Send. The returned code and response are displayed in the lower part of the page.

- Use the returned device_id value to update the device_id parameter in the IoTDA environment so that it can be used in other API calls.

Note: The device_id parameter is automatically updated in Postman. You do not need to manually update it.

Debugging the API Querying a Device
An application can call the API Querying a Device to query details about a device registered with the platform.
To call this API, the application constructs an HTTP request. An example request is as follows:
GET https://iotda.cn-north-4.myhuaweicloud.com/v5/iot/{project_id}/devices/{device_id}
Content-Type: application/json
X-Auth-Token: ********
Debug the API by following the instructions provided in Querying a Device.
Note: Only the parameters used in the debugging example are described in the following steps.
- Configure the HTTP method, URL, and headers of the API.

- Click Send. The returned code and response are displayed in the lower part of the page.

Last Article: Java Demo

Did this article solve your problem?
Thank you for your score!Your feedback would help us improve the website.