@tuyapi/openapi
TypeScript icon, indicating that this package has built-in type declarations

1.3.0 • Public • Published

A TypeScript wrapper for Tuya's OpenAPI

XO code style Build Status

Why?

There is another package called @tuyapi/cloud. Why does this one exist?

The other package deals with Tuya's 'mobile' API, which has limited usefulness as Tuya seems to be phasing it out.

This package instead uses their 'OpenAPI', the solution that they recommend third-party applications use.

Installation

npm i @tuyapi/openapi

Example Usage

(The schema value is your unique app ID from the Tuya console.)

const OpenAPI = require('@tuyapi/openapi');

const api = new OpenAPI({key: '10101010', secret: '1010101010', schema: '10101010'});

(async () => {
  // Must be called before any other operations to get auth token
  await api.getToken();

  const uid = await api.putUser({
    countryCode: '1',
    username: 'your-username',
    password: 'your-password',
    usernameType: 1});

  console.log(uid);

  const token = await api.getDeviceToken({uid, timezone: 'America/Chicago'});

  console.log(token);

  console.log(await api.getDevicesByToken('EkjQjlbo'));
})();

Docs

/@tuyapi/openapi/

    Package Sidebar

    Install

    npm i @tuyapi/openapi

    Weekly Downloads

    23

    Version

    1.3.0

    License

    MIT

    Unpacked Size

    15 kB

    Total Files

    9

    Last publish

    Collaborators

    • apollon77
    • codetheweb
    • tuyapi-ci