90 |
91 |
92 |
93 |
94 |
95 | TuyaCloud
96 |
97 |
98 |
99 |
100 |
101 |
102 | A TuyaCloud object.
103 | Providing apiEtVersion
option means that the new sign mechanism (HMAC-SHA256)
104 | instead of old (MD5) will be used. This also makes secret2
and certSign
mandatory.
105 |
106 | new TuyaCloud(options:
Object)
107 |
108 |
109 |
110 |
111 |
112 |
113 |
114 |
115 |
116 |
117 |
118 | Parameters
119 |
120 |
121 |
122 |
123 |
options (Object)
124 | construction options
125 |
126 |
127 |
128 |
129 |
130 |
131 |
132 |
133 |
134 |
135 | Name |
136 | Description |
137 |
138 |
139 |
140 |
141 |
142 | options.key String
143 | |
144 | API key
145 | |
146 |
147 |
148 |
149 |
150 |
151 | options.secret String
152 | |
153 | API secret
154 | |
155 |
156 |
157 |
158 |
159 |
160 | options.apiEtVersion String?
161 | |
162 | Tag existing in new mobile api version (as const '0.0.1'),
163 | |
164 |
165 |
166 |
167 |
168 |
169 | options.secret2 String?
170 | |
171 | Second API secret token, stored in BMP file (mandatory if apiEtVersion is specified)
172 | |
173 |
174 |
175 |
176 |
177 |
178 | options.certSign String?
179 | |
180 | App certificate SHA256 (mandatory if apiEtVersion is specified)
181 | |
182 |
183 |
184 |
185 |
186 |
187 | options.region String
188 |
189 | (default 'AZ' )
190 | |
191 | region (AZ=Americas, AY=Asia, EU=Europe)
192 | |
193 |
194 |
195 |
196 |
197 |
198 | options.deviceID String?
199 | |
200 | ID of device calling API (defaults to a random value)
201 | |
202 |
203 |
204 |
205 |
206 |
207 |
208 |
209 |
210 |
211 |
212 |
213 |
214 |
215 |
216 |
217 |
218 |
219 |
220 |
221 | Example
222 |
223 | Using the MD5 signing mechanism:
224 |
225 | const api = new Cloud({key: 'your-api-key', secret: 'your-api-secret'})
226 |
227 | Using the HMAC-SHA256 signing mechanism:
228 |
229 | const api = new Cloud({key: 'your-api-key', secret: 'your-api-secret',
230 | apiEtVersion: '0.0.1', secret2: 'your-apm-secret2',
231 | certSign: 'your-api-cert-sign'})
232 |
233 |
234 |
235 |
236 |
237 |
238 | Instance Members
239 |
240 |
241 |
242 |
243 |
244 |
▸
245 |
request(options)
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 | Sends an API request
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 | Parameters
268 |
269 |
270 |
271 |
272 |
options (Object)
273 | request options
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 |
283 |
284 | Name |
285 | Description |
286 |
287 |
288 |
289 |
290 |
291 | options.action String
292 | |
293 | API action to invoke (for example, 'tuya.cloud.device.token.create')
294 | |
295 |
296 |
297 |
298 |
299 |
300 | options.data Object
301 |
302 | (default {} )
303 | |
304 | data to send in the request body
305 | |
306 |
307 |
308 |
309 |
310 |
311 | options.gid String?
312 | |
313 | Group ID URL GET param (necessary for device-related actions)
314 | |
315 |
316 |
317 |
318 |
319 |
320 | options.requiresSID Boolean
321 |
322 | (default true )
323 | |
324 | set to false if the request doesn't require a session ID
325 | |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 |
337 |
338 |
339 |
340 |
341 |
342 | Returns
343 | Promise<Object>
:
344 | A Promise that contains the response body parsed as JSON
345 |
346 |
347 |
348 |
349 |
350 |
351 |
352 |
353 | Example
354 |
355 |
356 |
357 | api.request({action: 'tuya.m.device.token.create',
358 | data: {'timeZone': '-05:00'}}).then(token => console.log(token))
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 |
370 |
371 |
372 |
373 |
374 |
375 |
376 |
377 |
▸
378 |
register(options)
379 |
380 |
381 |
382 |
383 |
384 |
385 |
386 | Helper to register a new user. If user already exists, it instead attempts to log in.
387 |
388 |
389 |
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 | Parameters
401 |
402 |
403 |
404 |
405 |
options (Object)
406 | register options
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 | Name |
418 | Description |
419 |
420 |
421 |
422 |
423 |
424 | options.email String
425 | |
426 | email to register
427 | |
428 |
429 |
430 |
431 |
432 |
433 | options.password String
434 | |
435 | password for new user
436 | |
437 |
438 |
439 |
440 |
441 |
442 |
443 |
444 |
445 |
446 |
447 |
448 |
449 |
450 |
451 |
452 |
453 | Returns
454 | Promise<String>
:
455 | A Promise that contains the session ID
456 |
457 |
458 |
459 |
460 |
461 |
462 |
463 |
464 | Example
465 |
466 |
467 | api.register({email: 'example@example.com',
468 | password: 'example-password'})
469 | .then(sid => console.log('Session ID: ', sid))
470 |
471 |
472 |
473 |
474 |
475 |
476 |
477 |
478 |
479 |
480 |
481 |
482 |
483 |
484 |
485 |
486 |
487 |
488 |
▸
489 |
login(options)
490 |
491 |
492 |
493 |
494 |
495 |
496 |
497 | Helper to log in a user.
498 |
499 |
500 |
501 |
502 |
503 |
504 |
505 |
506 |
507 |
508 |
509 |
510 |
511 | Parameters
512 |
513 |
514 |
515 |
516 |
options (Object)
517 | register options
518 |
519 |
520 |
521 |
522 |
523 |
524 |
525 |
526 |
527 |
528 | Name |
529 | Description |
530 |
531 |
532 |
533 |
534 |
535 | options.email String
536 | |
537 | user's email
538 | |
539 |
540 |
541 |
542 |
543 |
544 | options.password String
545 | |
546 | user's password
547 | |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 |
558 |
559 |
560 |
561 |
562 |
563 |
564 | Returns
565 | Promise<String>
:
566 | A Promise that contains the session ID
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 | Example
576 |
577 |
578 | api.login({email: 'example@example.com',
579 | password: 'example-password'}).then(sid => console.log('Session ID: ', sid))
580 |
581 |
582 |
583 |
584 |
585 |
586 |
587 |
588 |
589 |
590 |
591 |
592 |
593 |
594 |
595 |
596 |
597 |
598 |
▸
599 |
loginEx(options)
600 |
601 |
602 |
603 |
604 |
605 |
606 |
607 | Helper to log in a user using enhanced login process (using empheral asymmetric RSA key)
608 |
609 |
610 |
611 |
612 |
613 |
614 |
615 |
616 |
617 |
618 |
619 |
620 |
621 | Parameters
622 |
623 |
624 |
625 |
626 |
options (Object)
627 | register options
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 | Name |
639 | Description |
640 |
641 |
642 |
643 |
644 |
645 | options.email String
646 | |
647 | user's email
648 | |
649 |
650 |
651 |
652 |
653 |
654 | options.password String
655 | |
656 | user's password
657 | |
658 |
659 |
660 |
661 |
662 |
663 |
664 |
665 |
666 |
667 |
668 |
669 |
670 |
671 |
672 |
673 |
674 | Returns
675 | Promise<String>
:
676 | A Promise that contains the session ID
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 | Example
686 |
687 |
688 | api.loginEx({email: 'example@example.com',
689 | password: 'example-password'}).then(sid => console.log('Session ID: ', sid))
690 |
691 |
692 |
693 |
694 |
695 |
696 |
697 |
698 |
699 |
700 |
701 |
702 |
703 |
704 |
705 |
706 |
707 |
708 |
▸
709 |
waitForToken(options)
710 |
711 |
712 |
713 |
714 |
715 |
716 |
717 | Helper to wait for device(s) to be registered.
718 | It's possible to register multiple devices at once,
719 | so this returns an array.
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 | Parameters
734 |
735 |
736 |
737 |
738 |
options (Object)
739 | options
740 |
741 |
742 |
743 |
744 |
745 |
746 |
747 |
748 |
749 |
750 | Name |
751 | Description |
752 |
753 |
754 |
755 |
756 |
757 | options.token String
758 | |
759 | token being registered
760 | |
761 |
762 |
763 |
764 |
765 |
766 | options.devices Number
767 |
768 | (default 1 )
769 | |
770 | number of devices to wait for
771 | |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 | Returns
789 | Promise<Array>
:
790 | A Promise that contains an array of registered devices
791 |
792 |
793 |
794 |
795 |
796 |
797 |
798 |
799 | Example
800 |
801 |
802 | api.waitForToken({token: token.token}).then(result => {
803 | let device = result[0];
804 | console.log('Params:');
805 | console.log(JSON.stringify({id: device['id'], localKey: device['localKey']}));
806 | });
807 |
808 |
809 |
810 |
811 |
812 |
813 |
814 |
815 |
816 |
817 |
818 |
819 |
820 |
821 |
822 |
823 |
824 |
825 |
826 |
827 |
828 |
829 |