One API between your product and six platforms
SocialPostAPI is a multi-tenant publishing service. Your product decides what to say, when, and where. SocialPostAPI handles everything between "post" and "published", including OAuth tokens, encryption, refresh, media uploads, platform quirks, retries and webhooks.
Your product
Owns the what and the when: captions, schedules, media choices, your UI, your data.
SocialPostAPI
Owns the how: encrypted credentials, automatic refresh, uploads, per-platform formatting, retries, webhooks.
The platforms
X, Instagram, Facebook, TikTok, LinkedIn, and YouTube. We use official APIs only.
One request shape
The same JSON works across the six platforms we currently offer.
Encrypted at rest
OAuth tokens are AES-256 ciphertext in the database, refreshed automatically at publish time.
Self-healing tokens
An expired token is refreshed and the post retried once, in the same attempt.
Queued and retried
A redundant worker publishes with per-platform status, backoff and jitter.
Media per platform
Upload once; each platform receives exactly what it accepts.
Webhooks that tell the truth
post.published and post.publish_failed, signed and retried for you.
This guide walks the full journey: a new API key, a connected account, an
uploaded video, a scheduled post, a refreshed token, a webhook that says it's live.
For the raw endpoint surface, the OpenAPI schema ships with the service
(/api/docs in development builds).
Quickstart: your first post in four steps
Every request below goes to
https://socialpostapi.makketing.com and carries your key as a bearer token.
No SDK is needed. Send regular HTTPS requests with JSON.
Step 1: Get an API key
Each tenant gets its own API key. During the beta, our team issues keys as part of onboarding. You'll see the full key exactly once. Keep it server-side:
$ export SOCIALPOSTAPI_KEY="sap_9fR2tQ8xLm4vNp6wKc3jHs1dYb7uZe5a"
Never put the key in frontend code, git, or client devices. It is a server-to-server credential: anyone holding it can publish as every account in your tenant. If it leaks, contact us to revoke it. Revocation takes effect immediately.
Step 2: Connect an account
Ask us for a login URL for the platform your customer wants to connect. The response includes the login URL and the callback URI to register with the platform. Your app never handles the customer's password.
$ curl "https://socialpostapi.makketing.com/api/connect/twitter/start" \ -H "Authorization: Bearer $SOCIALPOSTAPI_KEY"
{
"authorize_url": "https://twitter.com/i/oauth2/authorize?client_id=...&state=...",
"redirect_uri": "https://socialpostapi.makketing.com/api/connect/twitter/callback"
}
For Instagram, use the Instagram API with Instagram Login app ID and
app secret. In Meta for Developers, add the returned redirect_uri exactly
under Instagram → API setup with Instagram login → Business login settings → OAuth
Redirect URIs. For this deployment it is
https://socialpostapi.makketing.com/api/connect/instagram/callback.
Do not register /connect/result; that is only the browser success page.
$ curl "https://socialpostapi.makketing.com/api/connect/instagram/start" \ -H "Authorization: Bearer $SOCIALPOSTAPI_KEY"
{
"authorize_url": "https://www.instagram.com/oauth/authorize?client_id=...&redirect_uri=...&scope=...&response_type=code&state=...",
"redirect_uri": "https://socialpostapi.makketing.com/api/connect/instagram/callback"
}
After the customer approves, SocialPostAPI exchanges and stores the tokens. You can then see the connected account:
$ curl "https://socialpostapi.makketing.com/api/profiles" \ -H "Authorization: Bearer $SOCIALPOSTAPI_KEY"
[{
"id": "prf_x8Qw2mKd", "name": "@yourbrand",
"platform": "twitter", "status": "active"
}]
Step 3: Upload media
Upload an image or video once; it returns a media id you can attach to any post. Files use the storage backend configured for this service. Your app keeps only the media ID.
$ curl -X POST "https://socialpostapi.makketing.com/api/media" \ -H "Authorization: Bearer $SOCIALPOSTAPI_KEY" \ -F "file=@launch-video.mp4"
{
"id": "med_9f2kQw4n", "status": "ready",
"content_type": "video/mp4", "file_size_bytes": 18204432
}
Step 4: Publish
One call, many platforms. profiles accepts platform names
("twitter") or profile IDs. A platform name resolves to your tenant's
connected account of that platform. Add scheduled_at to the
post object to publish in the future instead of now.
$ curl -X POST "https://socialpostapi.makketing.com/api/posts" \ -H "Authorization: Bearer $SOCIALPOSTAPI_KEY" \ -H "Content-Type: application/json" \ -H "Idempotency-Key: launch-2026-09-28" \ -d '{ "post": { "body": "The biggest launch yet" }, "profiles": ["twitter", "instagram"], "media": ["med_9f2kQw4n"] }'
{
"id": "pst_x9k2Qw8", "status": "processing",
"platforms": [
{ "platform": "twitter", "status": "pending" },
{ "platform": "instagram", "status": "pending" }
]
}
Check GET /api/posts/pst_x9k2Qw8 for each platform's status and
permalink. For updates without polling, subscribe to webhooks.
That's the whole surface for the happy path: one key, one connect, one upload, one publish call. Everything below is the detail behind those four steps.
API keys and tenants
Every account you connect lives in a tenant, which represents one real business or creator managing their own presence. Your key identifies the tenant on every call; there is no tenant ID anywhere in the API surface.
What the service actually stores
Keys start with sap_ and are long random strings. At issue time you see
the plaintext once; the database keeps only a short display prefix and a one-way
SHA-256 lookup hash. The full key is not stored, so a database
leak reveals nothing usable.
Scoping that cannot be forgotten
Your tenant is derived from the key and applied to every query by
the framework, not passed per request. There is no tenant_id field to fill
in, forge, or accidentally leak. One tenant's key can never read, publish or delete
another tenant's posts, profiles or tokens. This is enforced on every route and covered
by cross-tenant regression tests.
White-label platform apps
Each tenant can carry its own OAuth app credentials per platform (client id / secret / redirect URI), so a white-label product can run each customer's brand through that customer's own approved apps. App secrets are encrypted with the same AES-256 key as account tokens. The API masks them and never returns the secrets.
Lifecycle
- Issue: The admin console shows the key once and stores only its hash.
- Store: Keep it encrypted with your other application secrets.
- Revoke: Revocation takes effect immediately. The next request returns 401.
- Reissue: Get a new key without changing connected accounts or posts.
Connecting accounts
Your customer's credentials never touch your servers. You request a login URL, you send the customer's browser to it, and the platform sends them back. SocialPostAPI does the exchange. Walk through it:
1 · Request a login URL
Your backend calls GET /api/connect/{platform}/start with your key.
The response contains authorize_url and the exact effective
redirect_uri. Because the start endpoint
requires your key, the OAuth state is bound to your tenant before the user ever
leaves your site.
2 · The customer consents
You send the customer's browser to authorize_url. They see the
platform's own consent screen, where they can review what your app can do and approve
or decline. Your app does not handle their login details.
3 · The platform redirects back
The platform sends the browser to SocialPostAPI's callback with a one-time code
and the state from step 1. The callback is a browser redirect, not an API call.
Step 1 binds the state to your tenant before the user leaves.
Register the returned redirect_uri exactly in the platform's OAuth settings.
Instagram's production callback is
https://socialpostapi.makketing.com/api/connect/instagram/callback.
4 · Server-to-server token exchange
SocialPostAPI exchanges the code for tokens directly with the platform, using PKCE where the platform supports it. The state is validated: single-use, tenant-bound, stored in the database. Replayed or forged callbacks are rejected.
5 · Encrypt and store
The fresh access and refresh tokens are encrypted (Fernet / AES-256) before they touch the database, alongside their expiry time. The raw tokens never pass through your servers at all.
6 · Success page
The browser lands on a success page showing the connected account, and the
redirect carries the platform and profile IDs. Your app can read the result there or
call GET /api/profiles.
If the customer later revokes your app on the platform, publishing fails
with TOKEN_INVALID. Reconnect the account to restore access.
SocialPostAPI never prompts on your behalf; a reconnect is the same six steps.
Credentials: encryption and refresh
Every connected account stores its tokens as encrypted ciphertext, and expired tokens are refreshed automatically at publish time. Here is exactly what that means.
What lands in the database
Encryption uses Fernet, which combines AES-128-CBC and HMAC.
Its 128-bit encryption key and 128-bit signing key provide 256 bits of key material. It is keyed by
ENCRYPTION_KEY from the server environment. There is no default
key: a deployment without one refuses to boot rather than silently storing
plaintext. Plaintext exists only inside a running worker's memory for the seconds of a
publish call. Tokens never appear in logs or API responses.
Watch a refresh happen
Refresh is reactive: when a publish call comes back
TOKEN_EXPIRED, the worker refreshes on the spot, stores the new tokens,
and retries the post once in the same attempt. Click through the sequence:
We don't refresh idle accounts in the background. Refresh happens
when a publish actually runs. The retry is safe because the first call
definitively failed: it returned TOKEN_EXPIRED, so nothing was posted, and
the retry is the only call that can succeed. No duplicate-post window. If the refresh
itself fails, the post fails with a clear error and the normal retry-with-backoff path
takes over.
Per platform
| Platform | Refresh mechanism | Refresh token |
|---|---|---|
| X | refresh_token grant | New token pair is stored |
| Long-lived token re-exchange | The access token is extended | |
| Page token re-derived from the user token | No refresh token | |
| TikTok | refresh_token grant | New token pair is stored |
| YouTube | Google refresh grant | Google reuses the same refresh token |
refresh_token grant | Only if your app has invite-only access |
LinkedIn, honestly: standard LinkedIn apps never receive a refresh
token, and LinkedIn tokens expire after 60 days with no way to renew them. When that
happens SocialPostAPI fails the publish with an explicit "reconnect this account to get
a new token" message instead of a bare token_expired. This is documented
because the product says so.
The publish lifecycle
A post is one row with one status, plus one platform-post row per target platform. The worker claims due posts, publishes each platform independently, and never leaves a post in a state it can't explain.
Post-level statuses
draft scheduled processing processed failed
- draft: Created with
"draft": true. Publish it later withPOST /api/posts/{id}/publish. - scheduled: Has a future
scheduled_at. A worker publishes it when the time comes. - processing: A worker has claimed it and is publishing or retrying.
- processed: Every platform post has finished. Read
platforms[]for links and statuses. - failed: At least one platform failed permanently. The platform post includes the reason.
Platform-post statuses
pending processing published failed failed_waiting_for_retry pending_deletion deleted
A platform post that fails transiently goes to
failed_waiting_for_retry and is retried with exponential backoff and
jitter (base 60 s). Retries are spaced out and do not run in a tight loop.
Two safety nets against double posts
- Idempotency keys. Send an
Idempotency-Keyheader onPOST /api/posts. If your client times out and retries with the same key, the service replays the original response instead of creating a second post. Keys are stored hashed and scoped per tenant and route. A concurrent duplicate gets a 409 "already in progress" until the first finishes. - Intent records. Before any platform call, the worker commits a
publish_attemptrow (in_flight), updated tosucceededorfailedafterwards. If the worker dies mid-call, the attempt is found stuck and moved toneeds_reconciliation, where a human verifies what the platform actually received. It is never blindly retried, because a crash after the platform accepted the post is exactly how duplicates are born.
Deletes follow the same honesty: DELETE /api/posts/{id} marks the
platform posts pending_deletion and the worker removes them on the platform.
The API waits for confirmation before reporting a successful delete.
Media uploads
Upload files with a multipart POST, up to 500 MB. Files use the storage backend configured for the service. Media rows store object keys, and short-lived URLs are created when a post is published.
Accepted upload types: image/jpeg, image/png,
image/gif, image/webp, video/mp4,
video/quicktime, video/webm. A bad type or size is rejected
up front with a 422.
What each platform accepts
Choose a platform to see its limits. A video your tenant uploads once can go to the platforms that accept it and fail only those that don't, with the reason in the platform post:
X (Twitter)
- Text
- up to 280 characters
- Media
- up to 4 items:
jpeg, png, gif, webp, mp4, mov - Extras
- threads (replies chained under the first post) and polls supported
- Text
- up to 2,200 characters
- Media
- up to 10 items:
jpeg, png, mp4, mov - Extras
- Media is required. Text-only posts return
MEDIA_REQUIRED.
- Text
- up to 63,206 characters
- Media
- up to 10 items:
jpeg, png, gif, webp, mp4, mov
TikTok
- Text
- up to 2,200 characters
- Media
- 1 video:
mp4, mov, webm
- Text
- up to 3,000 characters
- Media
- up to 9 items:
jpeg, png, gif, mp4
YouTube
- Text
- up to 5,000 characters (title + description)
- Media
- 1 video:
mp4, mov, webm, mkv
Errors and retries
Errors include a code and, when available, the platform's message. Here's the response format:
{
"error": "The LinkedIn access token has expired. LinkedIn tokens expire after 60 days…",
"error_code": "TOKEN_EXPIRED",
"details": { "platform": "linkedin" }
}
| HTTP | Meaning |
|---|---|
| 400 | Malformed request (bad JSON, unknown fields) |
| 401 | Missing, malformed or revoked API key |
| 403 | Key is valid but not allowed this action (e.g. touching another tenant's resource) |
| 404 | Unknown post, profile, media or webhook id |
| 409 | An Idempotency-Key for this request is still in flight. Retry shortly. |
| 422 | Validation failed. Check text length, media count and type, and schedule. |
| 429 | Rate limit reached. See the table below. |
| 503 | Storage or database temporarily unavailable |
Platform error codes
Platform failures appear on the platform post with a machine-readable code. useful to your support team and your UI:
TOKEN_EXPIRED TOKEN_INVALID SCOPE_MISSING
MEDIA_REQUIRED MEDIA_TOO_LARGE
MEDIA_FORMAT_UNSUPPORTED MEDIA_PROCESSING_FAILED
TEXT_TOO_LONG ACCOUNT_BANNED ACCOUNT_SUSPENDED
PAGE_REQUIRED PRIVACY_VIOLATION
PLATFORM_UNAVAILABLE PLATFORM_ERROR
TOKEN_EXPIRED is usually invisible to you: the worker refreshes and
retries before you'd ever see it. When a code does surface on a platform post,
it usually points to a specific issue, such as a suspended account, revoked access, or
unsupported media. Show the message so the user knows what to fix.
Webhooks
Subscribe to post outcomes and get pushed the moment a platform responds. Each request is signed, and failed deliveries are retried for you.
$ curl -X POST "https://socialpostapi.makketing.com/api/webhooks" \ -H "Authorization: Bearer $SOCIALPOSTAPI_KEY" \ -H "Content-Type: application/json" \ -d '{ "url": "https://yourapp.com/hooks/social", "events": ["post.published", "post.publish_failed"], "secret": "your-long-random-secret" }'
{ "id": "whk_…", "url": "https://yourapp.com/hooks/social", … }
- Events.
post.published(post_id,platform,permalink,platform_post_id) andpost.publish_failed(post_id,platform,error,error_details). You can also subscribe to"*". - Signatures. Every delivery carries
X-SocialPostAPI-Signature: sha256=<hex>contains an HMAC-SHA256 over the payload with your secret. Your secret is stored encrypted (and enforced to a minimum length); omit it and the service generates one, shown once in the create response. - Retries. Failed deliveries retry with exponential backoff and jitter (base 30 s). Every attempt is logged, and a customer endpoint never blocks publishing, and you can replay events from the delivery history.
- SSRF guards. URLs are validated when you create the webhook and again at delivery time (DNS is re-resolved; private, link-local and metadata ranges are rejected; redirects are never followed).
Rate limits
Limits are per tenant key, counted in a sliding window, and shared
across API replicas (the counters live in Redis, not in any one process). When you hit
one, the response is a 429 with RATE_LIMITED. Back off before retrying.
| Route | Limit |
|---|---|
| All routes (default) | 300 requests / minute |
POST /api/posts | 60 / minute |
POST /api/media | 30 / minute |
Two habits that keep you comfortably inside them: upload media ahead of posting (media ids are reusable), and poll post status only when you're not using webhooks. If your product needs higher limits, that's a conversation, not a hack.
FAQ
Are customer tokens encrypted at rest?
Yes. Every platform token is Fernet/AES-256 ciphertext before it touches the
database, keyed by an ENCRYPTION_KEY with no default. A
deployment without one refuses to boot. Plaintext exists only inside a worker's
memory during a publish call, never in logs or responses.
Does it refresh tokens automatically?
Yes. At publish time, when a platform answers TOKEN_EXPIRED, the
worker refreshes that platform's tokens, stores the new ciphertext, and retries the
post once in the same attempt. It's reactive, not a cron job: an idle account is
refreshed the next time a post actually runs. One exception, stated plainly:
standard LinkedIn apps get no refresh token, so a 60-day-old LinkedIn token means
reconnecting, not refreshing.
Can a post ever go out twice?
The service is built around exactly-once publishing. Your side: send an
Idempotency-Key, and a retried request replays the original response.
Our side: every platform call writes an intent record before it happens, and a
worker crash mid-call moves the attempt to needs_reconciliation for
human review. The service never retries it blindly.
Can one tenant read another tenant's data?
No. The tenant is derived from the API key on every request and applied to every query. Callers cannot set a tenant ID. Cross-tenant access attempts fail with 403/404, and the regression suite tests this per route, adversarially.
What happens if the customer revokes access on the platform?
Publishing fails with TOKEN_INVALID and the platform post says so.
A refresh cannot restore revoked access. Reconnect the account through the OAuth
flow, and publishing works again. Past posts are unaffected.
Do I need to write platform SDK code?
No. One request shape covers the six platforms we currently offer, and each platform's upload and publish steps are handled server-side. What each tenant needs is their own approved OAuth apps on the platforms you serve them on (Meta App Review, TikTok review, or an X developer app. These platform reviews are required before you can publish, but they do not change the API integration.
Where does media live?
Files use the storage backend configured for the service. Uploads return media IDs; the database stores object keys, and short-lived presigned URLs are minted at publish time so the platforms can fetch them.
Is there an MCP server?
Not yet. It's coming soon. The MCP server will let Claude and other MCP-compatible agents list profiles, upload media, and create and track posts through the same tenant-scoped keys as the REST API. It's one of several features on the roadmap; beta members get them first.
How do I get an API key?
Join the beta. During onboarding, we provision your tenant and issue an API key. It's shown once. Self-serve key management in the admin console is in flight. Keys are revocable at any time without touching your connected accounts.
What should I do when a publish fails?
Read the error_code on the platform post. It tells you whether
the fix is a retry, a reconnect, a format change, or something on the platform's
side. Transient failures retry on their own with backoff; permanent ones surface
with a message meant to be shown to a human. And a webhook tells you the moment it
happens.
Ready to put it to work?
Try the live demo with a real connected account, or join the beta list and we'll provision your tenant.