Submits a data parsing script for a specified product.

Usage notes

A data parsing script is used to convert data submitted by devices into the JSON format. The data submitted by devices is in a custom format. You can write a script in JavaScript, Python 2.7, and PHP 7.2. For more information, see Submit scripts for data parsing.

Notice If the data format is Alink JSON, the CreateThingScript operation is not supported. Alink JSON is a standard data format that is defined by IoT Connectivity Alliance (ICA).

QPS limits

Each Alibaba Cloud account can run a maximum of 10 queries per second (QPS).

Note The Resource Access Management (RAM) users of an Alibaba Cloud account share the quota of the account.

Debugging

OpenAPI Explorer automatically calculates the signature value. For your convenience, we recommend that you call this operation in OpenAPI Explorer. OpenAPI Explorer dynamically generates the sample code of the operation for different SDKs.

Request parameters

Parameter Type Required Example Description
Action String Yes CreateThingScript

The operation that you want to perform. Set the value to CreateThingScript.

ProductKey String Yes a1Q5XoY****

The ProductKey of the product.

You can view the ProductKey on the Product Details page of the IoT Platform console. You can also obtain the ProductKey by calling the QueryProductList operation.

ScriptContent String Yes "function protocolToRawData(jsonObj) {return rawdata; }function rawDataToProtocol(rawData) {return jsonObj; }"

The content of the script. You must specify this parameter.

For more information about script examples, see What is data parsing.

ScriptType String Yes JavaScript

The language of the script. Valid values:

  • JavaScript
  • Python_27: Python 2.7
  • PHP_72: PHP 7.2
IotInstanceId String No iot-cn-0pp1n8t****

The ID of the instance. You can view the ID of the instance on the Overview page in the IoT Platform console.

Notice
  • If your instance has an ID, you must specify this parameter. Otherwise, the call fails.
  • If the Overview page does not appear in the console or no ID is generated for your instance, you do not need to specify this parameter.

For more information, see Overview.

In addition to the preceding operation-specific request parameters, you must configure common request parameters when you call this operation. For more information, see Common request parameters.

Response parameters

Parameter Type Example Description
Code String iot.system.SystemException

The error code returned if the call fails. For more information, see Error codes.

ErrorMessage String A system exception occurred.

The error message returned if the request fails.

RequestId String BB71E443-4447-4024-A000-EDE09922891E

The ID of the request. The ID uniquely identifies this request.

Success Boolean true

Indicates whether the request was successful.

  • true: The request was successful.
  • false: The request failed.

Examples

Sample requests

http(s)://iot.cn-shanghai.aliyuncs.com/?Action=CreateThingScript
&ProductKey=a1Q5XoY****
&ScriptContent="function protocolToRawData(jsonObj) {return rawdata; }function rawDataToProtocol(rawData) {return jsonObj; }"
&ScriptType=JavaScript
&<Common request parameters>

Sample success responses

XML format

<CreateThingScriptResponse>
    <RequestId>BB71E443-4447-4024-A000-EDE09922891E</RequestId>
    <Success>true</Success>
</CreateThingScriptResponse>

JSON format

{
      "RequestId":"BB71E443-4447-4024-A000-EDE09922891E",
      "Success":true
  }