You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello, I've found out, that an official Smart Life app shows you deviceId. I've tested that deviceId with tuya OpenAPI and it works (at least for my smart sockets). This means, that you can get localKey from an OpenAPI /v1.0/devices/{{device_id}}.
I think, that this may be useful to simplify tuyapi setup workflow.
The new setup will consist of three steps:
after creating app on iot.tuya.com and getting key/secret, you need to link your devices, but instead of doing that with @tuyapi/cli, you should "Link device by Tuya Smart App Account":
then you can grab id from an app. From the main screen tap on device you interested in, then tap "edit icon" to get to the screen where you can manage/share/rename device. On that screen there is "Device information" menu option, where you can look up for the deviceId:
finally request device info from tuya OpenAPI, where you can get localKey value:
I tried this. I am getting: There was an error in evaluating the Pre-request Script: TypeError: Cannot read property 'sigBytes' of undefined. when trying to make the get request. I also can't tell what I am suppose to use as schema value when making the request.
Set up the variables according to your tuya developer profile client_id, device_id (from the app as described in this post), schema, and url (region based, i.e. https://openapi.tuyaeu.com for EU)
Run the access_token task in collections in postman
Run the {{url}}/v1.0/devices/{{device_id}} request to get your local_key
@SleepWalker so after looking at this a bit, it seems that while linking your TuyaSmart account to your SaaS instance works fine, there's not a programmatic way to get all device IDs. /devices throws an error, and /devices?schema=TuyaSmart gives a permission error. Did you find a good way to list devices?
Ideally, the user would be able to link their account through the web interface and then run one tuya-cli command to list devices; without having to manually find and copy device IDs.
@codetheweb you can use {{url}}/v1.0/users/{{uid}}/devices for that. But, the only way to get uid I know, is by copying deviceId from an app and than get uid field from device info request.
So the user should copy deviceId from any random device, that he had connected to his account. And then it can be used to list all other devices
I've added demo script in gist, that lists all the available devices:
deviceId can be obtained programmatically using the cloudtuya library, by providing it with your account login details (smart_life, tuya smart app) it will list the device ids for all connected devices, which can then be used here.
So close, but so far on this one. Fell at running {url}}/v1.0/devices/{{device_id}} with the error below. The access_token task had run successfully so I have my Postman environment set up correctly. Anybody seen this error?
@tim-jc looks like you've forgot to link your smart life account to your tuya dev account (https://auth.tuya.com/). See the issue description for the screenshots.
@SleepWalker - thank you. I had linked, but when I went back in to my Tuya account I saw my device count was now 0. I think I'd inadvertently run the DEL version of {url}}/v1.0/devices/{{device_id}} initially rather than GET. Re-added the device in the Tuya app and was able to get the key. Appreciate the help.
Please just use the trial! You only need it for getting the local key.
If you running home assistant as as example, you can run then the commands with a addon called local tuya without the cloud!
I run the access_token - all works great - success = true
I then paste {{url}}/v1.0/devices/{{device_id}} into the GET box... run it { "code": 1010, "msg": "token invalid", "success": false, "t": 1614xxxxxxxxx }
What am I doing wrong?
Edit: nevermind. Seems there is a pre-set GET that has that in although i missed it due to all the chinese writing!!
On Tue, Mar 2, 2021 at 4:03 PM vaderag ***@***.***> wrote:
Could someone please assist.
I run the access_token - all works great - success = true
I then paste {{url}}/v1.0/devices/{{device_id}} into the GET box... run it
{ "code": 1010, "msg": "token invalid", "success": false, "t":
1614xxxxxxxxx }
What am I doing wrong?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#323 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOI7KSSREMJMKOPDCGCCFU3TBUD6PANCNFSM4NFCOYFQ>
.
I am having trouble getting the API Explorer to work. I have linked device:
I have tried the different regions as well China gets permission denied:
Europe returns blank response
My devices show in the device list under Europe selection
Anyone have ideas here? I need to create an account on the app under a different locations?
I am having trouble getting the API Explorer to work. I have linked device:
I have tried the different regions as well China gets permission denied:
Europe returns blank response
My devices show in the device list under Europe selection
Anyone have ideas here? I need to create an account on the app under a different locations?
again....
go to api managment
api groups
and grant permissions to the api only DEVICE MANAGMENT wait 10 minutes
and then get device details is that easy
Clearly from my screenshot, device management is enabled and open under the API Groups.
I think it is strange I am getting blank response from Europe region api?
Do you get blank response from any region?
On Thu, Mar 4, 2021 at 1:05 PM matyman1122 ***@***.***> wrote:
Clearly from my screenshot, device management is enabled and open under
the API Groups.
I think it is strange I am getting blank response from Europe region api?
Do you get blank response from any region?
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#323 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AOI7KSVYCAF2VVNTQXB3MXDTB6ATNANCNFSM4NFCOYFQ>
.
Thanks for the reply, this step is already completed as per my last message. You can see in my screenshot all the API groups are available for selection. I suspect I get the deny message because that deviceID is not available on the China API as my devices are under the Europe location. But when I use the Europe one I get {} response. I might need to raise a ticket to them to enquire the status of the API. I was not able to find a status page anywhere.
Just to let everyone know I decided to try and use postman to call the Europe API instead and this is working.
The issue is on the Tuya Cloud not having permissions to the API
For anyone that is trying to use the API Explorer through Tuya IOT Platform and getting the response {} I have found the issue.
This is because the connection is getting blocked due to CORS restrictions. I found this error in the developer console.
Activity
Jaja0624 commentedon May 20, 2020
I tried this. I am getting: There was an error in evaluating the Pre-request Script: TypeError: Cannot read property 'sigBytes' of undefined. when trying to make the get request. I also can't tell what I am suppose to use as schema value when making the request.
codetheweb commentedon May 21, 2020
This could be really useful @SleepWalker, thank you for researching it.
tuya-cli linkstill has issues occasionally for some users, so this could be a great alternative.I'll take a look at some point this weekend.
etttoutoi commentedon May 21, 2020
Hello.
i would try your method, but im noob . It's ok for my virtual id, i have found.
But can you tell me how i have to find local key.
I don't know how i can use tuya openapi.
Can you tell me step by step what i have to write to found please.
thank you
Moudoux commentedon May 23, 2020
@etttoutoi This quick start guide from tuya has all the info you need for using postman to get the local key. Basically:
client_id, device_id (from the app as described in this post), schema, and url (region based, i.e. https://openapi.tuyaeu.com for EU)access_tokentask incollectionsin postman{{url}}/v1.0/devices/{{device_id}}request to get yourlocal_keySleepWalker commentedon May 23, 2020
Here is a gist, that demonstrates how to get
localKeyand then tries to use it with a demo code fromtuyapiREADME:https://gist.github.com/SleepWalker/18f19679adbfacee6c415d4f6dc218bb#file-readme-md
I've successfully turned on/off my socket using
demo.jsfrom that gist 🎉[-]A new way of getting deviceId and localKey (Probably)[/-][+]A new way of getting deviceId and localKey[/+]codetheweb commentedon May 23, 2020
@SleepWalker so after looking at this a bit, it seems that while linking your TuyaSmart account to your SaaS instance works fine, there's not a programmatic way to get all device IDs.
/devicesthrows an error, and/devices?schema=TuyaSmartgives a permission error. Did you find a good way to list devices?Ideally, the user would be able to link their account through the web interface and then run one
tuya-clicommand to list devices; without having to manually find and copy device IDs.SleepWalker commentedon May 23, 2020
@codetheweb you can use
{{url}}/v1.0/users/{{uid}}/devicesfor that. But, the only way to getuidI know, is by copyingdeviceIdfrom an app and than getuidfield from device info request.So the user should copy
deviceIdfrom any random device, that he had connected to his account. And then it can be used to list all other devicesI've added demo script in gist, that lists all the available devices:
https://gist.github.com/SleepWalker/18f19679adbfacee6c415d4f6dc218bb#file-listdevices-js
Moudoux commentedon May 23, 2020
deviceId can be obtained programmatically using the cloudtuya library, by providing it with your account login details (smart_life, tuya smart app) it will list the device ids for all connected devices, which can then be used here.
tim-jc commentedon Jun 13, 2020
So close, but so far on this one. Fell at running

{url}}/v1.0/devices/{{device_id}}with the error below. Theaccess_tokentask had run successfully so I have my Postman environment set up correctly. Anybody seen this error?SleepWalker commentedon Jun 13, 2020
@tim-jc looks like you've forgot to link your smart life account to your tuya dev account (https://auth.tuya.com/). See the issue description for the screenshots.
aidbish commentedon Jun 13, 2020
What do i put for the schema.
i am struggling to get token auth. i get
{
"code": 1000,
"msg": "data not exist",
"success": false,
"t": 1592041129210
}
tim-jc commentedon Jun 13, 2020
@SleepWalker - thank you. I had linked, but when I went back in to my Tuya account I saw my device count was now 0. I think I'd inadvertently run the
DELversion of{url}}/v1.0/devices/{{device_id}}initially rather thanGET. Re-added the device in the Tuya app and was able to get the key. Appreciate the help.31 remaining items
1aranzant commentedon Feb 18, 2021
That's the issue, I get the same screen when trying to link a device.
kinstray commentedon Feb 18, 2021
Yes, I'm getting those ridiculous pricing schemes too. My switch is still working with Octopi. Was it only a 1 month trial of the dev services?
Got another e-mail you can use maybe?
Senbei123 commentedon Feb 19, 2021
Please just use the trial! You only need it for getting the local key.
If you running home assistant as as example, you can run then the commands with a addon called local tuya without the cloud!
vaderag commentedon Mar 2, 2021
Could someone please assist.
I run the access_token - all works great - success = true
I then paste {{url}}/v1.0/devices/{{device_id}} into the GET box... run it
{ "code": 1010, "msg": "token invalid", "success": false, "t": 1614xxxxxxxxx }What am I doing wrong?
Edit: nevermind. Seems there is a pre-set GET that has that in although i missed it due to all the chinese writing!!
DEVAXTATOR commentedon Mar 2, 2021
matyman1122 commentedon Mar 4, 2021
I am having trouble getting the API Explorer to work. I have linked device:




