PostraDocsOpen Postra

Node.js SDK

@postra/node is a small Node.js library for the Public API. Since 1.3.0 it has a method for every route on the Endpoints page except the legacy POST /generate-video: channels, posts, slots, media, analytics, notifications and AI video.

Package @postra/node
Current version 1.3.0
Node.js 18 or newer
Dependencies None

Install

npm install @postra/node

Create a client

You need an API key. Copy it from Settings → Developers → Access in Postra. See Developer settings.

Keep the key on your server, for example in an environment variable. Never put it in a web page or a mobile app.

ES modules and TypeScript:

import Postra from '@postra/node';

const postra = new Postra(process.env.POSTRA_API_KEY); // YOUR_API_KEY

CommonJS (require):

const Postra = require('@postra/node').default;

const postra = new Postra(process.env.POSTRA_API_KEY);

The client sends the key in the Authorization header. An OAuth access token (it starts with pos_) works in the same place. See Sign in with Postra.

The second argument is the API address. It defaults to https://app.postra.co.uk/api, so you can leave it out.

Methods

Every method returns a promise with the API’s JSON answer.

Method What it does
integrations() Lists your connected channels
post(body) Creates a draft, a scheduled post or a post that goes out now
postList(filters) Lists posts between two dates
upload(file, extension) Uploads an image or video to your media library
mediaList(filters) Lists your media library
deletePost(id) Deletes a post
deletePostGroup(group) Deletes every post of a group from postList()
setPostStatus(id, status, options) Turns a post into a draft or puts it back in the queue
postMissing(id) Lists the platform’s recent items for a post published without an id
setReleaseId(id, releaseId) Links such a post to its item on the platform
findSlot(channelId) The next free posting time on a channel
uploadFromUrl(url) Postra downloads a file from a public HTTPS address into your media library
isConnected() Checks that your key works
integrationSettings(channelId) What a channel accepts: rules, maxLength, settings schema, tools
triggerIntegration(channelId, methodName, data) Runs one of the channel’s tools
connectChannel(platform, options) The sign-in address that connects a new channel
deleteIntegration(channelId) Removes a channel and all its posts
analytics(channelId, options) Channel analytics
postAnalytics(postId, options) Analytics of one published post
notifications(options) Your organisation’s notifications
startVideo(input) Starts an AI video and answers at once with its id
video(id) Where a started video stands: pending, done or failed
videoFunction(identifier, functionName, params) A helper an engine needs before a video

integrations()

const channels = await postra.integrations();
// [{ id, name, identifier, picture, disabled, profile, customer }, ...]

Use a channel’s id when you create a post.

post(body)

const result = await postra.post({
  type: 'schedule', // 'draft', 'schedule' or 'now'
  date: '2026-11-02T09:30:00.000Z',
  shortLink: false,
  tags: [],
  posts: [
    {
      integration: { id: 'CHANNEL_ID' },
      value: [{ content: 'Hello from Postra', image: [] }],
    },
  ],
});
// [{ postId, integration }]

Some platforms need extra settings in posts[].settings. See Platforms and settings and Endpoints for every field.

postList(filters)

const { posts } = await postra.postList({
  startDate: '2026-11-01T00:00:00.000Z',
  endDate: '2026-11-30T23:59:59.000Z',
});

Dates are ISO 8601. A range longer than 370 days is cut to 370 days. customer is optional: a customer ID, to list only that customer’s channels.

upload(file, extension)

import { readFile } from 'node:fs/promises';

const media = await postra.upload(await readFile('photo.jpg'), 'jpg');
// use media.id and media.path in a post's image list

file is a Buffer. extension is the file type, such as png, jpg, gif, webp or mp4. File types and sizes are on Uploading media.

To add the file to a post:

value: [{ content: 'New in store', image: [{ id: media.id, path: media.path }] }]

mediaList(filters)

const { pages, results } = await postra.mediaList({ page: 1, search: 'logo' });
// results: [{ id, name, originalName, path, createdAt }, ...]

Newest first, 18 items per page. Both filters are optional. search matches the original file name; files uploaded with the SDK’s upload() are named upload.<ext>. Reuse an id and path instead of uploading the same file again.

deletePost(id)

await postra.deletePost('POST_ID');

id is a postId from post() or an id from postList(). This deletes the post on that channel and its follow-up parts, such as thread replies.

The rest of the API (1.2.0)

Each of these calls one route on the Endpoints page and returns its JSON answer unchanged, so that page has the fields and the error codes.

await postra.isConnected();                         // { connected: true }
const settings = await postra.integrationSettings('CHANNEL_ID');
await postra.triggerIntegration('CHANNEL_ID', 'channels', {});
const { url } = await postra.connectChannel('linkedin');
await postra.deleteIntegration('CHANNEL_ID');       // also deletes its posts

const { date } = await postra.findSlot('CHANNEL_ID'); // next free time, UTC
await postra.setPostStatus('POST_ID', 'draft');
await postra.setPostStatus('POST_ID', 'schedule', { republish: true });
await postra.deletePostGroup('GROUP');
const items = await postra.postMissing('POST_ID');
await postra.setReleaseId('POST_ID', items[0].id);

const media = await postra.uploadFromUrl('https://example.com/photo.jpg');
const channelStats = await postra.analytics('CHANNEL_ID', { date: 30 });
const postStats = await postra.postAnalytics('POST_ID', { date: 7 });
const { notifications, hasMore } = await postra.notifications({ page: 0 });

connectChannel takes { refresh: 'CHANNEL_ID' } to renew an existing channel’s sign-in. analytics and postAnalytics take { date }, the number of days to cover (default 7). notifications takes { page }, from 0.

AI video (1.3.0)

A video takes a few minutes, so you start it and then ask where it stands. When it is done it is also in your media library.

const { id } = await postra.startVideo({
  type: 'veo3',
  output: 'vertical',
  customParams: { prompt: 'A barista pours latte art in a small cafe', images: [] },
});

let result = await postra.video(id);
while (result.status === 'pending') {
  await new Promise((resolve) => setTimeout(resolve, 15000));
  result = await postra.video(id);
}
// result.status is 'done' (with result.media) or 'failed' (with result.message)

The fields, the limits and the error codes are in AI video on the Endpoints page.

Errors

When the API answers with anything other than 2xx, the method throws a PostraError.

Property Meaning
status The HTTP status, for example 401
body The API’s answer, parsed from JSON when possible
message For example Postra API responded 401: {"msg":"Invalid API key"}
import { PostraError } from '@postra/node';

try {
  await postra.integrations();
} catch (err) {
  if (err instanceof PostraError) {
    console.log(err.status, err.body);
  } else {
    throw err; // for example, no network
  }
}

With require, use const { PostraError } = require('@postra/node');.

A network failure is not a PostraError. It comes through as the normal fetch error.

Common answers:

Status Body Meaning
401 {"msg":"Invalid API key"} Wrong key, or the key was rotated
401 {"msg":"Invalid OAuth token"} The pos_ token is unknown or no longer valid
401 {"msg":"No subscription found"} The workspace has no active plan
429 Too many requests. Wait and try again.

More on the Endpoints page.