更新时间:2024-09-23 GMT+08:00
分享

查询实例列表

功能介绍

用户可以调用此接口查询设备接入实例列表。

调用方法

请参见如何调用API

URI

GET /v5/iot/{project_id}/iotda-instances

表1 路径参数

参数

是否必选

参数类型

描述

project_id

String

参数说明:项目ID。获取方法请参见 获取项目ID

表2 Query参数

参数

是否必选

参数类型

描述

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值。

name

String

参数说明:设备接入实例名称,匹配规则为模糊匹配。

取值范围:由中文字符,英文字母、数字及“_”、“-”组成,且长度为[1-64]个字符。

instance_type

String

参数说明:实例类型。

取值范围

  • standard:标准版实例

  • enterprise:企业版实例

请求参数

表3 请求Header参数

参数

是否必选

参数类型

描述

X-Auth-Token

String

参数说明:用户Token。通过调用IAM服务 获取IAM用户Token接口获取,接口返回的响应消息头中“X-Subject-Token”就是需要获取的用户Token。简要的获取方法样例请参见 Token认证

响应参数

状态码: 200

表4 响应Body参数

参数

参数类型

描述

count

Integer

参数说明:设备接入实例的总数。

marker

String

参数说明:本次分页查询结果中最后一条记录的ID,可在下一次分页查询时使用。

instances

Array of QueryInstanceSimplify objects

参数说明:设备接入实例的详情列表。

表5 QueryInstanceSimplify

参数

参数类型

描述

instance_type

String

参数说明:实例类型。

取值范围

  • standard:标准版实例

  • enterprise:企业版实例

instance_id

String

参数说明:实例ID。

取值范围:长度不超过36,由小写字母[a-f]、数字、连接符(-)的组成。

name

String

参数说明:实例名称

取值范围:由中文字符,英文字母、数字及“_”、“-”组成,且长度为[1-64]个字符。

charge_mode

String

参数说明:实例的付费方式。

取值范围

  • prePaid:包年/包月

  • postPaid:按需计费

flavor

Flavor object

参数说明:设备接入实例的规格参数。

status

String

参数说明:实例状态。

取值范围

  • CREATING:实例正在创建

  • ACTIVE:实例正常

  • FROZEN:实例冻结

  • TRADING: 实例正在进行交易

  • MODIFYING:实例正在变更规格

  • FAILED:实例创建失败

create_time

String

参数说明:实例的创建时间。时间格式例如:2023-01-28T06:57:52Z。

update_time

String

参数说明:实例的最近一次更新的时间。时间格式例如:2023-01-28T06:57:52Z。

enterprise_project_id

String

参数说明:企业项目Id。

表6 Flavor

参数

参数类型

描述

type

String

参数说明:待创建设备接入实例的规格名称。详情请参见产品规格说明中的规格编码。

size

Integer

参数说明:待创建设备接入标准版实例的单元数量。详情请参见产品规格说明。当instance_type是standard时,该参数必填。

请求示例

列表查询所有实例。

GET https://{endpoint}/v5/iot/{project_id}/iotda-instances

响应示例

状态码: 200

OK

{
  "count" : 1,
  "marker" : 1805431584415871305,
  "instances" : [ {
    "instance_type" : "standard",
    "instance_id" : "8561675c-d8a3-4956-9884-9cf9cbdd3134",
    "name" : "iotda_instance",
    "flavor" : {
      "type" : "iotda.standard.s1",
      "size" : 1
    },
    "status" : "ACTIVE",
    "create_time" : "2023-01-28T06:57:52Z",
    "update_time" : "2023-01-28T06:57:52Z",
    "enterprise_project_id" : "d22e47e9-cfad-4254-8a29-d2a56a07681d"
  } ]
}

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
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 ListInstancesSolution {

    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();
        ListInstancesRequest request = new ListInstancesRequest();
        try {
            ListInstancesResponse response = client.listInstances(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
# 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 = ListInstancesRequest()
        response = client.list_instances(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
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.ListInstancesRequest{}
	response, err := client.ListInstances(request)
	if err == nil {
        fmt.Printf("%+v\n", response)
    } else {
        fmt.Println(err)
    }
}

更多编程语言的SDK代码示例,请参见API Explorer的代码示例页签,可生成自动对应的SDK代码示例。

状态码

状态码

描述

200

OK

400

Bad Request

401

Unauthorized

错误码

请参见错误码

相关文档