Batch Create Devices¶
Batch create devices.
Operation Permissions¶
Required Authorization  | 
Required Operation Permission  | 
|---|---|
Device Management  | 
Full Access  | 
Prerequisite¶
Ensure the product to create this device under exists.
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  | 
CreateOption Struct ¶
Name  | 
Mandatory/Optional  | 
Data Type  | 
Description  | 
|---|---|---|---|
productKey  | 
Mandatory  | 
String  | 
The product key.  | 
deviceName  | 
Mandatory  | 
StringI18n  | 
The device name. For more details on the structure and locales supported, see Internationalized name struct.  | 
timezone  | 
Mandatory  | 
String  | 
Timezone of the device’s location. For details, see Timezone representation.  | 
deviceAttributes  | 
Optional  | 
Map  | 
The device attributes.  | 
deviceKey  | 
Optional  | 
String  | 
The device key.  | 
deviceDesc  | 
Optional  | 
String  | 
The device description.  | 
deviceTags  | 
Optional  | 
Map  | 
The device tags. (The Key and Value are of String type.) For details, see How to use tags.  | 
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.  | 
EnosBatchEachData Struct ¶
Name  | 
Data Type  | 
Description  | 
|---|---|---|
code  | 
Integer  | 
Failed or succeeded to create an alert. 0: succeeded, -1: failed.  | 
msg  | 
String  | 
Returns   | 
data  | 
DeviceCreateResult Struct  | 
The returned results of the device creation. For details, see DeviceCreateResult Struct.  | 
DeviceCreateResult Struct ¶
Name  | 
Data Type  | 
Description  | 
|---|---|---|
productKey  | 
String  | 
The product key.  | 
deviceKey  | 
String  | 
The device key.  | 
deviceSecret  | 
String  | 
The device connection key.  | 
assetId  | 
String  | 
The asset ID.  | 
Error Codes¶
Code  | 
Message  | 
Description  | 
|---|---|---|
11702  | 
DeviceKey existed  | 
The   | 
11714  | 
Generate deviceKey failed  | 
The key of the device cannot be assigned temporarily (when the   | 
11739  | 
Exceed max device size  | 
A product can have a max of 10,000 devices under it. This operation will exceed the limit.  | 
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
}
Java SDK Sample¶
import com.envision.apim.poseidon.config.PConfig;
import com.envision.apim.poseidon.core.Poseidon;
import com.envisioniot.enos.api.common.constant.common.StringI18n;
import com.envisioniot.enos.connect_service.v2_1.device.BatchCreateDeviceRequest;
import com.envisioniot.enos.connect_service.v2_1.device.BatchCreateDeviceResponse;
import com.envisioniot.enos.connect_service.v2_1.device.CreateDeviceRequest;
import com.envisioniot.enos.connect_service.v2_1.device.CreateDeviceResponse;
import com.envisioniot.enos.connect_service.vo.DeviceCreateVo;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
public class CreateDeviceBatch {
    public static void main(String[] args) {
      final String appKey = "yourAppKey";
      final String appSecret = "yourAppSecret";
      final String serverUrl = "yourServerUrl";
      final String orgId = "yourOrgID";
      BatchCreateDeviceRequest request = new BatchCreateDeviceRequest();
      request.setOrgId(orgId);
      DeviceCreateVo deviceCreateVo = new DeviceCreateVo();
      deviceCreateVo.setProductKey("yourProductKey");
      StringI18n stringI18n = new StringI18n();
      stringI18n.setDefaultValue("Device Name");
      Map<String, Object> deviceAttributes = new HashMap<>();
      //deviceAttributes.put("serial",111111);
      Map<String, String> deviceTags = new HashMap<>();
      deviceTags.put("tag1", "tag value");
      deviceCreateVo.setDeviceAttributes(deviceAttributes);
      deviceCreateVo.setDeviceTags(deviceTags);
      deviceCreateVo.setTimezone("+08:00");
      deviceCreateVo.setDeviceName(stringI18n);
      DeviceCreateVo deviceCreateVo2 = new DeviceCreateVo();
      deviceCreateVo2.setProductKey("yourProductKey2");
      StringI18n stringI18n2 = new StringI18n();
      stringI18n2.setDefaultValue("Device Name 2");
      Map<String, Object> device2Attributes = new HashMap<>();
      //device2Attributes.put("serial",222222);
      Map<String, String> device2Tags = new HashMap<>();
      device2Tags.put("tag2", "tag value");
      deviceCreateVo2.setDeviceAttributes(device2Attributes);
      deviceCreateVo2.setDeviceTags(device2Tags);
      deviceCreateVo2.setTimezone("+08:00");
      deviceCreateVo2.setDeviceName(stringI18n2);
      request.setDeviceList(Arrays.asList(deviceCreateVo,deviceCreateVo2));
      BatchCreateDeviceResponse response = Poseidon.config(PConfig.init().appKey(appKey).appSecret(appSecret).debug())
        .url(serverUrl)
        .getResponse(request, BatchCreateDeviceResponse.class);
  }
}