Sign inSign up

nierdna/x-post-api

By nierdna

Updated 11 months ago

Image
0

202

nierdna/x-post-api repository overview

X Post API

Minimal Express API to post a tweet (content + optional image) to X (Twitter) and return the result (tweet id + URL).

📚 API Documentation

Interactive Swagger documentation is available at:

http://localhost:3000/api-docs

Open this URL in your browser after starting the server to explore and test all API endpoints with a beautiful UI.

Endpoints

GET /me

Test endpoint to verify Twitter API credentials and get authenticated user information.

POST /tweet

Options:

  • JSON:

    {
      "content": "Hello from my API 🚀",
      "imageUrl": "https://picsum.photos/800/450"
    }
    
  • multipart/form-data:

    • content (text)
    • image (file)

Response sample:

{
  "ok": true,
  "tweetId": "1234567890123456789",
  "url": "https://x.com/i/web/status/1234567890123456789"
}

Getting Started

pnpm install
cp .env.example .env
# edit your .env with Twitter keys
pnpm start

Notes

  • Requires OAuth 1.0a user context keys (app key/secret + access token/secret).
  • Images are converted to JPEG ~88 quality to reduce upload errors/size.
  • The returned URL uses /i/web/status/{id} which doesn't require the username.

Tag summary

Content type

Image

Digest

sha256:cefbaec41

Size

63.3 MB

Last updated

11 months ago

docker pull nierdna/x-post-api