Skip to content

Quickstart

From a workspace to a confirmed delivery.

This guide publishes one post to one account in a single call, then reads the confirmed result. Drafts, revisions, and preflight are the advanced path.

Before you start

You need a PubNio workspace, an enabled publishing account, and an API key or access token.

List the workspace and accounts with the API:

curl -s https://pubnio.com/api/v1/workspaces \
  -H "Authorization: Bearer $PUBNIO_TOKEN"

curl -s "https://pubnio.com/api/v1/integrations?workspaceId=$WORKSPACE_ID" \
  -H "Authorization: Bearer $PUBNIO_TOKEN"

Workspace IDs and account IDs are UUIDs. The account response includes the provider and whether the account is available.

Publish in one call

  1. Install the SDK

    TypeScript

    bun add @pubnio/sdk
    # or: npm install @pubnio/sdk

    The package ships ESM and CommonJS builds with TypeScript declarations. Node 20.19 or newer is required for the CommonJS entry.

    Python

    pip install pubnio
    # or: uv add pubnio

    Python 3.11 or newer is required. See the Python SDK for the async client and the full surface.

  2. Prepare media

    TypeScript

    const intake = await workspace.media.importUrl(
      "https://cdn.example.com/launch-reel.mp4",
      { idempotencyKey: "launch-reel" },
    );
    const ready = await workspace.media.wait(intake.mediaId, {
      timeoutMs: 30_000,
    });
    if (ready.status !== "ready") throw new Error("Media is not ready.");

    Python

    intake = workspace.media.import_url(
        "https://cdn.example.com/launch-reel.mp4",
        idempotency_key="launch-reel",
    )
    ready = workspace.media.wait(intake["mediaId"], timeout=30)
    if ready["status"] != "ready":
        raise RuntimeError("Media is not ready.")

    Import, upload, status, and wait return the same { mediaId, status, asset?, issue? } result. For a local file, call workspace.media.upload(file) instead.

  3. Create and submit the post

    TypeScript

    import { createPubNioClient } from "@pubnio/sdk";
    
    const client = createPubNioClient({
      baseUrl: "https://pubnio.com",
      apiKey: process.env.PUBNIO_API_KEY,
    });
    const workspace = client.workspace(workspaceId);
    
    const accepted = await workspace.posts.create({
      text: "CSV exports are live. Download a week of reports in one click.",
      targets: [
        {
          accountId,
          provider: "instagram",
          placement: "reel",
          media: [{ mediaId: ready.mediaId }],
        },
      ],
    });
    console.log(accepted.postId, accepted.targets);

    Python

    import os
    
    from pubnio import PubNio
    
    client = PubNio(
        api_key=os.environ["PUBNIO_API_KEY"],
        base_url="https://pubnio.com",
    )
    workspace = client.workspace(workspace_id)
    
    accepted = workspace.posts.create(
        text="CSV exports are live. Download a week of reports in one click.",
        targets=[
            {
                "accountId": account_id,
                "provider": "instagram",
                "placement": "reel",
                "media": [{"mediaId": ready["mediaId"]}],
            }
        ],
    )
    print(accepted["postId"], accepted["targets"])

    Send platforms or accounts when one default destination per account is enough. Use targets for exact placements, text, media, or schedules.

  4. Read the result

    TypeScript

    const post = await workspace.posts.get(accepted.postId);
    console.log(post.status, post.deliveries);

    Python

    post = workspace.posts.get(accepted["postId"])
    print(post["status"], post["deliveries"])

    posts.get returns the saved content, revision, status, and one delivery per destination. Use posts.wait for a bounded wait on a terminal outcome.

The SDK generates an idempotency key for each publish and returns it on the accepted response. Reuse that key when retrying the same publish call; use a new key for a new intent. GET and keyed writes retry twice with backoff, while unsafe writes are never retried.

Read every page

List methods return one cursor page. Use iterate to read all of them without writing a page loop.

for await (const post of workspace.posts.iterate({ isDraft: true })) {
  console.log(post.postId, post.textPreview);
}

Filters stay applied on every page. Pass { signal, maxPages } as the second argument to bound the work.

Save a draft

A draft is a post with isDraft: true. It shares the same ID namespace and route family as a submitted post.

const draft = await workspace.posts.create({
  isDraft: true,
  text: "CSV exports are live.",
  targets: [{ accountId, provider: "instagram", placement: "reel" }],
});

const validation = await workspace.posts.validate(draft.postId);
if (!validation.valid) console.log(validation.errors);

const accepted = await workspace.posts.publish(draft.postId, {
  expectedRevision: draft.revision,
});

posts.update edits a draft with expectedRevision, and posts.delete archives it. Preflight is optional for the one-call path.

Schedule instead of publishing now

await workspace.posts.publish(postId, {
  expectedRevision,
  scheduledAt: "2026-12-02T15:00:00-08:00",
});

scheduledAt is an ISO 8601 timestamp with an explicit offset. The Workflow can reschedule or cancel a target until it reserves the provider write.

Use the CLI

pnio exposes the same operations. In this repository, run it with bun run cli.

pnio auth login
pnio workspaces list
pnio posts create --workspace "$WORKSPACE_ID" \
  --text "CSV exports are live." --platform instagram
pnio posts get --workspace "$WORKSPACE_ID" "$POST_ID"

# Advanced: a reviewed draft
pnio posts create --draft --workspace "$WORKSPACE_ID" --file draft.json
pnio posts validate --workspace "$WORKSPACE_ID" "$POST_ID"
pnio posts publish --workspace "$WORKSPACE_ID" "$POST_ID" \
  --revision 1 --idempotency-key "$(uuidgen)"

draft.json uses the same Post content shape as the API. The publish response is accepted work, not the final provider result; read pnio posts status.

Type to search…

↑↓ navigate↵ selectEsc close