Get all devices as list

Developer Platform features usage and feedback.


Post Reply
DennyWolf
Posts: 1

Hello everyone. Im new.
Im developing with python3 and I like to retrieve all my devices to store all the ids to perform, after, some operation.
The documentation says that the endpoint is GET /v1.0/devices but the result message is "param is empty".
What's the mistake?

Im using tuya_connector (https://pypi.org/project/tuya-connector-python/).
The code is

from tuya_connector import (
    TuyaOpenAPI
)

from env import ENDPOINT, ACCESS_ID, ACCESS_KEY

# Init OpenAPI and connect
openapi = TuyaOpenAPI(ENDPOINT, ACCESS_ID, ACCESS_KEY)
openapi.connect()

print(dir(openapi.token_info))

# Call any API from Tuya
response = openapi.get(f"/v1.0/devices")

print(response)
JamesG
Posts: 47

Re: Get all devices as list

superstef1005
Posts: 4

Re: Get all devices as list

I have the same problem in Java...

Code: Select all

final BaseResponse<TokenResult> accessToken = tokenApi.getAccessToken(1);
HttpClientUtils.setTokenResult(accessToken.getResult());
final BaseResponse<PageResult<ProjectListItem>> response = projectApi.page(1, 10, null);
    PageResult<ProjectListItem> result = response.getResult();
    List<ProjectListItem> list = result.getList();
    List<ProjectListItem> records = result.getRecords();

I expected one device, but list and records are empty...

panda-cat
Posts: 23

Re: Get all devices as list

Hi, please post the request parameters without a key and the detailed return result information for easy analysis. :) :)

panda-cat
Posts: 23

Re: Get all devices as list

After checking the request code you provided, I found that a required parameter is missing. Supports obtaining the device list and corresponding device status information through the application (schema), product (product_id) or device ID (device_ids) dimensions. Please select the required parameters in one of the dimensions to query.

superstef1005
Posts: 4

Re: Get all devices as list

org.apache.http.wire.wire 73 : http-outgoing-0 >> "GET /v1.0/illumination/devices HTTP/1.1[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "Accept: application/json[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "sign_method: HMAC-SHA256[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "t: 1704190355706[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "client_id: ***********************[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "Signature-Headers: [\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "access_token: 5cc03b47f5286022809d3972464db52d[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "sign: A01E256FF21956DAC4F22D90FF4D2E134FC5BD42610D76F7CE0675B0516E3A33[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "Content-Length: 78[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "Content-Type: text/plain; charset=UTF-8[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "Content-Encoding: UTF-8[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "Host: openapi.tuyaeu.com[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "Connection: Keep-Alive[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.14 (Java/17.0.4.1)[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "Accept-Encoding: gzip,deflate[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 >> "[\r][\n]"
org.apache.http.wire.wire 87 : http-outgoing-0 >> "{"deviceStatus":["
**************"],"projectId":"***************"}"
org.apache.http.wire.wire 73 : http-outgoing-0 << "HTTP/1.1 200 OK[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Content-Type: application/json;charset=UTF-8[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Content-Length: 106[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Connection: keep-alive[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Date: Tue, 02 Jan 2024 10:12:34 GMT[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Credentials: true[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Headers: [\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Headers: access_token,Content-Type[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Methods: POST[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Methods: OPTIONS[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Methods: GET[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Methods: DELETE[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Methods: PUT[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Access-Control-Allow-Origin: https://iot.tuya.com[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Gateway-Info: highway[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Server: Sec[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "Strict-Transport-Security: max-age=31536000[\r][\n]"
org.apache.http.wire.wire 73 : http-outgoing-0 << "[\r][\n]"
org.apache.http.wire.wire 87 : http-outgoing-0 << "{"result":{"list":[],"total":0},"success":true,"t":1704190354503,"tid":"721ffb16a95711eebed8228175f5e2c1"}"
....
o.a.http.impl.execchain.MainClientExec.execute 285 : Connection can be kept alive indefinitely
o.a.h.i.c.PoolingHttpClientConnectionManager.releaseConnection 344 : Connection [id: 0][route: {s}->https://openapi.tuyaeu.com:443] can be kept alive indefinitely
o.a.h.i.c.DefaultManagedHttpClientConnection.setSocketTimeout 88 : http-outgoing-0: set socket timeout to 0
o.a.h.i.c.PoolingHttpClientConnectionManager.releaseConnection 351 : Connection released: [id: 0][route: {s}->https://openapi.tuyaeu.com:443][total available: 1; route allocated: 1 of 32; total allocated: 1 of 64]
o.a.http.impl.execchain.MainClientExec.cancel 145 : Cancelling request execution

Post Reply