> ## Documentation Index
> Fetch the complete documentation index at: https://docs.webrouter.net/llms.txt
> Use this file to discover all available pages before exploring further.

# X (Twitter) API

> X API v2: search recent posts, look up users and posts, and read timelines and followers.

![](https://mintcdn.com/webrouter/8QP9EZc8V07Kl-0I/logo/data-apis/x.webp?fit=max\&auto=format\&n=8QP9EZc8V07Kl-0I\&q=85\&s=a5a184096093be0633ca41e2a238cc93)

[Web Catalog · Social](https://docs.webrouter.net/data-apis.md?category=social)

Needs&#x20;

`X_BEARER_TOKEN`

Endpoints

5

Auth

Key in header

[Vendor docs](https://docs.x.com/x-api) · [Pricing](https://docs.x.com/x-api/getting-started/pricing) · Serves `x.com`, `twitter.com`

## Setup

| Variable | | What it is |
| - | - | - |
| `X_BEARER_TOKEN` | required | An X API bearer token: an app-only token for public reads (developer console > your app > Keys and tokens), or a user-context OAuth 2.0 access token for the user's own actions such as posting |

Put them in your environment or `.env`; [Data APIs](https://docs.webrouter.net/vendors.md) covers the other ways.

## Notes

* A bearer token reads public data. Publishing needs a user-context access token with the right scopes, minted through X's OAuth 2.0 flow.
* Responses carry only default fields (id, text for posts; id, name, username for users): request more with post.fields and user.fields.
* Pagination is by next\_token (search) or pagination\_token (timelines) taken from meta in the previous answer.
* Access and rate limits depend on the developer account's plan (see pricing\_url).

## Endpoints

GET

Search posts from the last 7 days

Posts matching a search query, newest first, limited to the past 7 days.

[Open](#x-posts-search-recent)

GET

Get a user by username

Profile of one account by its handle (no @).

[Open](#x-users-by-username)

GET

Get a post by id

One post with the fields you ask for.

[Open](#x-posts-get)

GET

List a user's posts

A user's recent posts timeline, by numeric user id.

[Open](#x-users-posts)

GET

List a user's followers

Accounts following a user, by numeric user id.

[Open](#x-users-followers)

### Search posts from the last 7 days

GET

`/tweets/search/recent`

`x.posts.search_recent`

Posts matching a search query, newest first, limited to the past 7 days.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`query` required</td><td>string</td><td>query</td><td>X search query with operators (from:, lang:, -is:retweet, ...). Example `from:XDevelopers -is:retweet`</td></tr>

    <tr>
      <td>
        `max_results`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        10 to 100.
      </td>
    </tr>

    <tr>
      <td>
        `start_time`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td>
        ISO 8601; must be within the last 7 days.
      </td>
    </tr>

    <tr>
      <td>
        `end_time`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td>
        ISO 8601.
      </td>
    </tr>

    <tr>
      <td>
        `since_id`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td />
    </tr>

    <tr>
      <td>
        `until_id`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td />
    </tr>

    <tr><td>`sort_order`</td><td>string</td><td>query</td><td>recency or relevancy. One of `recency`, `relevancy`</td></tr>

    <tr>
      <td>
        `next_token`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td>
        Pagination token from meta.next\_token.
      </td>
    </tr>

    <tr><td>`post_fields`</td><td>string</td><td>query</td><td>Comma-separated post fields to return. Example `created_at,public_metrics,lang,conversation_id`</td></tr>
    <tr><td>`user_fields`</td><td>string</td><td>query</td><td>Comma-separated user fields to return. Example `created_at,description,public_metrics,verified`</td></tr>
    <tr><td>`expansions`</td><td>string</td><td>query</td><td>Comma-separated expansions, e.g. author\_id to include the author in includes.users. Example `author_id`</td></tr>
  </tbody>
</table>

[Vendor docs](https://docs.x.com/x-api/posts/search/introduction) · Same job: [AnyAPI](https://docs.webrouter.net/data-apis/anyapi.md#anyapi-facebook-search), [DEV Community](https://docs.webrouter.net/data-apis/dev-to.md#dev-to-articles-search), [FastMoss](https://docs.webrouter.net/data-apis/fastmoss.md#fastmoss-creators-search), [Fetchin](https://docs.webrouter.net/data-apis/fetchinio.md#fetchinio-posts-search), [HarvestAPI](https://docs.webrouter.net/data-apis/harvestapi.md#harvestapi-linkedin-post-search), [Hacker News Search (Algolia)](https://docs.webrouter.net/data-apis/hn-algolia.md#hn-algolia-search)

```python Python theme={null}
router.call_data_api("x.posts.search_recent", {'query': 'from:XDevelopers -is:retweet', 'post_fields': 'created_at,public_metrics,lang,conversation_id', 'user_fields': 'created_at,description,public_metrics,verified', 'expansions': 'author_id'})
```

```text MCP theme={null}
call_data_api(endpoint="x.posts.search_recent", params={"query": "from:XDevelopers -is:retweet", "post_fields": "created_at,public_metrics,lang,conversation_id", "user_fields": "created_at,description,public_metrics,verified", "expansions": "author_id"})
```

> [!NOTE]
>
> * Only the last 7 days: older posts need the full-archive search, which is a higher access tier and not listed here.
> * Without post.fields a post comes back as just id and text. Ask for public\_metrics, created\_at, author\_id.
> * Pages by meta.next\_token. Reads are billed to the developer account's X API plan.

### Get a user by username

GET

`/users/by/username/{username}`

`x.users.by_username`

Profile of one account by its handle (no @).

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`username` required</td><td>string</td><td>path</td><td>Handle without the @. Example `XDevelopers`</td></tr>
    <tr><td>`user_fields`</td><td>string</td><td>query</td><td>Comma-separated user fields to return. Example `created_at,description,public_metrics,verified`</td></tr>

    <tr>
      <td>
        `expansions`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td>
        Comma-separated: pinned\_post\_id, most\_recent\_post\_id.
      </td>
    </tr>

    <tr><td>`post_fields`</td><td>string</td><td>query</td><td>Comma-separated post fields to return. Example `created_at,public_metrics,lang,conversation_id`</td></tr>
  </tbody>
</table>

[Vendor docs](https://docs.x.com/x-api/users/lookup/introduction) · Same job: [AnyAPI](https://docs.webrouter.net/data-apis/anyapi.md#anyapi-facebook-profile), [Aviato](https://docs.webrouter.net/data-apis/aviato.md#aviato-company-social-metrics), [DEV Community](https://docs.webrouter.net/data-apis/dev-to.md#dev-to-users-get), [Facebook Pages (Graph API)](https://docs.webrouter.net/data-apis/facebook.md#facebook-page-get), [Fetchin](https://docs.webrouter.net/data-apis/fetchinio.md#fetchinio-post-reactions), [HarvestAPI](https://docs.webrouter.net/data-apis/harvestapi.md#harvestapi-linkedin-post-reactions)

```python Python theme={null}
router.call_data_api("x.users.by_username", {'username': 'XDevelopers', 'user_fields': 'created_at,description,public_metrics,verified', 'post_fields': 'created_at,public_metrics,lang,conversation_id'})
```

```text MCP theme={null}
call_data_api(endpoint="x.users.by_username", params={"username": "XDevelopers", "user_fields": "created_at,description,public_metrics,verified", "post_fields": "created_at,public_metrics,lang,conversation_id"})
```

> [!NOTE]
>
> * Returns only id, name and username unless user.fields asks for more (description, public\_metrics, created\_at, verified ...).

### Get a post by id

GET

`/tweets/{id}`

`x.posts.get`

One post with the fields you ask for.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr><td>`id` required</td><td>string</td><td>path</td><td>Post id. Example `1460323737035677698`</td></tr>
    <tr><td>`post_fields`</td><td>string</td><td>query</td><td>Comma-separated post fields to return. Example `created_at,public_metrics,lang,conversation_id`</td></tr>
    <tr><td>`user_fields`</td><td>string</td><td>query</td><td>Comma-separated user fields to return. Example `created_at,description,public_metrics,verified`</td></tr>
    <tr><td>`expansions`</td><td>string</td><td>query</td><td>Comma-separated expansions, e.g. author\_id to include the author in includes.users. Example `author_id`</td></tr>
  </tbody>
</table>

[Vendor docs](https://docs.x.com/x-api/posts/lookup/introduction) · Same job: [akta.pro](https://docs.webrouter.net/data-apis/akta.md#akta-company-social-posts), [AnyAPI](https://docs.webrouter.net/data-apis/anyapi.md#anyapi-facebook-posts), [DEV Community](https://docs.webrouter.net/data-apis/dev-to.md#dev-to-articles-list), [Edges](https://docs.webrouter.net/data-apis/edges.md#edges-post-extract), [Facebook Pages (Graph API)](https://docs.webrouter.net/data-apis/facebook.md#facebook-page-feed), [FastMoss](https://docs.webrouter.net/data-apis/fastmoss.md#fastmoss-videos-search)

```python Python theme={null}
router.call_data_api("x.posts.get", {'id': '1460323737035677698', 'post_fields': 'created_at,public_metrics,lang,conversation_id', 'user_fields': 'created_at,description,public_metrics,verified', 'expansions': 'author_id'})
```

```text MCP theme={null}
call_data_api(endpoint="x.posts.get", params={"id": "1460323737035677698", "post_fields": "created_at,public_metrics,lang,conversation_id", "user_fields": "created_at,description,public_metrics,verified", "expansions": "author_id"})
```

### List a user's posts

GET

`/users/{id}/tweets`

`x.users.posts`

A user's recent posts timeline, by numeric user id.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `id`

        required
      </td>

      <td>
        string
      </td>

      <td>
        path
      </td>

      <td>
        Numeric user id (not the handle): get it from users.by\_username.
      </td>
    </tr>

    <tr>
      <td>
        `max_results`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        5 to 100.
      </td>
    </tr>

    <tr>
      <td>
        `pagination_token`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td>
        meta.next\_token from the previous page.
      </td>
    </tr>

    <tr>
      <td>
        `start_time`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td />
    </tr>

    <tr>
      <td>
        `end_time`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td />
    </tr>

    <tr>
      <td>
        `since_id`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td />
    </tr>

    <tr>
      <td>
        `until_id`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td />
    </tr>

    <tr>
      <td>
        `exclude`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td>
        Comma-separated: replies, retweets.
      </td>
    </tr>

    <tr><td>`post_fields`</td><td>string</td><td>query</td><td>Comma-separated post fields to return. Example `created_at,public_metrics,lang,conversation_id`</td></tr>
    <tr><td>`expansions`</td><td>string</td><td>query</td><td>Comma-separated expansions, e.g. author\_id to include the author in includes.users. Example `author_id`</td></tr>
  </tbody>
</table>

[Vendor docs](https://docs.x.com/x-api/posts/timelines/introduction) · Same job: [akta.pro](https://docs.webrouter.net/data-apis/akta.md#akta-company-social-posts), [AnyAPI](https://docs.webrouter.net/data-apis/anyapi.md#anyapi-facebook-posts), [DEV Community](https://docs.webrouter.net/data-apis/dev-to.md#dev-to-articles-list), [Edges](https://docs.webrouter.net/data-apis/edges.md#edges-post-extract), [Facebook Pages (Graph API)](https://docs.webrouter.net/data-apis/facebook.md#facebook-page-feed), [FastMoss](https://docs.webrouter.net/data-apis/fastmoss.md#fastmoss-videos-search)

### List a user's followers

GET

`/users/{id}/followers`

`x.users.followers`

Accounts following a user, by numeric user id.

Input

<table>
  <thead>
    <tr>
      <th>
        Name
      </th>

      <th>
        Type
      </th>

      <th>
        In
      </th>

      <th>
        Notes
      </th>
    </tr>
  </thead>

  <tbody>
    <tr>
      <td>
        `id`

        required
      </td>

      <td>
        string
      </td>

      <td>
        path
      </td>

      <td>
        Numeric user id.
      </td>
    </tr>

    <tr>
      <td>
        `max_results`
      </td>

      <td>
        integer
      </td>

      <td>
        query
      </td>

      <td>
        1 to 1000.
      </td>
    </tr>

    <tr>
      <td>
        `pagination_token`
      </td>

      <td>
        string
      </td>

      <td>
        query
      </td>

      <td />
    </tr>

    <tr><td>`user_fields`</td><td>string</td><td>query</td><td>Comma-separated user fields to return. Example `created_at,description,public_metrics,verified`</td></tr>
  </tbody>
</table>

[Vendor docs](https://docs.x.com/x-api/users/follows/introduction) · Same job: [AnyAPI](https://docs.webrouter.net/data-apis/anyapi.md#anyapi-facebook-profile), [Aviato](https://docs.webrouter.net/data-apis/aviato.md#aviato-company-social-metrics), [DEV Community](https://docs.webrouter.net/data-apis/dev-to.md#dev-to-users-get), [Facebook Pages (Graph API)](https://docs.webrouter.net/data-apis/facebook.md#facebook-page-get), [Fetchin](https://docs.webrouter.net/data-apis/fetchinio.md#fetchinio-post-reactions), [HarvestAPI](https://docs.webrouter.net/data-apis/harvestapi.md#harvestapi-linkedin-post-reactions)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.