IoTIoT

Compute
Elastic Cloud Server
Bare Metal Server
Auto Scaling
Image Management Service
Dedicated Host
FunctionGraph
Networking
Virtual Private Cloud
Elastic IP
Elastic Load Balance
NAT Gateway
Direct Connect
Virtual Private Network
Domain Name Service
VPC Endpoint
Cloud Connect
Enterprise Switch
Security & Compliance
Anti-DDoS
Web Application Firewall
Host Security Service
Data Encryption Workshop
Database Security Service
Advanced Anti-DDoS
Data Security Center
Container Guard Service
Situation Awareness
Managed Threat Detection
Compass
Cloud Certificate Manager
Anti-DDoS Service
Databases
Relational Database Service
Document Database Service
Data Admin Service
Data Replication Service
GaussDB NoSQL
GaussDB(for MySQL)
Distributed Database Middleware
GaussDB(for openGauss)
Developer Services
ServiceStage
Distributed Cache Service
Simple Message Notification
Application Performance Management
Application Operations Management
Blockchain Service
API Gateway
Cloud Performance Test Service
Distributed Message Service for Kafka
Distributed Message Service for RabbitMQ
Distributed Message Service for RocketMQ
Cloud Service Engine
DevCloud
ProjectMan
CodeHub
CloudRelease
CloudPipeline
CloudBuild
CloudDeploy
Cloud Communications
Message & SMS
Cloud Ecosystem
Marketplace
Partner Center
User Support
My Account
Billing Center
Cost Center
Resource Center
Enterprise Management
Service Tickets
HUAWEI CLOUD (International) FAQs
ICP License Service
Support Plans
Customer Operation Capabilities
Partner Support Plans
Professional Services
enterprise-collaboration
Meeting
IoT
IoT
Intelligent EdgeFabric
DeveloperTools
SDK Developer Guide
API Request Signing Guide
Terraform
HCloud CLI
Updated at: Feb 24, 2022 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 Prototype

Method

POST

URL

https://server:port/iocm/app/batchtask/v1.1.0/tasks

Transport Protocol

HTTPS

Request Parameters

Parameter

Mandatory or Optional

Type

Location

Description

app_key

Mandatory

String

header

Identifies an application that can be accessed on the IoT platform. The value of this parameter is allocated by the IoT platform when the application is created on the platform.

Authorization

Mandatory

String

header

Indicates the authentication information for accessing the IoT platform. The value is Bearer {accessToken}, in which {accessToken} indicates the access token returned by the Authentication API.

appId

Mandatory

String(64)

body

Identifies an application that can be accessed on the IoT platform. The value of this parameter is allocated by the IoT platform when the application is created on the platform. Set this parameter to the value of appId of the authorized application.

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 DeviceCmd.

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. 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. The value must be the same as that defined in the profile file.

manufacturerId

Conditionally optional

String

body

Identifies a manufacturer. This parameter is mandatory when type is set to DeviceType. The value must be the same as that defined in the profile file.

model

Conditionally optional

String

body

Indicates the model of the device. This parameter is mandatory when type is set to DeviceType. The value must be the same as that 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

optional

String

body

Indicates the push address of the command execution result.

maxRetransmit

optional

Integer(0-3)

body

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

groupTag

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.

Response Parameters

Status Code: 200 OK

Parameter

Type

Description

taskID

String

Identifies a batch task.

Request Example

Method: POST
Request:
https://server:port/iocm/app/batchtask/v1.1.0/tasks
Header:
app_key: ******
Authorization: Bearer ******
Content-Type: application/json
Body:
{
  "appId": "******",
  "timeout": 1000,
  "taskName": "******",
  "taskType": "DeviceCmd",
  "param": {
    "type": "******",
    "deviceList": [
      "********",
      "********",
      "********"
    ],
    "command": {
      "serviceId": "********",
      "method": "********",
      "paras": {
        "paraName1": "paraValue1",
        "paraName2": "paraValue2"
      }
    }

  }
}

Response Example

Response:
Status Code: 200 OK
Content-Type: application/json
Body:
{
  "taskID": "******"
}

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.

Did you find this page helpful?

Failed to submit the feedback. Please try again later.

Which of the following issues have you encountered?







Please complete at least one feedback item.

Content most length 200 character

Content is empty.

OK Cancel