I have tried the different regions as well China gets permission denied:
Europe returns blank response
My devices show in the device list under Europe selection
Anyone have ideas here? I need to create an account on the app under a different locations?
DEVAXTATOR commentedon Mar 4, 2021
again....

go to api managment
api groups
and grant permissions to the api only DEVICE MANAGMENT wait 10 minutes
and then get device details is that easy
matyman1122 commentedon Mar 4, 2021
Clearly from my screenshot, device management is enabled and open under the API Groups.
I think it is strange I am getting blank response from Europe region api?
Do you get blank response from any region?
DEVAXTATOR commentedon Mar 4, 2021
matyman1122 commentedon Mar 4, 2021
thanks for the confirmation, I will try again tomorrow
kinstray commentedon Mar 4, 2021
If you are getting 'Permission Deny' read my post from the 5th Jan 2021...
#323 (comment)
matyman1122 commentedon Mar 4, 2021
Thanks for the reply, this step is already completed as per my last message. You can see in my screenshot all the API groups are available for selection. I suspect I get the deny message because that deviceID is not available on the China API as my devices are under the Europe location. But when I use the Europe one I get {} response. I might need to raise a ticket to them to enquire the status of the API. I was not able to find a status page anywhere.
matyman1122 commentedon Mar 4, 2021
Just to let everyone know I decided to try and use postman to call the Europe API instead and this is working.
The issue is on the Tuya Cloud not having permissions to the API
matyman1122 commentedon Mar 8, 2021
For anyone that is trying to use the API Explorer through Tuya IOT Platform and getting the response {} I have found the issue.

This is because the connection is getting blocked due to CORS restrictions. I found this error in the developer console.
I was able to get the API working again using this extension for Chrome:
https://chrome.google.com/webstore/detail/cross-domain-cors/mjhpgnbimicffchbodmgfnemoghjakai