Updated on 2022-02-24 GMT+08:00

Creating a Batch Task

Typical Scenario

When an NA needs to perform an operation on a batch of devices, the NA can call this API to create a batch task. Currently, the supported batch operations include delivering pending commands to devices in batches.

API Function

This API is used by an NA to create a batch task for devices on the IoT platform.

API Description

1
def createBatchTask(self, btcInDTO, accessToken)

Class

BatchProcess

Parameter Description

Parameter

Mandatory or Optional

Type

Location

Description

btcInDTO

Mandatory

BatchTaskCreateInDTO

body

For details, see BatchTaskCreateInDTO structure.

accessToken

Mandatory

String

header

This parameter is set to the value of the access token obtained by calling the Authentication API.

BatchTaskCreateInDTO structure

Parameter

Mandatory or Optional

Type

Location

Description

appId

Mandatory

String(64)

body

Uniquely identifies an NA. This parameter is used to identify an NA that can call open APIs provided by the IoT platform. The value of this parameter is obtained when the NA is created on the SP portal of the IoT platform.

param

Mandatory

ObjectNode

body

Indicates the task parameter, which varies depending on the value of taskType.

taskName

Mandatory

String

body

Indicates the task name. The value is a string of a maximum of 256 characters.

taskType

Mandatory

String

body

Indicates the task type. The values include DeviceReg, DeviceCmd, DeviceLocation, DeviceMod, DeviceDel, and DeviceLicense.

timeout

Mandatory

Integer

body

Indicates the timeout duration of a task, in minutes. The value range is 10–2880.

tags

Optional

List<TagDTO2>

body

Indicates the tag list.

ObjectNode structure

Parameter

Mandatory or Optional

Type

Location

Description

type

mandatory

String

body

Indicates the batch command type. This parameter is mandatory when taskType is set to DeviceCmd. The options include DeviceList, DeviceType, DeviceArea, GroupList, Broadcast, and GroupIdList.

deviceList

Conditionally mandatory

List<String>

body

Indicates the device ID list. This parameter is mandatory when type is set to DeviceList.

deviceType

Conditionally mandatory

String

body

Indicates the device type. This parameter is mandatory when type is set to DeviceType. Set this parameter to the value defined in the profile file.

manufacturerId

Conditionally optional

String

body

Identifies the manufacturer. This parameter is mandatory when type is set to DeviceType. Set this parameter to the value defined in the profile file.

model

Conditionally optional

String

body

Indicates the device model. This parameter is mandatory when type is set to DeviceType. Set this parameter to the value defined in the profile file.

deviceLocation

Conditionally mandatory

String

body

Indicates the location of the device. This parameter is mandatory when type is set to DeviceArea.

groupList

Conditionally mandatory

List<String>

body

Indicates the group ID list or device group name list. When type is set to GroupIdList, set this parameter to the group ID. When type is set to GroupList, set this parameter to the device group name.

command

mandatory

CommandDTO

body

Indicates the command information.

callbackUrl

Conditionally optional

String

body

Indicates the push address of the command execution result.

maxRetransmit

Conditionally optional

Integer(0~3)

body

Indicates the maximum number of retransmissions of a command. The value ranges from 0 to 3.

groupTag

Conditionally optional

String

body

Indicates the group tag.

CommandDTO structure

Parameter

Mandatory or Optional

Type

Location

Description

serviceId

Mandatory

String(1-64)

body

Identifies the service corresponding to the command. The value of this parameter must be the same as the value of serviceId defined in the profile file.

method

Mandatory

String(1-128)

body

Indicates the name of a specific command under the service. The value of this parameter must be the same as the command name defined in the profile file.

paras

Optional

ObjectNode

body

Indicates a command parameter in the jsonString format. The value consists of key-value pairs. Each key is the paraName parameter in commands in the profile file. The specific format depends on the application and device.

TagDTO2 structure

Parameter

Mandatory or Optional

Type

Location

Description

tagName

Mandatory

String(1-128)

body

Indicates the tag name.

tagValue

Mandatory

String(1-1024)

body

Indicates the tag value.

Return Value

BatchTaskCreateOutDTO structure

Parameter

Type

Description

taskID

String

Identifies a batch task.

Error Codes

HTTP Status Code

Error Code

Error Description

Remarks

200

100203

The application is not existed.

The application does not exist.

Recommended handling:

  • Check whether appId carried in the HTTP request header is correct.
  • Check whether appId in the request path (URL) is correct.

200

101001

Resource doesn't exist.

The resource does not exist.

200

105001

The batchTask count has reached the limit.

If the number of unfinished tasks is greater than or equal to 10, a message is returned, indicating that the number of tasks reaches the limit.

200

105002

The batchTask name has exist.

The task name exists.

Recommended handling: Change the task name.

400

105201

The tagName and tagValue has been used on the platform.

The tagName and tagValue have been used on the IoT platform.

400

50400

The input is invalid.

An input parameter is invalid.

Recommended handling: Check whether parameters carried in the API call request are valid.

401

100028

The user has no right.

The user has no operation permission.

403

100203

The application is not existed.

The application does not exist.

Recommended handling:

  • Check whether appId carried in the HTTP request header is correct.
  • Check whether appId in the request path (URL) is correct.

403

100217

The application hasn't been authorized.

The application has not been authorized.

Recommended handling: In scenarios where applications are not authorized, ensure that request parameter appId is null.

403

1010009

app throttle exceed.

The NA calls the API at a frequency that exceeds the flow control threshold (100 calls per minute by default).

Recommended handling: Contact IoT platform maintenance personnel to adjust the flow control threshold or control the API call frequency.

403

1010005

App_key or access_token is invalid.

The access token is invalid.

Recommended handling: Check whether accessToken carried in the API request is correct.

404

105202

The tag is not existed.

The tag does not exist.

500

100203

The application is not existed.

The application does not exist.

Recommended handling:

  • Check whether appId carried in the HTTP request header is correct.
  • Check whether appId in the request path (URL) is correct.

500

50252

Internal server error.

An internal server error occurs.

Recommended handling: An internal error occurs on the IoT platform. Contact IoT platform maintenance personnel.