V2.0 Batch Create Devices


Batch create devices.


This API is available in EnOS 2.1.0 and above. Version 2.4 has been added and it is recommended to use V2.4 Batch Create Devices.

Operation Permissions


Before invoking this API, ensure that the service account has been authorized the policy that includes the following service(s) and action permission(s). For how to authorize the service account, see Managing Service Accounts.


Required Service

Required Operation Permission

Device Management Service

Full Access

Prerequisite

  • The product to create this device under exists.

  • You have learnt the Limitations about devices.

Request Format

POST https://{apigw-address}/connect-service/v2.0/devices?action=batchCreate

Request Parameters (URI)

Name

Location (Path/Query)

Mandatory/Optional

Data Type

Description

orgId

Query

Mandatory

String

The organization ID which the asset belongs to. How to get orgId>>

Request Parameters (Body)

Name

Mandatory/Optional

Data Type

Description

deviceList

Mandatory

Array of CreateOption Structs

The list of devices to create. For more details, see CreateOption Struct

Response Parameters

Name

Data Type

Description

data

Array of EnosBatchEachData Struct

The list of success or failure messages. For more information, see EnosBatchEachData Struct.

successSize

Integer

The number of sucessfully created devices.

totalSize

Integer

The total number of devices to be created.

Error Codes

Samples

Request Sample

url:https://{apigw-address}/connect-service/v2.1/devices?action=batchCreate&orgId=yourOrgId
method: POST
requestBody:
{
  "deviceList":
  [
    {
      "productKey": "yourProductKey",
      "deviceName":
      {
        "defaultValue": "Device Name",
        "i18nValue":
        {
            "zh_CN": "设备名称",
            "en_US": "Device Name"
        }
      },
      "timezone": "+08:00",
      "deviceAttributes":
      {
        "serial": 111111
      },
      "deviceDesc": "Device description",
      "deviceTags":
      {
        "tag1": "tag value"
      }
    },
    {
      "productKey": "yourProductKey2",
      "deviceName":
      {
        "defaultValue": "Device Name 2",
        "i18nValue":
        {
            "zh_CN": "设备名称 2",
            "en_US": "Device Name 2"
        }
      },
      "timezone": "+08:00",
      "deviceAttributes":
      {
        "serial": 222222
      },
      "deviceDesc": "Device description 2",
      "deviceTags":
      {
        "tag2": "tag value"
      }
    }
  ]
}

Return Sample

{
  "code": 0,
  "msg": "OK",
  "requestId": "21938538-9266-495d-b1b9-b15597ad3e1f",
  "data":
  [
    {
      "code": 0,
      "msg": "OK",
      "data":
      {
        "assetId": "yourAssetId",
        "productKey": "yourProductKey",
        "deviceKey": "yourDeviceKey",
        "deviceSecret": "yourDeviceSecret"
      }
    },
    {
      "code": 0,
      "msg": "OK",
      "data":
      {
        "assetId": "yourAssetId2",
        "productKey": "yourProductKey2",
        "deviceKey": "yourDeviceKey2",
        "deviceSecret": "yourDeviceSecret2"
      }
    }
  ],
  "successSize": 2,
  "totalSize": 2
}

SDK Samples


You can access the SDK samples for Connection Service on GitHub: