Skip to main content
This guide walks you through making your first X API request. You’ll need a developer account with app credentials before starting.

Quick start with cURL

The fastest way to test the API is with cURL. Let’s look up a user:
curl "https://api.x.com/2/users/by/username/xdevelopers" \
  -H "Authorization: Bearer $BEARER_TOKEN"
Replace $BEARER_TOKEN with your actual Bearer Token. You’ll get a response like:
{
  "data": {
    "id": "2244994945",
    "name": "X Developers",
    "username": "xdevelopers"
  }
}

Step-by-step guide

1

Get your Bearer Token

In the Developer Console, navigate to your app and copy the Bearer Token.
2

Choose an endpoint

Start with one of these beginner-friendly endpoints:
EndpointWhat it does
User lookupGet user profile by username or ID
Post lookupGet post by ID
Recent searchSearch posts from the last 7 days
3

Make the request

Use cURL, Postman, or your preferred HTTP client:
# Look up a user by username
curl "https://api.x.com/2/users/by/username/xdevelopers" \
  -H "Authorization: Bearer $BEARER_TOKEN"
4

Parse the response

Responses are JSON. The primary data is in the data field:
{
  "data": {
    "id": "2244994945",
    "name": "X Developers",
    "username": "xdevelopers"
  }
}

Request more data with fields

By default, endpoints return minimal fields. Use the fields parameter to request additional data:
curl "https://api.x.com/2/users/by/username/xdevelopers?user.fields=created_at,description,public_metrics" \
  -H "Authorization: Bearer $BEARER_TOKEN"
Response:
{
  "data": {
    "id": "2244994945",
    "name": "X Developers",
    "username": "xdevelopers",
    "created_at": "2013-12-14T04:35:55.000Z",
    "description": "The voice of the X Developer Platform",
    "public_metrics": {
      "followers_count": 570842,
      "following_count": 2048,
      "tweet_count": 14052,
      "listed_count": 1672
    }
  }
}
Learn more about fields →

More examples

curl "https://api.x.com/2/tweets/1460323737035677698?tweet.fields=created_at,public_metrics" \
  -H "Authorization: Bearer $BEARER_TOKEN"

Using code instead of cURL

import requests

bearer_token = "YOUR_BEARER_TOKEN"
url = "https://api.x.com/2/users/by/username/xdevelopers"

headers = {"Authorization": f"Bearer {bearer_token}"}
response = requests.get(url, headers=headers)

print(response.json())

Tools for testing


Troubleshooting

  • Check that your Bearer Token is correct
  • Ensure the token hasn’t been regenerated
  • Verify the Authorization header format: Bearer YOUR_TOKEN
  • Your app may not have access to this endpoint
  • Some endpoints require user-context authentication (OAuth 1.0a or 2.0)
  • Check your app’s permissions in the Developer Console
  • You’ve hit a rate limit
  • Check the x-rate-limit-reset header for when to retry
  • Implement exponential backoff in your code
Full error reference →

Next steps