Javascript / Typescript Seam API Library & CLI
Control locks, lights and other internet of things devices with Seam's simple API!
Check out the generated typescript docs or some examples:
Usage
This package contains both a library and a CLI tool.
CLI Usage
Install with yarn global add seamapi
or npm install -g seamapi
.
Then:
export SEAM_API_KEY=<your api key>
seam workspaces list
Library Usage
Install with yarn add seamapi
or npm install seamapi -s
.
Then:
import Seam from "seamapi";
const seam = new Seam();
const myLock = await seam.locks.get({ name: "My Lock" });
const myLockId = myLock.device_id
await seam.locks.lockDoor(myLockId);
console.log(await seam.locks.list())
await seam.accessCodes.create({
name: "Some Access Code",
code: "1234",
device_id: someLockId,
});
console.log(await seam.accessCodes.list({ device_id: myLockId }))
Receiving Webhooks
Although you don't need to use this package when receiving webhooks, we strongly recommend that you do. Using the included helper class will verify payloads (preventing malicious requests) and return a well-typed event.
SeamWebhook
is a thin wrapper around the Webhook
class from the Svix library.
Example for Express:
import { SeamWebhook } from "seamapi";
import bodyParser from "body-parser";
const secret = "sample-secret";
app.post('/webhook', bodyParser.raw({type: 'application/json'}), (req, res) => {
const payload = req.body;
const headers = req.headers;
const wh = new SeamWebhook(secret);
let msg;
try {
msg = wh.verify(payload, headers);
} catch (err) {
res.status(400).json({});
}
res.json({});
});
For examples using other frameworks, see the Svix docs.