SmartThings Core SDK
The SmartThings Core SDK is a wrapper designed to simplify the use of the SmartThings API when the API is called from JavaScript or TypeScript applications. With the Core SDK, you can easily integrate SmartThings APIs into your JavaScript and TypeScript applications.
The Core SDK is in early development. Changes may be made that are not backwards compatible.
Installation
Find the SmartThings Core SDK source on our GitHub repository.
npm install @smartthings/core-sdk
Authentication
You must authenticate with the SmartThings platform when interacting with SmartThings APIs.
The Core SDK supports multiple ways of authenticating with the SmartThings platform. Available authenticators include:
- BearerTokenAuthenticator - This authenticator is instantiated with any valid bearer token. This is the authenticator to use with a PAT (Personal Access Token).
- RefreshTokenAuthenticator -- This authenticator is instantiated with a bearer token and a RefreshTokenStore that provides methods for retrieving and storing access and refresh tokens. When this authenticator is used, the API will automatically refresh expired access tokens, save the new tokens, and retry the original request.
- SequentialRefreshTokenAuthenticator
For more information on authenticating with the SmartThings platform, visit Authorization and Permissions.
Import the Core SDK Into Your Application
Import the Core SDK into your JavaScript or TypeScript application:
-
NodeJS:
const {SmartThingsClient} = require('@smartthings/core-sdk')
-
ES2015+:
import {SmartThingsClient} from '@smartthings/core-sdk'
Example Usage
The sample below demonstrates importing the Core SDK and retrieving a list of locations for a given user.
Substitute {YOUR-PAT-TOKEN}
with your Personal Access Token (that has a scope of at least r:locations
) in the following code:
const {SmartThingsClient, BearerTokenAuthenticator} = require('@smartthings/core-sdk')
const client = new SmartThingsClient(new BearerTokenAuthenticator('{YOUR-PAT-TOKEN}'))
client.locations.list().then(locations => {
console.log(`Found ${locations.length} locations`)
})
For tutorials and more, visit the SmartThings Community.
Endpoints
For a list of API endpoints, refer to the API documentation. To see these API endpoints utilized in code, visit the Core SDK README "Endpoints" section.