Install and connect
Configure the OpenPost TypeScript SDK for Hosted or self-hosted OpenPost.
Install
npm install @getopenpost/sdkCreate a developer token in Settings → Personal → Developer. For an unattended service, create a separate token, give it only the scopes it needs, bind it to one workspace when possible, and set an expiry.
Configure the client
import { OpenPost } from "@getopenpost/sdk";
const openpost = new OpenPost({
token: process.env.OPENPOST_TOKEN,
workspaceId: process.env.OPENPOST_WORKSPACE_ID,
});The default origin is https://app.openpo.st. For self-hosting, set baseUrl to the OpenPost origin, without /api/v1:
const openpost = new OpenPost({
baseUrl: "https://social.example.com",
token: process.env.OPENPOST_TOKEN,
workspaceId: process.env.OPENPOST_WORKSPACE_ID,
});You can use environment variables instead of constructor options:
| Variable | Purpose |
|---|---|
OPENPOST_TOKEN | Developer token |
OPENPOST_URL | OpenPost origin |
OPENPOST_INSTANCE | Fallback name for the OpenPost origin |
OPENPOST_WORKSPACE_ID | Default workspace ID |
OPENPOST_WORKSPACE | Fallback workspace value shared with the CLI |
The SDK rejects credentialed plain HTTP by default. For a local self-hosted instance, pass allowInsecureHttp: true only when you control the network.
Test access
const workspaces = await openpost.workspaces.list();
console.log(workspaces.map(({ id, name }) => ({ id, name })));Use an ID from this response as workspaceId. A workspace-bound token cannot access another workspace even if code passes its ID.