SocialPostAPI
The mental model

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).

The fastest path

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:

bash: keep the key on your server
$ 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.

bash: request a login URL
$ 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.

bash: get Instagram login and callback URLs
$ 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:

bash: list connected profiles
$ 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.

bash: upload media
$ 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.

bash: publish to X and Instagram
$ 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.

Identity

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.

shown once sap_9fR2tQ8xLm4vNp6wKc3jHs1dYb7uZe5a stored prefix sap_9fR2tQ8xL stored hash sha256(key) → 64 hex chars, keyed by tenant

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.
OAuth, handled

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:

1Login URL 2Customer consents 3Platform redirects 4Token exchange 5Encrypt & store 6Success page

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.

Step 1 of 6

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.

The part everyone asks about

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

access_token_encrypted gAAAAABm8zQ…AES-256 Fernet ciphertext…== refresh_token_encrypted gAAAAABm8zQ…ciphertext…== (platforms without refresh grants store none) token_expires_at 2026-11-27T09:14:02Z

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:

worker: publishing pst_x9k2Qw8
encrypted in DB decrypted in memory platform call refresh re-encrypted retry published

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

PlatformRefresh mechanismRefresh token
Xrefresh_token grantNew token pair is stored
InstagramLong-lived token re-exchangeThe access token is extended
FacebookPage token re-derived from the user tokenNo refresh token
TikTokrefresh_token grantNew token pair is stored
YouTubeGoogle refresh grantGoogle reuses the same refresh token
LinkedInrefresh_token grantOnly 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.

Exactly-once publishing

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 with POST /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

  1. Idempotency keys. Send an Idempotency-Key header on POST /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.
  2. Intent records. Before any platform call, the worker commits a publish_attempt row (in_flight), updated to succeeded or failed afterwards. If the worker dies mid-call, the attempt is found stuck and moved to needs_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.

Upload once, format per platform

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
No silent drops

Errors and retries

Errors include a code and, when available, the platform's message. Here's the response format:

JSON error response
{
  "error": "The LinkedIn access token has expired. LinkedIn tokens expire after 60 days…",
  "error_code": "TOKEN_EXPIRED",
  "details": { "platform": "linkedin" }
}
HTTPMeaning
400Malformed request (bad JSON, unknown fields)
401Missing, malformed or revoked API key
403Key is valid but not allowed this action (e.g. touching another tenant's resource)
404Unknown post, profile, media or webhook id
409An Idempotency-Key for this request is still in flight. Retry shortly.
422Validation failed. Check text length, media count and type, and schedule.
429Rate limit reached. See the table below.
503Storage 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.

Be told, don't poll

Webhooks

Subscribe to post outcomes and get pushed the moment a platform responds. Each request is signed, and failed deliveries are retried for you.

bash: create a webhook
$ 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) and post.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).
Fair use, enforced fairly

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.

RouteLimit
All routes (default)300 requests / minute
POST /api/posts60 / minute
POST /api/media30 / 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.

Short answers

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.