Call an API

更新时间:
复制 MD 格式

This topic explains the request structure for IoT Platform cloud APIs and provides examples.

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 endpoint of the cloud service. The IoT Platform endpoint uses the following format: iot.${RegionId}.aliyuncs.com. Replace ${RegionId} with the region ID of your IoT Platform service. For Alibaba Cloud region IDs, see Supported regions.

Action

The operation to perform, which is the name of the cloud API. For example, to call the Pub API to publish a message to a topic, set the value of Action to Pub. For example, Action=Pub.

Parameters

The request parameters for the API call, separated by an ampersand (&).

Request parameters consist of common request parameters and API-specific request parameters. Common parameters include information such as the API version and authentication details.

Request example

The following example shows a call to the 2018-01-20 version of the Pub API to publish a message to a topic:

Note

This example uses the endpoint for the China (Shanghai) region and is formatted for readability. For parameter descriptions, see Common parameters and Pub.

Replace the placeholder value for the AccessKeyId parameter with the AccessKey ID from your Alibaba Cloud account or RAM user. For instructions on how to create an AccessKey, 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

The Alibaba Cloud OpenAPI Developer Portal provides OpenAPI Explorer. On the API Debugging page, you can quickly search for and test API calls. The tool automatically generates SDK code examples for various languages based on your input parameters. The examples are displayed on the SDK Example tab on the right side of the page. The Debugging Result tab shows the actual request URL and the response in JSON format.

The left side of the API Debugging page is the parameter configuration area, which includes the Service Address selector and forms for each API parameter. In addition to the SDK Example and Debugging Result tabs, the right side also includes the OpenAPI Document, Related Examples, Error Codes, and Throttling tabs. In the SDK example section, you can select an SDK version (V2.0/V1.0) and multiple programming languages. Above the code area are the Run in Sandbox, Download Project, and Copy buttons.