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
| Scope | Allows |
|---|---|
channels:read | List connected channels |
posts:read | Read posts, and hear post.* webhook events |
posts:write | Create, change, delete, schedule and publish posts |
media:write | Attach media to posts |
analytics:read | Read publishing and audience analytics |
webhooks:manage | Manage 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.
- Send the user to
https://pub.postia.app/oauth/authorizewithresponse_type=code,client_id,redirect_uri,scope(space separated),stateand a PKCEcode_challengewithcode_challenge_method=S256. - Exchange the code at
POST /oauth/tokenwithgrant_type=authorization_code,code,redirect_uriandcode_verifier. Private apps also send their client secret. - Call the API with the access token (
pst_at_...) as a Bearer token. It lasts one hour. - Refresh with
grant_type=refresh_token. The refresh token (pst_rt_...) is replaced each time you use it. Revoke atPOST /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.