@outposted/node
v2.2.1
Published
Outposted Node.js client — publish to Instagram, Facebook, YouTube, LinkedIn, Threads, TikTok from one API call.
Maintainers
Readme
@outposted/node
Outposted Node.js client. Publish content to Instagram, Facebook, YouTube, LinkedIn, Threads from a single API call. Resilient HMAC-SHA256 signed webhooks with built-in verification.
Installation
pnpm add @outposted/node
# or
npm install @outposted/node
# or
yarn add @outposted/nodeRequires Node.js >= 18 (uses native fetch and node:crypto).
Quick start
import { Outposted } from '@outposted/node';
const client = new Outposted({ apiKey: process.env.OUTPOSTED_API_KEY! });
// Publish an Instagram image post
const result = await client.contents.create('ws_123', {
brand_id: 'brand_abc',
content_type: 'post',
target_platforms: ['instagram'],
content: {
caption: 'Hello from the SDK',
media: [{ type: 'image', url: 'https://cdn.example.com/cover.jpg' }],
},
});
if (result.status !== 'awaiting_media') {
console.log(`queued ${result.jobs.length} job(s)`);
}The client validates the opst_ prefix at construction. Resources are instantiated lazily — first property access builds the resource class, subsequent accesses return the cached instance.
Options
new Outposted({
apiKey: 'opst_live_...', // required, must start with opst_
baseUrl: 'https://api.outposted.one', // optional override
fetch: customFetch, // optional fetch polyfill / interceptor
});The transport layer retries transient failures (5xx + network errors) up to 3 attempts with exponential backoff (250ms, 500ms, 1000ms). 4xx errors are never retried — they surface as typed errors immediately.
Resources
workspaces
The "who am I?" probe for the authenticated API key.
const workspace = await client.workspaces.me();
console.log(workspace.id, workspace.slug);brands
A brand is a publishing identity inside a workspace. One brand can connect multiple platforms (e.g. 1 IG handle + 1 FB Page + 1 Threads).
const brands = await client.brands.list('ws_123');
const brand = await client.brands.get('ws_123', 'brand_abc');
const fresh = await client.brands.create('ws_123', {
name: 'Coke',
slug: 'coke',
brand_type: 'product',
});contents
The core publishing surface. Create, list, fetch, cancel, and retry contents.
// Create + dispatch
await client.contents.create('ws_123', {
brand_id: 'brand_abc',
content_type: 'post',
target_platforms: ['instagram'],
content: { caption: '…', media: [{ type: 'image', url: '…' }] },
});
// Multi-connection disambiguation (brand has ≥2 LinkedIn connections)
await client.contents.create('ws_123', {
brand_id: 'brand_abc',
content_type: 'post',
target_platforms: ['linkedin'],
target_connections: ['conn_personal', 'conn_company'],
content: { text: 'Cross-posted to both surfaces' },
});
const { items, total } = await client.contents.list('ws_123', { status: 'published', limit: 20 });
const detail = await client.contents.get('ws_123', 'cnt_abc');
await client.contents.cancel('ws_123', 'cnt_abc');
await client.contents.retry('ws_123', 'cnt_abc');connections
Build OAuth start URLs that the end user is redirected to in order to authorize a platform connection. The callback handler inside Outposted creates the ConnectedAccount row automatically.
const url = client.connections.getOAuthStartUrl('ws_123', 'brand_abc', 'instagram', {
returnTo: 'https://app.example.com/settings/connections',
});
res.redirect(url);list(workspaceId, brandId) exists but throws today — the V0 API does not yet expose a list endpoint for connected accounts. Use client.brands.get(...) and inspect brand.connected_accounts in the meantime.
webhooks
Register, list, update, delete webhook endpoints. Capture result.secret immediately on create — the plaintext is shown only once.
const endpoint = await client.webhooks.create('ws_123', {
url: 'https://api.example.com/outposted-webhook',
enabled_events: ['content.published', 'content.failed'],
});
await secretManager.store('OUTPOSTED_WHSEC', endpoint.secret); // whsec_..., shown ONCE
const endpoints = await client.webhooks.list('ws_123');
await client.webhooks.update('ws_123', endpoint.id, { active: false });
await client.webhooks.delete('ws_123', endpoint.id);webhooks.verify(rawBody, header, secret) is the inbound verifier — see the dedicated section below.
deliveries
Inspect webhook delivery history and manually retry stuck deliveries.
const page = await client.deliveries.list('ws_123', 'wh_456', {
status: 'failed',
since: '2026-06-01T00:00:00.000Z',
limit: 50,
});
for (const delivery of page.items) {
console.log(delivery.id, delivery.last_response_status);
}
await client.deliveries.redeliver('ws_123', 'del_789');oauth
Pure URL builders — no HTTP I/O. The customer redirects the end user's browser to the returned URL; the platform handshake completes server-side and persists the ConnectedAccount.
const ig = client.oauth.startInstagram({ brandId: 'brand_abc' });
const fb = client.oauth.startFacebook({
brandId: 'brand_abc',
returnTo: 'https://app.example.com/connected',
});
const yt = client.oauth.startYouTube({ brandId: 'brand_abc' });
const th = client.oauth.startThreads({ brandId: 'brand_abc' });
const li = client.oauth.startLinkedIn({ brandId: 'brand_abc', accountType: 'page' });
res.redirect(ig);apiKeys
List API key metadata and rotate (create + optionally revoke others). The plaintext key is returned exactly once on rotate().
const keys = await client.apiKeys.list('ws_123');
// Full rotation hygiene: create a fresh key + revoke every other active key atomically
const result = await client.apiKeys.rotate('ws_123', {
name: 'post-leak',
revoke_others: true,
});
await secretStore.put('OUTPOSTED_API_KEY', result.api_key); // plaintext, shown ONCEWebhook verification
The SDK ships webhooks.verify() so consumers don't need a second package. It's byte-identical to the signing path used by the API + worker.
rawBody MUST be the exact bytes of the request body — any reformatting (key re-ordering, whitespace normalization) breaks the HMAC. Capture the raw stream BEFORE any JSON parser touches it.
import express from 'express';
import { Outposted } from '@outposted/node';
const client = new Outposted({ apiKey: process.env.OUTPOSTED_API_KEY! });
const secret = process.env.OUTPOSTED_WHSEC!; // saved from webhooks.create()
const app = express();
app.post('/outposted-webhook', express.raw({ type: 'application/json' }), (req, res) => {
const rawBody = req.body.toString('utf8');
const sig = req.header('x-outposted-signature');
const result = client.webhooks.verify(rawBody, sig, secret);
if (!result.ok) {
const status =
result.code === 'signature_mismatch'
? 401
: result.code === 'timestamp_out_of_tolerance'
? 408
: 400;
return res.status(status).json({ error: result.code, detail: result.detail });
}
const event = JSON.parse(rawBody);
// … react to event.type, event.data …
res.status(200).end();
});verify() returns a discriminated union:
type VerifyResult =
| { ok: true; timestamp: number }
| { ok: false; code: 'missing'; detail: string }
| { ok: false; code: 'malformed'; detail: string }
| { ok: false; code: 'unsupported_version'; detail: string }
| { ok: false; code: 'timestamp_out_of_tolerance'; detail: string }
| { ok: false; code: 'signature_mismatch'; detail: string };| code | HTTP suggestion |
| ---------------------------- | --------------- |
| ok: true | 200 OK |
| missing / malformed | 400 |
| unsupported_version | 400 |
| timestamp_out_of_tolerance | 408 |
| signature_mismatch | 401 |
Default replay tolerance is 300s (Stripe-compatible). Override with client.webhooks.verify(body, sig, secret, { toleranceSeconds: 600 }).
Errors
Every HTTP error surfaces as a typed OutpostedError subclass. Branch with instanceof.
| Class | Fires on |
| -------------------------- | --------------------------------------------------------------- |
| OutpostedAuthError | 401 — API key missing, invalid, or revoked. |
| OutpostedForbiddenError | 403 — key is valid but lacks permission for the resource. |
| OutpostedNotFoundError | 404 — resource does not exist or belongs to another tenant. |
| OutpostedConflictError | 409 — slug clash, idempotency replay, cancel_too_late, etc. |
| OutpostedValidationError | 400 / 422 — payload shape invalid; carries issues[]. |
| OutpostedRateLimitError | 429 — carries retryAfter (seconds) parsed from Retry-After. |
| OutpostedServerError | 5xx — automatically retried 2× before surfacing. |
| OutpostedNetworkError | DNS failure, connection refused, abort, timeout — no response. |
| OutpostedError | Base class — catches any of the above. |
import {
Outposted,
OutpostedAuthError,
OutpostedRateLimitError,
OutpostedValidationError,
} from '@outposted/node';
try {
await client.contents.create('ws_123', input);
} catch (err) {
if (err instanceof OutpostedAuthError) {
// rotate the key
} else if (err instanceof OutpostedRateLimitError) {
console.log(`rate limited — retry in ${err.retryAfter}s`);
} else if (err instanceof OutpostedValidationError) {
for (const issue of err.issues) {
console.error(issue.path, issue.message);
}
} else {
throw err;
}
}Every error carries status, code, requestId (X-Outposted-Request-ID, for support correlation), body, and headers.
License
MIT
Reference
Full API docs: https://docs.outposted.one
