Postia API
EN
Console

Authentication

Use an API key for your own account. Register an OAuth app to publish for other people's accounts.

API keys

Send the key as a Bearer token: Authorization: Bearer pst_live_.... Live keys act on real accounts, test keys (pst_test_...) are a sandbox.

A key has scopes, and a request outside them is a 403. A key can also be limited to IP addresses and given an expiry. When you rotate a key, the old one keeps working for a short while.

Scopes

ScopeAllows
channels:readList connected channels
posts:readRead posts, and hear post.* webhook events
posts:writeCreate, change, delete, schedule and publish posts
media:writeAttach media to posts
analytics:readRead publishing and audience analytics
webhooks:manageManage webhook endpoints

OAuth for apps

Register an app in the console. Users approve the scopes you ask for, and you receive tokens for their account. Metadata is at https://pub.postia.app/.well-known/oauth-authorization-server.

  1. Send the user to https://pub.postia.app/oauth/authorize with response_type=code, client_id, redirect_uri, scope (space separated), state and a PKCE code_challenge with code_challenge_method=S256.
  2. Exchange the code at POST /oauth/token with grant_type=authorization_code, code, redirect_uri and code_verifier. Private apps also send their client secret.
  3. Call the API with the access token (pst_at_...) as a Bearer token. It lasts one hour.
  4. Refresh with grant_type=refresh_token. The refresh token (pst_rt_...) is replaced each time you use it. Revoke at POST /oauth/revoke.
import { createHash, randomBytes } from "node:crypto";

const verifier = randomBytes(32).toString("base64url");
const challenge = createHash("sha256").update(verifier).digest("base64url");

const url = new URL("https://pub.postia.app/oauth/authorize");
url.search = new URLSearchParams({
  response_type: "code",
  client_id: CLIENT_ID,
  redirect_uri: REDIRECT_URI,
  scope: "channels:read posts:write",
  state: randomBytes(16).toString("hex"),
  code_challenge: challenge,
  code_challenge_method: "S256",
});
// Send the user to url, keep verifier with their session.
curl -X POST https://pub.postia.app/oauth/token \
  -d grant_type=authorization_code \
  -d code=CODE_FROM_THE_REDIRECT \
  -d redirect_uri=REDIRECT_URI \
  -d client_id=CLIENT_ID \
  -d code_verifier=VERIFIER

Redirect URIs must match exactly: https, or http on localhost. A public app is reviewed before other people can connect to it; until then only its owner can.