Skip to content
OpenPostDocs
OpenPostDocs

TypeScript SDK

Install the SDK and make your first authenticated request.

Use @getopenpost/sdk for JavaScript or TypeScript services, scripts, and CI jobs. It runs on Node.js 20 or newer, Bun, and Cloudflare Workers. It has no runtime dependencies and uses the platform fetch implementation.

The SDK covers workspaces, accounts, Social Sets, Publications, Renditions, media, Inbox activity, and jobs. Use the HTTP API when another language or an operation outside the SDK is a better fit.

Install

npm install @getopenpost/sdk

Create a developer token in Settings > Personal > Developer. For unattended work, create one token per integration, 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:

VariablePurpose
OPENPOST_TOKENDeveloper token
OPENPOST_URLOpenPost origin
OPENPOST_INSTANCEFallback name for the OpenPost origin
OPENPOST_WORKSPACE_IDDefault workspace ID
OPENPOST_WORKSPACEFallback 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.

New records store creation_source: "sdk". The SDK sends its client identity to distinguish these posts from raw API requests.

Continue

Read Inbox activity

const workspaceId = openpost.workspaceId();
const reviews = await openpost.inbox.list({
  workspace_id: workspaceId,
  kind: "review",
  limit: 50,
});

const receipt = await openpost.inbox.act("REVIEW_ID", {
  workspace_id: workspaceId,
  action: "reply",
  message: "Thanks for your feedback",
  client_operation_id: crypto.randomUUID(),
});
await openpost.jobs.wait(receipt.job_id);
const current = await openpost.inbox.get(workspaceId, "REVIEW_ID");
console.log(current.item.subject?.review?.owner_reply?.state);

Keep the operation ID if admission is interrupted, and reuse it only for the same intent. Review submission and moderation are separate. list and get read saved state; refresh queues collection. setState updates shared read/archive state, and markRead applies its filters across all pages. Follow next_cursor to read older saved activity. See the Inbox guide.

On this page