Updated on 2024-06-27 GMT+08:00

Query the Batch Task List

Function

This API is used by an application to query the batch task list on the IoT platform. Each task includes the task content, task status, and task completion statistics.

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

URI

GET /v5/iot/{project_id}/batchtasks

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Parameter description: project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

app_id

No

String

Parameter description: resource space ID. This parameter is optional. If you have multiple resource spaces, you can specify this parameter to query tasks in a specified resource space. If this parameter is not carried, tasks in all resource spaces are queried. Value: The value can contain a maximum of 36 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

task_type

Yes

String

Parameter description: batch task type. Options:

  • softwareUpgrade: software upgrade task

  • firmwareUpgrade: firmware upgrade task

  • createDevices: batch device creation task

  • deleteDevices: batch device deletion task

  • freezeDevices: batch device freezing task

  • unfreezeDevices: batch device unfreezing task

  • createCommands: task for creating synchronous commands in batches

  • createAsyncCommands: task for creating asynchronous commands in batches

  • createMessages: batch message creation task

  • updateDeviceShadows: task for configuring device shadows in batch

  • updateDevices: batch device update task

status

No

String

Parameter description: Indicates the status of the batch task. This parameter is optional. Options:

  • Initializing: The task is being initialized.

  • Waitting: The task is waiting to be executed.

  • Processing: The task is being executed.

  • Success: The task is executed.

  • Fail: The task execution failed.

  • PartialSuccess: Only some subtasks in the batch task are executed.

  • Stopped: The task is stopped.

  • Stopping: The task is being stopped.

limit

No

Integer

Parameter description: number of records to display on each page. Value: The value is an integer ranging from 1 to 50. The default value is 10.

Minimum: 1

Maximum: 50

Default: 10

marker

No

String

Parameter description: ID of the last record in the previous query. The value is returned by the platform during the previous query. Records are queried in descending order of record IDs (the marker value). A newer record will have a larger ID. If marker is specified, only the records whose IDs are smaller than marker are queried. If marker is not specified, the query starts from the record with the largest ID, that is, the latest record. If all data needs to be queried in sequence, this parameter must be filled with the value of marker returned in the last query response each time. Value: The value is a string of 24 hexadecimal characters. The default value is ffffffffffffffffffffffff.

Default: ffffffffffffffffffffffff

offset

No

Integer

Parameter description: If offset is set to N, the query starts from the N+1 record after the last record in the previous query. The value is an integer ranging from 0 to 500. The default value is 0. If offset is set to 0, the output starts from the first record after the last record in the previous query. To ensure API performance, you can use this parameter together with marker to turn pages. For example, if there are 50 records on each page, you can directly specify offset to jump to the specified page within page 1 and 11. If you want to view records displayed on pages 12 to 22, you need to use the marker value returned on page 11 as the marker value for the next query. Value: The value is an integer ranging from 0 to 500. The default value is 0.

Minimum: 0

Maximum: 500

Default: 0

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

Parameter description: user token. You can obtain the token by calling the IAM API Obtaining a User Token Through Password Authentication. X-Subject-Token in the response header returned by the API is the desired user token. For details about how to obtain the token, see Token Authentication.

Instance-Id

No

String

Parameter description: instance ID. Unique identifier of each instance in the physical multi-tenant scenario. Mandatory for professional editions and recommended in other cases. Log in to the IoTDA console and choose Overview in the navigation pane to view the instance ID. For details, see Viewing Instance Details.

Minimum: 1

Maximum: 36

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

batchtasks

Array of Task objects

Batch task list.

page

Page object

Pagination information of the query results.

Table 5 Task

Parameter

Type

Description

task_id

String

Batch task ID. It is allocated by the platform during batch task creation.

task_name

String

Batch task name.

task_type

String

Batch task type. Options:

  • softwareUpgrade: software upgrade task

  • firmwareUpgrade: firmware upgrade task

  • createDevices: batch device creation task

  • deleteDevices: batch device deletion task

  • freezeDevices: batch device freezing task

  • unfreezeDevices: batch device unfreezing task

  • createCommands: task for creating synchronous commands in batches

  • createAsyncCommands: task for creating asynchronous commands in batches

  • createMessages: batch message creation task

  • updateDeviceShadows: task for configuring device shadows in batch

  • updateDevices: batch device update task

task_mode

String

Parameter description: batch task mode. Currently, only the gateway mode is supported. This parameter is supported when task_type is set to firmwareUpgrade or softwareUpgrade. In the software/firmware upgrade scenario, if the device to be upgraded is a child device of a gateway, the version information obtaining notification and upgrade notification delivered by the IoT platform carry task_id (ID of the software/firmware upgrade batch task) and sub_device_count (number of child devices to be upgraded in a batch task). Value: GATEWAY (gateway mode).

task_ext_info

Object

Parameter description: extended information of batch tasks This parameter is supported when task_type is set to firmwareUpgrade or softwareUpgrade. In the software/firmware upgrade scenario, this parameter is carried in the version information obtaining notification and upgrade notification delivered by the IoT platform. Value: a maximum of 512 characters.

