From 1f8d3a029101c9f0caa380504bdc7a5d2791efc3 Mon Sep 17 00:00:00 2001 From: imbeacon Date: Tue, 20 May 2025 10:46:21 +0300 Subject: [PATCH] Added documentation about API to request all attributes from some scope --- _includes/docs/reference/coap-api.md | 94 ++++++++ _includes/docs/reference/http-api.md | 344 ++++++++++++++++++++++++++- _includes/docs/reference/mqtt-api.md | 41 ++++ 3 files changed, 478 insertions(+), 1 deletion(-) diff --git a/_includes/docs/reference/coap-api.md b/_includes/docs/reference/coap-api.md index d8e1f71f44..273f917576 100644 --- a/_includes/docs/reference/coap-api.md +++ b/_includes/docs/reference/coap-api.md @@ -227,6 +227,8 @@ This example shown with the coap-client instead of CoAP cli since CoAP cli does {% endcapture %} {% include templates/info-banner.md content=difference %} +##### Request specific client and shared attributes + {% capture tabspec %}coap-attributes-request A,Execute the command:,shell,resources/coap-attributes-request.sh,/docs/reference/resources/coap-attributes-request.sh{% endcapture %} {% include tabs.html %} @@ -245,6 +247,98 @@ However, it is still possible to have same keys for client, shared or even serve {% endcapture %} {% include templates/info-banner.md content=difference %} +{% if docsPrefix != "edge/" %} + +##### Request specific client attributes +In order to request specific client attributes, you can use the following command: + +```shell +coap-client -m get "coap://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/client?keys=attribute1,attribute2" +``` +{: .copy-code} +Where: + - **$THINGSBOARD_HOST_NAME** - your localhost, or the platform address. + - **$ACCESS_TOKEN** - your device access token. + +Result: + +```json +{"client":{"attribute2":true,"attribute1":"value1"}} +``` + +##### Request specific shared attributes +In order to request specific shared attributes, you can use the following command: + +```shell +coap-client -m get "coap://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/shared?keys=shared1" +``` +{: .copy-code} +Where: + - **$THINGSBOARD_HOST_NAME** - your localhost, or the platform address. + - **$ACCESS_TOKEN** - your device access token. + +Result: + +```json +{"shared":{"shared1":"value1"}} +``` + +##### Request all client and shared attributes + +In order to request all attributes, you can use the following command: + +```shell +coap-client -m get "coap://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes" +``` +{: .copy-code} +Where: + - **$THINGSBOARD_HOST_NAME** - your localhost, or the platform address. + - **$ACCESS_TOKEN** - your device access token. + +Result: + +```json +{"client":{"attribute2":true,"attribute1":"value1"},"shared":{"shared1":"value1"}} +``` + +#### Request all client attributes + +To request all client attributes from the server, you can use the following command: + + ```shell + coap-client -m get "coap://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/client" + ``` + {: .copy-code} +Where: + - **$THINGSBOARD_HOST_NAME** - your localhost, or the platform address. + - **$ACCESS_TOKEN** - your device access token. + +Result: + +```json +{"client":{"attribute2":true,"attribute1":"value1"}} +``` + +#### Request all shared attributes + +To request all shared attributes from the server, you can use the following command: + + ```shell + coap-client -m get "coap://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/shared" + ``` +{: .copy-code} +Where: + - **$THINGSBOARD_HOST_NAME** - your localhost, or the platform address. + - **$ACCESS_TOKEN** - your device access token. + +Result: + +```json +{"shared":{"shared1":"value1"}} +``` + +{% endif %} + ### Subscribe to attribute updates from the server In order to subscribe to shared device attribute changes, send GET request with Observe option. diff --git a/_includes/docs/reference/http-api.md b/_includes/docs/reference/http-api.md index 49a0d66f1e..9f3e6f1ba6 100644 --- a/_includes/docs/reference/http-api.md +++ b/_includes/docs/reference/http-api.md @@ -400,7 +400,11 @@ The content of the JSON file: ### Request attribute values from the server -In order to request client-side or shared device attributes to ThingsBoard server node, send GET request to the following URL: +Client-side and shared device attributes can be requested from ThingsBoard server node using HTTP GET request. + +##### Request specific client and shared attributes from the server + +In order to request client-side or shared device attributes from ThingsBoard server node, send GET request to the following URL: {% if docsPrefix == null or docsPrefix == "pe/" %} ```shell @@ -482,6 +486,344 @@ However, it is still possible to have same keys for client, shared or even serve {% endcapture %} {% include templates/info-banner.md content=difference %} +{% if docsPrefix != "edge/" %} +##### Request specific client attributes from the server +In order to request client-side device attributes from ThingsBoard server node, send GET request to the following URL: + +{% if docsPrefix == "pe/" %} +```shell +http(s)://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/client?keys=attribute1,attribute2 +``` +{: .copy-code} + +Where +- **$THINGSBOARD_HOST_NAME** - the hostname or IP address your platform is running on; +- **$ACCESS_TOKEN** - device access token. +{% endif %} +{% if docsPrefix == null %} +If you use live demo server, the command will look like this: + +```shell +https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes/client?keys=attribute1,attribute2 +``` +{: .copy-code} + +{% endif %} +{% if docsPrefix contains "paas/" %} + +```shell +{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes/client?keys=attribute1,attribute2 +``` +{: .copy-code} + +Where **$ACCESS_TOKEN** - device access token. +{% endif %} + +{% if docsPrefix == null %} +Execute the command. Don't forget to replace demo.thingsboard.io with your host and $ACCESS_TOKEN with your device's access token. In this example, the hostname references live demo server. +{% endif %} +{% if docsPrefix == "pe/" %} +Execute the command. Don't forget to replace $THINGSBOARD_HOST_NAME with your host and port and $ACCESS_TOKEN with your device's access token +{% endif %} +{% if docsPrefix contains "paas/" %} +Execute the command. Don't forget to replace $ACCESS_TOKEN with your device's access token +{% endif %} + +{% if docsPrefix == null %} +```shell +curl -v -X GET "https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes/client?keys=attribute1,attribute2" +``` +{: .copy-code} +{% endif %} +{% if docsPrefix == "pe/" %} +```shell +curl -v -X GET http://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/client?keys=attribute1,attribute2 +``` +{: .copy-code} +{% endif %} +{% if docsPrefix contains "paas/" %} +```shell +curl -v -X GET "{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes/client?keys=attribute1,attribute2" +``` +{: .copy-code} +{% endif %} + +Result: +```shell +{"client":{"attribute1":"value1","attribute2":true}} +``` + +##### Request specific shared attributes from the server +In order to request shared device attributes from ThingsBoard server node, send GET request to the following URL: + +{% if docsPrefix == "pe/" %} +```shell +http(s)://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/shared?keys=shared1,shared2 +``` +{: .copy-code} + +Where +- **$THINGSBOARD_HOST_NAME** - the hostname or IP address your platform is running on; +- **$ACCESS_TOKEN** - device access token. +{% endif %} +{% if docsPrefix == null %} +If you use live demo server, the command will look like this: + +```shell +https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes/shared?keys=shared1,shared2 +``` +{: .copy-code} + +{% endif %} +{% if docsPrefix contains "paas/" %} + +```shell +{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes/shared?keys=shared1,shared2 +``` +{: .copy-code} + +Where **$ACCESS_TOKEN** - device access token. +{% endif %} + +{% if docsPrefix == null %} +Execute the command. Don't forget to replace demo.thingsboard.io with your host and $ACCESS_TOKEN with your device's access token. In this example, the hostname references live demo server. +{% endif %} +{% if docsPrefix == "pe/" %} +Execute the command. Don't forget to replace $THINGSBOARD_HOST_NAME with your host and port and $ACCESS_TOKEN with your device's access token +{% endif %} +{% if docsPrefix contains "paas/" %} +Execute the command. Don't forget to replace $ACCESS_TOKEN with your device's access token +{% endif %} + +{% if docsPrefix == null %} +```shell +curl -v -X GET "https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes/shared?keys=shared1,shared2" +``` +{: .copy-code} +{% endif %} +{% if docsPrefix == "pe/" %} +```shell +curl -v -X GET http://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/shared?keys=shared1,shared2 +``` +{: .copy-code} +{% endif %} +{% if docsPrefix contains "paas/" %} +```shell +curl -v -X GET "{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes/shared?keys=shared1,shared2" +``` +{: .copy-code} +{% endif %} + +Result: +```shell +{"shared":{"shared1":"value1","shared2":true}} +``` + +##### Request all client and shared attributes from the server + +In order to request all attributes, you can send request to one of the following urls: +{% if docsPrefix == "pe/" %} + +```shell +http(s)://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes +``` +{: .copy-code} + +Where +- **$THINGSBOARD_HOST_NAME** - the hostname or IP address your platform is running on; +- **$ACCESS_TOKEN** - device access token. +{% endif %} +{% if docsPrefix == null %} +If you use live demo server, the command will look like this: + +```shell +https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes +``` +{: .copy-code} + +{% endif %} +{% if docsPrefix contains "paas/" %} + +```shell +{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes +``` +{: .copy-code} + +Where **$ACCESS_TOKEN** - device access token. +{% endif %} +{% if docsPrefix == null %} +Execute the command. Don't forget to replace demo.thingsboard.io with your host and $ACCESS_TOKEN with your device's access token. In this example, the hostname references live demo server. +{% endif %} +{% if docsPrefix == "pe/" %} +Execute the command. Don't forget to replace $THINGSBOARD_HOST_NAME with your host and port and $ACCESS_TOKEN with your device's access token. +{% endif %} +{% if docsPrefix contains "paas/" %} +Execute the command. Don't forget to replace $ACCESS_TOKEN with your device's access token. +{% endif %} +{% if docsPrefix == null %} +```shell +curl -v -X GET "https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes" +``` +{: .copy-code} +{% endif %} +{% if docsPrefix == "pe/" %} +```shell +curl -v -X GET http://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes +``` +{: .copy-code} +{% endif %} +{% if docsPrefix contains "paas/" %} +```shell +curl -v -X GET "{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes" +``` +{: .copy-code} +{% endif %} +{% if docsPrefix == "edge/" %} +```shell +curl -v -X GET "http://$THINGSBOARD_EDGE_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes" +``` +{: .copy-code} +{% endif %} + +Result: +```shell +{"client":{"attribute1":"value1","attribute2":true},"shared":{"shared1":"value1"}} +``` + +##### Request all client attributes from the server +In order to request all client-side device attributes from ThingsBoard server node, send GET request to the following URL: + +{% if docsPrefix == "pe/" %} +```shell +http(s)://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/client +``` +{: .copy-code} + +Where + - **$THINGSBOARD_HOST_NAME** - the hostname or IP address your platform is running on; + - **$ACCESS_TOKEN** - device access token. +{% endif %} +{% if docsPrefix == null %} +If you use live demo server, the command will look like this: + +```shell +https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes/client +``` +{: .copy-code} + +{% endif %} +{% if docsPrefix contains "paas/" %} + +```shell +{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes/client +``` +{: .copy-code} + +Where **$ACCESS_TOKEN** - device access token. +{% endif %} + +{% if docsPrefix == null %} +Execute the command. Don't forget to replace demo.thingsboard.io with your host and $ACCESS_TOKEN with your device's access token. In this example, the hostname references live demo server. +{% endif %} +{% if docsPrefix == "pe/" %} +Execute the command. Don't forget to replace $THINGSBOARD_HOST_NAME with your host and port and $ACCESS_TOKEN with your device's access token +{% endif %} +{% if docsPrefix contains "paas/" %} +Execute the command. Don't forget to replace $ACCESS_TOKEN with your device's access token +{% endif %} + +{% if docsPrefix == null %} +```shell +curl -v -X GET "https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes/client" +``` +{: .copy-code} +{% endif %} +{% if docsPrefix == "pe/" %} +```shell +curl -v -X GET http://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/client +``` +{: .copy-code} +{% endif %} +{% if docsPrefix contains "paas/" %} +```shell +curl -v -X GET "{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes/client" +``` +{: .copy-code} +{% endif %} + +Result: +```shell +{"client":{"attribute1":"value1","attribute2":true}} +``` + +##### Request all shared attributes from the server +In order to request all shared device attributes from ThingsBoard server node, send GET request to the following URL: + +{% if docsPrefix == "pe/" %} +```shell +http(s)://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/shared +``` +{: .copy-code} + +Where + - **$THINGSBOARD_HOST_NAME** - the hostname or IP address your platform is running on; + - **$ACCESS_TOKEN** - device access token. +{% endif %} +{% if docsPrefix == null %} +If you use live demo server, the command will look like this: + +```shell +https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes/shared +``` +{: .copy-code} + +{% endif %} +{% if docsPrefix contains "paas/" %} + +```shell +{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes/shared +``` +{: .copy-code} + +Where **$ACCESS_TOKEN** - device access token. +{% endif %} + +{% if docsPrefix == null %} +Execute the command. Don't forget to replace demo.thingsboard.io with your host and $ACCESS_TOKEN with your device's access token. In this example, the hostname references live demo server. +{% endif %} +{% if docsPrefix == "pe/" %} +Execute the command. Don't forget to replace $THINGSBOARD_HOST_NAME with your host and port and $ACCESS_TOKEN with your device's access token +{% endif %} +{% if docsPrefix contains "paas/" %} +Execute the command. Don't forget to replace $ACCESS_TOKEN with your device's access token +{% endif %} + +{% if docsPrefix == null %} +```shell +curl -v -X GET "https://demo.thingsboard.io/api/v1/$ACCESS_TOKEN/attributes/shared" +``` +{: .copy-code} +{% endif %} +{% if docsPrefix == "pe/" %} +```shell +curl -v -X GET http://$THINGSBOARD_HOST_NAME/api/v1/$ACCESS_TOKEN/attributes/shared +``` +{: .copy-code} +{% endif %} +{% if docsPrefix contains "paas/" %} +```shell +curl -v -X GET "{{httpsUrl}}/api/v1/$ACCESS_TOKEN/attributes/shared" +``` +{: .copy-code} +{% endif %} + +Result: +```shell +{"shared":{"shared1":"value1"}} +``` + +{% endif%} + ### Subscribe to attribute updates from the server In order to subscribe to shared device attribute changes, send GET request with optional "timeout" request parameter to the following URL: diff --git a/_includes/docs/reference/mqtt-api.md b/_includes/docs/reference/mqtt-api.md index f102fd673e..682b2b1db9 100644 --- a/_includes/docs/reference/mqtt-api.md +++ b/_includes/docs/reference/mqtt-api.md @@ -301,6 +301,47 @@ Result: {"client":{"attribute1":"value1","attribute2":true}} ``` +##### Request all client and shared attributes + +In order to request all client attributes and all shared attributes, replace a payload in example below to an object with the "`clientKeys`", "`sharedKeys`" set to an empty string. + +```json +{"clientKeys": "", "sharedKeys": ""} +``` +Result: + +```json +{"client":{"attribute2":true,"attribute1":"value1"},"shared":{"shared1":"value1"}} +``` + +##### Request all client attributes + +In order to request all client attributes, replace a payload in example below to an object with the "`clientKeys`" set to an empty string. + +```json +{"clientKeys": ""} +``` + +Result: + +```json +{"client":{"attribute2":true,"attribute1":"value1"}} +``` + +##### Request all shared attributes +In order to request all shared attributes, replace a payload in example below to an object with the "`sharedKeys`" set to an empty string. + +```json +{"sharedKeys": ""} +``` + +Result: + +```json +{"shared":{"shared1":"value1"}} +``` + + {% capture difference %} **Please note**, the intersection of client-side and shared device attribute keys is a bad practice! However, it is still possible to have same keys for client, shared or even server-side attributes.