A TuyaCloud object.
Providing apiEtVersion
option means that the new sign mechanism (HMAC-SHA256)
instead of old (MD5) will be used. This also makes secret2
and certSign
mandatory.
(Object)
construction options
Name | Description |
---|---|
options.key String
|
API key |
options.secret String
|
API secret |
options.apiEtVersion String?
|
Tag existing in new mobile api version (as const '0.0.1'), |
options.secret2 String?
|
Second API secret token, stored in BMP file (mandatory if apiEtVersion is specified) |
options.certSign String?
|
App certificate SHA256 (mandatory if apiEtVersion is specified) |
options.region String
(default 'AZ' )
|
region (AZ=Americas, AY=Asia, EU=Europe) |
options.deviceID String?
|
ID of device calling API (defaults to a random value) |
Using the MD5 signing mechanism:
const api = new Cloud({key: 'your-api-key', secret: 'your-api-secret'})
Using the HMAC-SHA256 signing mechanism:
const api = new Cloud({key: 'your-api-key', secret: 'your-api-secret',
apiEtVersion: '0.0.1', secret2: 'your-apm-secret2',
certSign: 'your-api-cert-sign'})
Sends an API request
(Object)
request options
Name | Description |
---|---|
options.action String
|
API action to invoke (for example, 'tuya.cloud.device.token.create') |
options.data Object
(default {} )
|
data to send in the request body |
options.gid String?
|
Group ID URL GET param (necessary for device-related actions) |
options.requiresSID Boolean
(default true )
|
set to false if the request doesn't require a session ID |
Promise<Object>
:
A Promise that contains the response body parsed as JSON
// generate a new token
api.request({action: 'tuya.m.device.token.create',
data: {'timeZone': '-05:00'}}).then(token => console.log(token))
Helper to wait for device(s) to be registered. It's possible to register multiple devices at once, so this returns an array.
Promise<Array>
:
A Promise that contains an array of registered devices
api.waitForToken({token: token.token}).then(result => {
let device = result[0];
console.log('Params:');
console.log(JSON.stringify({id: device['id'], localKey: device['localKey']}));
});