Product data APIs include snapshot, raw, and event data APIs for devices within a product. After you create a product data API, you can call it to retrieve data for specific devices. This topic describes how to create and edit product data APIs.
Prerequisites
You have created a product and a device. For more information, see Create a product and Create a device.
Create a product data API
You can use product data APIs to query data from the last 30 days only.
-
In the IoT Platform console, go to the Overview page and click the ID or alias of the target Enterprise Edition instance.
-
In the left-side navigation pane, choose Data Service > Data API.
-
Click the Product Data API tab, and then click Create API.
-
In the Create API panel, select the check box next to the target product.
-
Click Apply.
The snapshot data API and raw data API for the product are added to the product data API list.
Parameter
Snapshot data API
Raw data API
Event data API
API name
${productName} product snapshot data query${productName} product raw data query${productName} product event data queryAPI Path
/${productKey}/snapshot/data/get/${productKey}/rawdata/get/${productKey}/event/data/get${productName}is the product name, and${productKey}is the unique identifier of the product.
Edit a product data API
For snapshot and raw data query APIs, you can edit the API name, request parameters, and response parameters.
-
On the Data API page, click the Product Data API tab.
-
In the API list, find the snapshot or raw data query API for the target product, and click Edit in the Actions column.
-
In the Edit API wizard, modify the API Basic Information, and then click Next.
Parameter
Description
API name
Change the name of the API. The name can contain Chinese characters, letters, digits, underscores (_), and hyphens (-). The name can be up to 30 characters long.
API Path
This parameter cannot be modified.
API tags
Enter the tag content and press Enter to create the tag.
Tags can contain Chinese characters, letters, digits, underscores (_), and hyphens (-). Each tag can be up to 30 characters long.
Use tags to add custom IDs to your APIs for flexible management.
ImportantYou can add a maximum of five tags to an API.
API description
Enter a description for the API to explain its features and other information.
Return type
The format of the data returned after the API is called. This is fixed to JSON.
-
On the Configure Parameters and Test page, modify the configuration parameters and advanced settings.
Category
Configuration item
Description
Configuration parameters
Request parameters
-
Click Add Parameter and select a Bound Field.
For the added parameter, you can set the operator, specify whether it is required, and provide a sample value and description.
-
To delete a parameter, click the delete icon
.
ImportantIf the parameter type is numeric, the
LIKEoperator is not supported.Response parameters
By default, all fields that the API can return are selected. You can specify whether a field is used for sorting and provide a sample value and description.
To delete a parameter, click the delete icon
. After you delete a parameter, you can click Add Parameter to add a bound field as a response parameter again. You can also select the Select All Parameters check box on the right to reselect all fields as response parameters.NoteUsed for Sorting specifies that the queried data is sorted by the values of this field in ascending or descending order before the query results are returned.
Sort order
Select the order in which to sort the parameters.
-
Ascending (default): The parameters are sorted in ascending order.
-
Descending: The parameters are sorted in descending order.
Advanced Settings
Enable paging for results
Select whether to enable paging for the returned results.
-
Disabled: You can view a maximum of 100 results.
-
Enabled: You can view all results in pages. If you enable this feature, the following common parameters are automatically added:
-
pageNum: The page number.
-
pageSize: The number of results to display on each page. The maximum value is 100.
-
Timeout error settings
If an API call request exceeds 8000 milliseconds, a timeout error is returned. This parameter cannot be modified.
-
-
After you complete the configuration, in the Test API section, enter test values for the request parameters and click Start Test.
You can view sample data on the Response Example tab or view the details of the request on the Request Details tab.
The request parameters include pageNum (INTEGER), pageSize (INTEGER), timestamp (BIGINT, required), and device_name (VARCHAR). The JSON-formatted data in the response example contains fields related to the power and light status of IoT devices, such as date_time, ActivePower, LightVolt, PowerRatio, DrainVoltage, PowerConsumption, LightAdjustLevel, timestamp, device_name, iot_id, LightCurrent, and LightStatus.
-
Click Publish.
Important-
Ensure that the API passes the test before you publish it.
-
If you only click Save for an API, its Status on the API Details page is Unpublished.
-
An API must be published before you can call it to query data.
After the API is published, a success message appears, and the API Name and API Path are displayed. You can click Copy to copy the path. Call examples for the Java SDK, Node.js SDK, and Python SDK are provided at the bottom of the page. You can click View List to return to the API list or click Create Again to create another API.
-
What to do next
-
Call a product data API to view the raw, snapshot, and event data for a specific device in a product.
For call examples, see:
-
View the API usage on the API Details page. For more information, see View an API.