查询实例任务列表
功能介绍
用户可以调用此接口查询设备接入实例任务列表。
接口约束:仅支持查询180天内的实例任务,实例任务的最大数量为20条。
调用方法
请参见如何调用API。
URI
GET /v5/iot/{project_id}/iotda-instances/{instance_id}/tasks
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
project_id |
是 |
String |
参数说明:项目ID。获取方法请参见 获取项目ID 。 |
instance_id |
是 |
String |
参数说明:实例ID。 取值范围:长度不超过36,由小写字母[a-f]、数字、连接符(-)的组成。 |
参数 |
是否必选 |
参数类型 |
描述 |
---|---|---|---|
offset |
否 |
Integer |
参数说明:表示从marker后偏移offset条记录开始查询。默认为0,取值范围为0-500的整数。当offset为0时,表示从marker后第一条记录开始输出。 - 限制offset最大值是出于API性能考虑,您可以搭配marker使用该参数实现翻页,例如每页50条记录,1-11页内都可以直接使用offset跳转到指定页,但到11页后,由于offset限制为500,您需要使用第11页返回的marker作为下次查询的marker,以实现翻页到12-22页。 取值范围:0-500的整数,默认为0。 |
limit |
否 |
Integer |
参数说明:分页查询时每页显示的记录数。 取值范围:1-500的整数,默认为500。 |
marker |
否 |
String |
上一次分页查询结果中最后一条记录的ID,在上一次分页查询时由物联网平台返回获得。分页查询时物联网平台是按marker也就是记录ID降序查询的,越新的数据记录ID也会越大。若填写marker,则本次只查询记录ID小于marker的数据记录。若不填写,则从记录ID最大也就是最新的一条数据开始查询。如果需要依次查询所有数据,则每次查询时必须填写上一次查询响应中的marker值。 |
请求参数
无
响应参数
状态码:200
参数 |
参数类型 |
描述 |
---|---|---|
page |
Page object |
查询批量分页结构体,定义了分页页码、每页记录数、记录总数、该页记录的最大Id。 |
tasks |
Array of InstanceTask objects |
实例任务列表 |
参数 |
参数类型 |
描述 |
---|---|---|
task_id |
String |
参数说明:实例任务Id。 取值范围:长度不超过64,由小写字母[a-f]、数字、连接符(-)的组成。 |
type |
String |
参数说明:实例任务类型。 取值范围:
|
status |
String |
参数说明:任务状态。 取值范围:
|
status_detail |
String |
参数说明:任务状态描述。 |
create_time |
String |
参数说明:实例任务的创建时间。格式为:"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" |
start_time |
String |
参数说明:实例任务的开始时间。格式为:"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" |
end_time |
String |
参数说明:实例任务的结束时间。格式为:"yyyy-MM-dd'T'HH:mm:ss.SSS'Z'" |
target_config |
TargetConfig object |
实例规格变更时,实例的目标规格配置。 |
operate_window |
OperateWindow object |
实例维护时间窗,用户在变更实例规格时,可以指定在该时间窗内进行变更。 |
参数 |
参数类型 |
描述 |
---|---|---|
flavor |
Flavor object |
参数说明:设备接入实例的规格参数。 |
charge_mode |
String |
参数说明:实例的付费方式。 取值范围:
|
请求示例
查询实例任务列表。
GET https://{endpoint}/v5/iot/{project_id}/iotda-instances/{instance_id}/tasks
响应示例
状态码:200
OK
{ "page" : { "count" : 1, "marker" : 1805431584415871305 }, "tasks" : [ { "task_id" : "075f413d-a3bb-4243-974d-8eb9221c2df8", "type" : "CREATE", "status" : "SUCCESS", "create_time" : "2020-08-19T01:52:49.493Z", "start_time" : "2020-08-19T01:52:49.492Z", "end_time" : "2020-08-19T01:52:49.492Z", "target_config" : null, "operate_window" : null }, { "task_id" : "075f413d-a3bb-4243-974d-8eb9221c1234", "type" : "MODIFY", "status" : "PENDING", "create_time" : "2021-08-19T01:52:49.493Z", "start_time" : "2021-08-19T01:52:49.492Z", "end_time" : "2021-08-19T01:52:49.492Z", "target_config" : { "flavor" : { "type" : "iotda.standard.s2", "size" : 2 } }, "operate_window" : { "start_time" : "18:00", "end_time" : "22:00" } } ] }
SDK代码示例
SDK代码示例如下。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 |
package com.huaweicloud.sdk.test; import com.huaweicloud.sdk.core.auth.ICredential; import com.huaweicloud.sdk.core.auth.BasicCredentials; import com.huaweicloud.sdk.core.exception.ConnectionException; import com.huaweicloud.sdk.core.exception.RequestTimeoutException; import com.huaweicloud.sdk.core.exception.ServiceResponseException; import com.huaweicloud.sdk.iotdm.v5.region.IoTDMRegion; import com.huaweicloud.sdk.iotdm.v5.*; import com.huaweicloud.sdk.iotdm.v5.model.*; public class ListInstanceTasksSolution { public static void main(String[] args) { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment String ak = System.getenv("CLOUD_SDK_AK"); String sk = System.getenv("CLOUD_SDK_SK"); String projectId = "{project_id}"; ICredential auth = new BasicCredentials() .withProjectId(projectId) .withAk(ak) .withSk(sk); IoTDMClient client = IoTDMClient.newBuilder() .withCredential(auth) .withRegion(IoTDMRegion.valueOf("<YOUR REGION>")) .build(); ListInstanceTasksRequest request = new ListInstanceTasksRequest(); request.withInstanceId("{instance_id}"); try { ListInstanceTasksResponse response = client.listInstanceTasks(request); System.out.println(response.toString()); } catch (ConnectionException e) { e.printStackTrace(); } catch (RequestTimeoutException e) { e.printStackTrace(); } catch (ServiceResponseException e) { e.printStackTrace(); System.out.println(e.getHttpStatusCode()); System.out.println(e.getRequestId()); System.out.println(e.getErrorCode()); System.out.println(e.getErrorMsg()); } } } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
# coding: utf-8 import os from huaweicloudsdkcore.auth.credentials import BasicCredentials from huaweicloudsdkiotdm.v5.region.iotdm_region import IoTDMRegion from huaweicloudsdkcore.exceptions import exceptions from huaweicloudsdkiotdm.v5 import * if __name__ == "__main__": # The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. # In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak = os.environ["CLOUD_SDK_AK"] sk = os.environ["CLOUD_SDK_SK"] projectId = "{project_id}" credentials = BasicCredentials(ak, sk, projectId) client = IoTDMClient.new_builder() \ .with_credentials(credentials) \ .with_region(IoTDMRegion.value_of("<YOUR REGION>")) \ .build() try: request = ListInstanceTasksRequest() request.instance_id = "{instance_id}" response = client.list_instance_tasks(request) print(response) except exceptions.ClientRequestException as e: print(e.status_code) print(e.request_id) print(e.error_code) print(e.error_msg) |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
package main import ( "fmt" "github.com/huaweicloud/huaweicloud-sdk-go-v3/core/auth/basic" iotdm "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5" "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/model" region "github.com/huaweicloud/huaweicloud-sdk-go-v3/services/iotdm/v5/region" ) func main() { // The AK and SK used for authentication are hard-coded or stored in plaintext, which has great security risks. It is recommended that the AK and SK be stored in ciphertext in configuration files or environment variables and decrypted during use to ensure security. // In this example, AK and SK are stored in environment variables for authentication. Before running this example, set environment variables CLOUD_SDK_AK and CLOUD_SDK_SK in the local environment ak := os.Getenv("CLOUD_SDK_AK") sk := os.Getenv("CLOUD_SDK_SK") projectId := "{project_id}" auth := basic.NewCredentialsBuilder(). WithAk(ak). WithSk(sk). WithProjectId(projectId). Build() client := iotdm.NewIoTDMClient( iotdm.IoTDMClientBuilder(). WithRegion(region.ValueOf("<YOUR REGION>")). WithCredential(auth). Build()) request := &model.ListInstanceTasksRequest{} request.InstanceId = "{instance_id}" response, err := client.ListInstanceTasks(request) if err == nil { fmt.Printf("%+v\n", response) } else { fmt.Println(err) } } |
更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。
状态码
状态码 |
描述 |
---|---|
200 |
OK |
400 |
Bad Request |
401 |
Unauthorized |
403 |
Forbidden |
错误码
请参见错误码。