Updated on 2024-06-27 GMT+08:00

Query All Tunnels of a Device

Function

You can use this API to query the data of all device tunnels in a project for device management. This API is used by an application to query the status of device tunnels from the IoT platform.

  • This API is not supported by Basic editions.

  • For details, see [Remote Login] (https://support.huaweicloud.com/intl/en-us/usermanual-iothub/iot_01_00301.html).

Debugging

You can debug this API through automatic authentication in API Explorer or use the SDK sample code generated by API Explorer.

URI

GET /v5/iot/{project_id}/tunnels

Table 1 Path Parameters

Parameter

Mandatory

Type

Description

project_id

Yes

String

Parameter description: project ID. For details about how to obtain the project ID, see Obtaining a Project ID.

Table 2 Query Parameters

Parameter

Mandatory

Type

Description

device_id

No

String

Parameter description: device ID.

Request Parameters

Table 3 Request header parameters

Parameter

Mandatory

Type

Description

X-Auth-Token

No

String

Parameter description: user token. You can obtain the token by calling the IAM API Obtaining a User Token Through Password Authentication. In the returned response header, X-Subject-Token is the desired user token. For details about how to obtain the token, see Token Authentication.

Instance-Id

No

String

Parameter description: instance ID. Unique identifier of each instance in the physical multi-tenant scenario. Mandatory for professional editions and recommended in other cases. Log in to the IoTDA console and choose Overview in the navigation pane to view the instance ID. For details, see Viewing Instance Details.

Response Parameters

Status code: 200

Table 4 Response body parameters

Parameter

Type

Description

tunnels

Array of TunnelInfo objects

Tunnel information list.

Array Length: 0 - 100

Table 5 TunnelInfo

Parameter

Type

Description

tunnel_id

String

Tunnel ID.

device_id

String

Device ID.

create_time

String

Time when a tunnel was created. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

closed_time

String

Time when a tunnel was updated. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

status

String

Tunnel status. Options: CLOSED and OPEN.

source_connect_state

ConnectState object

Access end (console) status.

device_connect_state

ConnectState object

Device status.

Table 6 ConnectState

Parameter

Type

Description

last_update_time

String

Time when the latest tunnel status was updated. The value is in the format of yyyyMMdd'T'HHmmss'Z', for example, 20151212T121212Z.

status

String

Client connection status. Options: CONNECTED and DISCONNECTED.

Example Requests

Queries device tunnels in a list.

GET https://{endpoint}/v5/iot/{project_id}/tunnels

Example Responses

Status code: 200

All tunnel information of the device is successfully queried.

{
  "tunnels" : [ {
    "tunnel_id" : "d144a524-1997-4b99-94bf-f27128da8a34",
    "device_id" : "1a7ffc5c-d89c-44dd-8265-b1653d951ce0",
    "create_time" : "20190303T081011Z",
    "closed_time" : "20190303T081011Z",
    "status" : "CLOSED",
    "source_connect_state" : {
      "last_update_time" : "20190303T081011Z",
      "status" : "CONNECTED"
    },
    "device_connect_state" : {
      "last_update_time" : "20190303T081011Z",
      "status" : "CONNECTED"
    }
  } ]
}

Status Codes

Status Code

Description

200

All tunnel information of the device is successfully queried.

400

Invalid value.

401

Unauthorized

403

Authentication failed.

500

Internal Server Error

Error Codes

See Error Codes.