Updated on 2022-06-30 GMT+08:00

Querying 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 in API Explorer.

URI

Request Method

GET

URI

/v5/iot/{project_id}/batchtasks

Transport Protocol

HTTPS

Request Parameters

Parameter

Mandatory

Type

Location

Description

X-Auth-Token

Yes

String

Header

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

Header

Instance ID. This parameter is required only when the API is called from the management plane in the physical multi-tenant scenario.

project_id

Yes

String

Path

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

app_id

No

String

Query

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.

The value is a string of no more than 36 characters. Only letters, digits, underscores (_), and hyphens (-) are allowed.

task_type

Yes

String

Query

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

status

No

String

Query

(Optional) Batch task status.

Options:

  • Initializing: The batch task is being initialized.
  • Waitting: The batch task is waiting to be executed.
  • Processing: The batch task is being executed.
  • Success: The batch task is executed.
  • Fail: The batch task fails to be executed.
  • PartialSuccess: Only some subtasks in the batch task are executed.
  • Stopped: The batch task is stopped.

limit

No

Integer

Query

Number of records to display on each page.

The value is an integer ranging from 1 to 50. The default value is 10.

marker

No

String

Query

ID of the last record in the previous query. The value is returned by the platform during the previous query. The platform queries records in descending order based on the marker value. The latest record has a larger ID. If marker is specified, only the data 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.

The value is a string of 24 hexadecimal characters. The default value is ffffffffffffffffffffffff.

offset

No

Integer

Query

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.

The value is an integer ranging from 0 to 500. The default value is 0.

Response Parameters

Parameter

Type

Description

batchtasks

List<Task>

Batch task list.

page

Page Object

Pagination information of the query results.

Table 1 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

targets

List<String>

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

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-related 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-related 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-related parameters, for example, {"shadow": [{"service_id": "WaterMeter","desired": {"temperature": "60"}}]}. For details, see Configuring Desired Device Shadow Data.

task_policy

TaskPolicy Object

Policies for executing the task.

status

String

(Optional) Batch task status. Options:

  • Initializing: The batch task is being initialized.
  • Waitting: The batch task is waiting to be executed.
  • Processing: The batch task is being executed.
  • Success: The batch task is executed.
  • Fail: The batch task fails to be executed.
  • PartialSuccess: Only some subtasks in the batch task are executed.
  • Stopped: The batch task is 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 2 TaskPolicy

Parameter

Type

Description

schedule_time

String

Time when the task is executed.

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

Number of automatic retries upon failure for subtasks.

This parameter is mandatory if retry_interval is specified. Up to five retries are supported.

retry_interval

Integer

Interval for automatic retries upon failure for subtasks, in minutes.

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.

Table 3 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.

Table 4 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 Request

GET https://{Endpoint}/v5/iot/{project_id}/batchtasks?app_id={app_id}&task_type={task_type}&status={status}&limit={limit}&marker={marker}&offset={offset}
Content-Type: application/json
X-Auth-Token: ********
Instance-Id: ********

Example Response

Status Code: 200 OK

Content-Type: application/json

{
  "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"
  }
}