Call APIs
This topic describes the request structure of the IoT Platform API and provides a request example.
Request structure
To call an IoT Platform API, send an HTTP or HTTPS request.
A request has the following structure:
http://Endpoint/?Action=****&Parameters
|
Parameter |
Description |
|
Endpoint |
The service endpoint. The endpoint for IoT Platform is in the format |
|
Action |
The API operation to perform. For example, to call the Pub operation to publish a message to a specific topic, set the Action parameter to Pub, such as |
|
Parameters |
The parameters for the API request. Separate multiple parameters with an ampersand (&). Request parameters include common request parameters and operation-specific parameters. Common request parameters specify details such as the API version and authentication. |
Request example
The following example shows how to call the Pub operation of version 2018-01-20 to publish a message to a specified topic:
The examples in this topic use the endpoint for the China (Shanghai) region. The code is formatted for readability. For more information about the request parameters, see Common parameters and Pub.
Set the AccessKeyId parameter to the AccessKey ID of your Alibaba Cloud account or a RAM user. For instructions, see Create an AccessKey.
The AccessKey pair of an Alibaba Cloud account can be used to call all API operations. We recommend that you use a RAM user to call API operations or perform routine O&M. Keep your AccessKey pair confidential.
We recommend that you do not include your AccessKey pair in files that are easily accessible to others, such as the project code. Otherwise, your AccessKey pair may be leaked and resources in your account become insecure.
https://iot.cn-shanghai.aliyuncs.com/?Action=Pub
&Format=XML
&Version=2018-01-20
&Signature=Pc5WB8gok***1dgI%3D
&SignatureMethod=HMAC-SHA1
&SignatureNonce=15215528852396
&SignatureVersion=1.0
&AccessKeyId=yourAccessKeyID
&Timestamp=2017-07-19T12:00:00Z
&RegionId=cn-shanghai
...
API debugging
Alibaba Cloud OpenAPI Explorer provides an API debugging tool. On the API Debugging page, you can quickly search for and call APIs. The system automatically generates SDK example code for different languages based on the parameters that you enter. The SDK example code is displayed on the right side of the page under the Example Code tab for your reference. On the Debugging Result tab, you can view the actual request URL and the JSON-formatted response of the API call.