X (Twitter)

X API: Post a Tweet

How to publish a post to X (formerly Twitter) via API.

Quick answer

Connect an X profile — your own OAuth 1.0a developer app or PostGate’s house app — then send one POST /api/posts call with the profile ID, a body, and any media. PostGate validates X’s 280-character weighted limit and media rules before sending, and X’s per-action charge applies via your own app or your workspace credit balance.

This is the shortest path from a piece of content to a live post on X (formerly Twitter): one connected profile, one POST /api/posts call. For the full walkthrough with error handling and delivery polling, see How to Post to X via API. If you want the raw X API v2 call underneath, see Twitter API v2: Create a Tweet.

X is the one platform in PostGate where publishing has a direct dollar cost per action — worth understanding before your first request. You can start in the sandbox for free to see the full request/response shape before connecting a real X account.

01

Connect an X profile

X publishing requires an X developer app with OAuth 1.0a enabled — the classic “API Key” / “API Key Secret” consumer credentials, not the OAuth 2.0 client ID/secret pair most other platforms use. You can bring your own developer app, or use PostGate's house app and draw down your workspace credit balance instead. See the X platform guide for the full capability table.
Connect a profilePostGate API
curl -X POST https://postgate.studio/api/profiles/connect \
  -H "Authorization: Bearer $POSTGATE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "platform": "x",
    "profile_group_id": "grp_acme123",
    "return_url": "https://app.example.com/settings/social"
  }'
02

Publish the post

Once connected, X is just another target in the same unified envelope used for every platform: pass the profile ID, a body, and any media. A stable Idempotency-Key makes the request safe to retry.
Publish nowPostGate API
curl -X POST "https://postgate.studio/api/posts?profile_group_id=grp_acme123" \
  -H "Authorization: Bearer $POSTGATE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: launch-post-x-001" \
  -d '{
    "post": { "body": "Launch day. 🚀" },
    "profiles": ["pro_x123"],
    "media": ["https://cdn.example.com/launch.jpg"]
  }'
03

What does this request actually cost?

X charges per post and per analytics read — a real mechanic, not a PostGate markup. Bring your own X developer app and you publish at no credit cost to your PostGate workspace; use PostGate's shared app instead and the equivalent charge is drawn from your workspace credit balance. See X API Pricing Tiers for the current per-action prices.
04

Text and media limits enforced before you pay for it

PostGate validates against X's real limits before sending: 280 characters using X's weighted counting (URLs and non-Latin characters don't count 1:1 with plain ASCII), up to 4 media items, images up to 5 MB, and MP4 video up to 512 MB / 140 seconds. Larger video should go through chunked media upload first.
05

Read back the result

The response includes a per-target status, the platform post ID, and the permalink once delivered. Poll the post if you need to wait for a not-yet-terminal target.
Check deliveryPostGate API
curl https://postgate.studio/api/posts/post_01JXYZ \
  -H "Authorization: Bearer $POSTGATE_API_KEY"

Frequently asked questions

Does posting to X through the API cost money?

Yes — X charges per post and per analytics read, a real mechanic rather than a PostGate markup. Bring your own X developer app and you publish at no credit cost to your PostGate workspace; use PostGate’s shared app instead and the equivalent charge is drawn from your workspace credit balance.

What are the text and media limits for an X post?

PostGate validates against X’s real limits before sending: 280 characters using X’s weighted counting (URLs and non-Latin characters don’t count 1:1 with plain ASCII), up to 4 media items, images up to 5 MB, and MP4 video up to 512 MB and 140 seconds. Larger video goes through chunked media upload first.

What kind of OAuth does X publishing require?

An X developer app with OAuth 1.0a enabled — the classic “API Key” / “API Key Secret” consumer credentials, not the OAuth 2.0 client ID/secret pair most other platforms use. Alternatively, use PostGate’s house app and draw down your workspace credit balance instead.

How do I confirm the post was delivered?

The response includes a per-target status, the platform post ID, and the permalink once delivered. Poll the post with GET /api/posts/{id} if you need to wait for a not-yet-terminal target.

Build it with PostGate

One API for every social platform your customers care about — sandboxed, documented, and ready today.

Start building Read the docs