Updated on 2023-11-14 GMT+08:00

Query Device Tunnels

Function

You can use this API to query the information and connection status of a device tunnel in a project. 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/{tunnel_id}

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.

tunnel_id

Yes

String

Tunnel ID.

Minimum: 1

Maximum: 128

Request Parameters

Table 2 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 3 Response body parameters

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 4 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 tunnel details of a device.

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

Example Responses

Status code: 200

OK

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

OK

400

Invalid value.

403

Authentication failed.

404

The tunnel does not exist.

Error Codes

See Error Codes.