更新时间:2023-02-06 GMT+08:00
示例一:使用模板文件批量创建设备
涉及接口
操作步骤
- 确定待创建设备所属的产品。
- 查询产品列表
- 接口信息
URL:GET /v5/iot/{project_id}/products
详情参见查询产品列表
- 请求示例
GET https://{Endpoint}/v5/iot/{project_id}/products?limit={limit}&marker={marker}&app_id={app_id}&offset={offset} Content-Type: application/json X-Auth-Token: ******** Instance-Id: ********
- 响应示例
Content-Type: application/json { "products" : [ { "app_id" : "jeQDJQZltU8iKgFFoW060F5SGZka", "app_name" : "testAPP01", "product_id" : "5ba24f5ebbe8f56f5a14f605", "name" : "Thermometer", "device_type" : "Thermometer", "protocol_type" : "CoAP", "data_format" : "binary", "manufacturer_name" : "ABC", "industry" : "smartCity", "description" : "this is a thermometer produced by Huawei", "create_time" : "20190303T081011Z" } ], "page" : { "count" : 10, "marker" : "5c90fa7d3c4e4405e8525079" } }
- 接口信息
- 根据实际需要选择产品,并记录产品的product_id。
- 查询产品列表
- 下载批量任务模板文件。
访问这里,下载模板文件。
- 填写模板文件中待创建设备的参数。
样例如下:
- 上传批量任务文件。
- 上传批量任务文件
- 接口信息
URL:POST /v5/iot/{project_id}/batchtask-files
详情参见上传批量任务文件
- 请求示例
POST https://{Endpoint}/v5/iot/{project_id}/batchtask-files Content-Type: multipart/form-data X-Auth-Token: ******** Instance-Id: ********
- 响应示例
Content-Type: application/json { "file_id" : "0c3c77dd-42a2-4309-9e10-da2e8bf64ac3", "file_name" : "BatchCreateDevices_test01.xlsx", "upload_time" : "20200617T081608Z" }
- 接口信息
- 记录批量任务文件“file_id”。
- 上传批量任务文件
- 创建批量任务
- 创建批量任务
- 接口信息
URL:POST /v5/iot/{project_id}/batchtasks
详情参见创建批量任务
- 请求示例
POST https://{Endpoint}/v5/iot/{project_id}/batchtasks Content-Type: application/json X-Auth-Token: ******** Instance-Id: ******** { "app_id" : "Ev8FVvCfOdQDzrFrxSOemiw_aMca", "task_name" : "BatchCommandTask", "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 }, "document_source" : "jeQDJQZltU8iKgFFoW060F5SGZka" }
- 响应示例
Content-Type: application/json { "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" }
- 接口信息
- 记录批量任务“task_id”。
- 创建批量任务
- 查询批量任务
- 查询批量任务
- 接口信息
URL:GET /v5/iot/{project_id}/batchtasks/{task_id}
详情参见查询批量任务
- 请求示例
GET https://{Endpoint}/v5/iot/{project_id}/batchtasks/{task_id}?limit={limit}&marker={marker}&offset={offset} Content-Type: application/json X-Auth-Token: ******** Instance-Id: ********
- 响应示例
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" }, "task_details" : [ { "target" : "e495cf17-ff79-4294-8f64-4d367919d665", "status" : "Success", "output" : "success", "error" : { "error_code" : "IOTDA.000002", "error_msg" : "The request is unauthorized." } } ], "page" : { "count" : 10, "marker" : "5c90fa7d3c4e4405e8525079" } }
- 接口信息
- 确认任务执行结果。
- 查询批量任务
父主题: 应用示例