Maximum: 512

targets

Array of strings

Batch task targets. When task_type is set to firmwareUpgrade, softwareUpgrade, deleteDevices, freezeDevices, unfreezeDevices, createCommands, createAsyncCommands, createMessages, or updateDeviceShadows, set this parameter to a device ID list.

targets_filter

Map<String,Object>

Parameters for filtering task targets. The value is in JSON format (key-value pairs). Supported filter key is group_ids and its value is a list of group IDs, for example, ["e495cf17-ff79-4294-8f64-4d367919d665"]. Devices matching the filter will become the task targets.

document

Object

Task execution data file in JSON format. When task_type is set to softwareUpgrade or firmwareUpgrade, the JSON file contains the key-value pair. Set key to package_id and value to IDs of the software or firmware packages uploaded on the platform. IDs can be obtained from the software library on the platform. When task_type is set to createCommands, the JSON file contains command parameters, for example, {"service_id":"water","command_name":"ON_OFF","paras":{"value":"ON"}}. For details, see Synchronous Device Command APIs. When task_type is set to createAsyncCommands, the JSON file contains command parameters, for example, {"service_id":"water","command_name":"ON_OFF","paras":{"value":"ON"},"expire_time":0,"send_strategy":"immediately"}. For details, see Asynchronous Device Command APIs. When task_type is set to updateDeviceShadows, the JSON file contains command parameters, for example, {"shadow": [{"service_id": "WaterMeter","desired": {"temperature": "60"}}]}. For details, see Configuring Desired Properties in a Device Shadow.

task_policy

TaskPolicy object

Policies for executing the task.

status

String

Indicates the status of a batch task. This parameter is optional. Options:

  • Initializing: The task is being initialized.

  • Waitting: The task is waiting to be executed.

  • Processing: The task is being executed.

  • Success: The task is executed.

  • Fail: The task execution failed.

  • PartialSuccess: Only some subtasks in the batch task are executed.

  • Stopped: The task is stopped.

  • Stopping: The task is being stopped.

status_desc

String

Description of the batch task status (including the error information of the parent task).

task_progress

TaskProgress object

Subtask execution statistics.

create_time

String

Time when the batch task was created. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

Table 6 TaskPolicy

Parameter

Type

Description

schedule_time

String

Parameter description: time when the task is executed. Value: The task is executed within 7 days. If this parameter is not specified, the task is executed immediately. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

retry_count

Integer

Parameter description: number of automatic retries upon failure for subtasks. Value: This parameter is mandatory if retry_interval is specified. Up to five retries are supported.

Minimum: 1

Maximum: 5

retry_interval

Integer

Parameter description: interval for automatic retries upon failure for subtasks, in minutes. Value: The maximum value is 1440 (24 hours). If this parameter is not passed, subtasks will not be retried. This parameter is mandatory if retry_count is specified.

Minimum: 0

Maximum: 1440

Table 7 TaskProgress

Parameter

Type

Description

total

Integer

Total number of subtasks.

processing

Integer

Number of subtasks that are being executed.

success

Integer

Number of subtasks that are executed.

fail

Integer

Number of subtasks that fail.

waitting

Integer

Number of subtasks to execute.

fail_wait_retry

Integer

Number of subtasks waiting for retry.

stopped

Integer

Number of stopped subtasks.

removed

Integer

Indicates the number of removed subtasks.

Table 8 Page

Parameter

Type

Description

count

Long

Total number of records that meet the query conditions.

marker

String

ID of the last record in this query, which can be used in the next query.

Example Requests

Queries all batch tasks in a list.

GET https://{endpoint}/v5/iot/{project_id}/batchtasks

Example Responses

Status code: 200

OK

{
  "batchtasks" : [ {
    "task_id" : "5c8ba99030344005c02316ad",
    "task_name" : "testname",
    "task_type" : "softwareUpgrade",
    "targets" : [ "e495cf17-ff79-4294-8f64-4d367919d665" ],
    "targets_filter" : {
      "group_ids" : [ "e495cf17-ff79-4294-8f64-4d367919d665" ]
    },
    "document" : {
      "package_id" : "32822e5744a45ede319d2c50"
    },
    "task_policy" : {
      "schedule_time" : "20151212T121212Z",
      "retry_count" : 5,
      "retry_interval" : 60
    },
    "status" : "Success",
    "status_desc" : "string",
    "task_progress" : {
      "total" : 0,
      "processing" : 0,
      "success" : 0,
      "fail" : 0,
      "waitting" : 0,
      "fail_wait_retry" : 0,
      "stopped" : 0
    },
    "create_time" : "20151212T121212Z"
  } ],
  "page" : {
    "count" : 10,
    "marker" : "5c90fa7d3c4e4405e8525079"
  }
}

Status Codes

Status Code

Description

200

OK

400

Bad Request

401

Unauthorized

403

Forbidden

500

Internal Server Error

Error Codes

See Error Codes.