> ## Documentation Index
> Fetch the complete documentation index at: https://x-preview-mintlify-sse-streaming-1775019876.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# v1 to v2

export const Button = ({href, children}) => {
  return <div className="not-prose group">
    <a href={href}>
      <button className="flex items-center space-x-2.5 py-1 px-4 bg-primary-dark dark:bg-white text-white dark:text-gray-950 rounded-full group-hover:opacity-[0.9] font-medium">
        <span>
          {children}
        </span>
        <svg width="3" height="24" viewBox="0 -9 3 24" class="h-6 rotate-0 overflow-visible"><path d="M0 0L3 3L0 6" fill="none" stroke="currentColor" stroke-width="1.5" stroke-linecap="round"></path></svg>
      </button>
    </a>
  </div>;
};

### Standard v1.1 compared to X API v2

If you have been working with the standard v1.1 GET users/show and GET users/lookup, the goal of this guide is to help you understand the similarities and differences between the standard and X API v2 users lookup endpoints.

* **Similarities**
  * OAuth 1.0a User Context
  * Users per request limits
* **Differences**
  * Endpoint URLs
  * App and Project requirements
  * Response data format
  * Request parameters

#### Similarities

**OAuth 1.0a User Context authentication method**

The standard endpoint supports [OAuth 1.0a User Context](/resources/fundamentals/authentication#oauth-1-0a-2), while the new X API v2 users lookup endpoints supports both OAuth 1.0a User Context and [App only](/resources/fundamentals/authentication#oauth-2-0). Therefore, if you were previously using one of the standard v1.1 users lookup endpoints, you can continue using the same authentication method if you migrate to the X API v2 version.

Depending on your authentication library/package of choice, App only authentication is probably the easiest way to get started and can be set with a simple request header. To learn how to generate an App only Access Token, see [this App only guide](/resources/fundamentals/authentication#bearer-token-also-known-as-app-only).

**Users per request limits**

The standard v1.1 GET users/lookup endpoint allows you to specify 100 users per request. This also goes for the GET /users and GET /users/by endpoints. To specify a full 100 users, you will need to pass the ids (GET /users) parameter or the username (GET /users/by) parameter as a query parameter, and include the list of user IDs/usernames in a comma-separated list.

#### Differences

**Endpoint URLs**

* Standard v1.1 endpoints:
  * [https://api.x.com/1.1/users/show](https://api.x.com/1.1/users/show) (single-ID or username lookup)
  * [https://api.x.com/1.1/users/lookup](https://api.x.com/1.1/users/lookup) (multi-ID or username lookup)
* X API v2 endpoint:
  * [https://api.x.com/2/users](https://api.x.com/2/users) (multi-ID lookup)
  * [https://api.x.com/2/users/:id](https://api.x.com/2/users/:id) (single-ID lookup)
  * [https://api.x.com/2/users/by](https://api.x.com/2/users/by) (multi-username lookup)
  * [https://api.x.com/2/users/by/username/:username](https://api.x.com/2/users/by/username/:username) (single-username lookup)

**App and Project requirements**

The X API v2 endpoints require that you use credentials from a [developer App](/resources/fundamentals/developer-apps) that is associated to a [Project](/resources/fundamentals/developer-apps) when authenticating your requests. All X API v1.1 endpoints can use credentials from Apps or Apps associated with a project.

**Response data format**

One of the biggest differences between standard v1.1 and X API v2 endpoint versions is how you select which fields return in your payload.

For the standard endpoints, you receive many of the response fields by default, and then have the option to use parameters to identify which fields or sets of fields should return in the payload.

The X API v2 version only delivers the user id , name, and username fields by default. To request any additional fields or objects, you wil need to use the [fields](/x-api/fundamentals/fields) and [expansions](/x-api/fundamentals/expansions) parameters. Any user fields that you request from this endpoint will return in the primary user object. Any expanded Post object and fields will return in an includes object within your response. You can then match any expanded objects back to the user object by matching the IDs located in both the user and the expanded Post object.

We encourage you to read more about these new parameters in their respective guides, or by reading our guide on [how to use fields and expansions](/x-api/fundamentals/data-dictionary#how-to-use-fields-and-expansions).

We have also put together a [data format migration guide](/x-api/migrate/data-format-migration#migrating-from-standard-v1-1s-data-format-to-v2) which can help you map standard v1.1 fields to the newer v2 fields. This guide will also provide you the specific expansion and field parameter that you will need to pass with your v2 request to return specific fields.

In addition to the changes in how you request certain fields, X API v2 is also introducing new JSON designs for the objects returned by the APIs, including [Post](/x-api/fundamentals/data-dictionary#tweet) and [user](/x-api/fundamentals/data-dictionary#user) objects.

* At the JSON root level, the standard endpoints return Post objects in a statuses array, while X API v2 returns a data array.
* Instead of referring to Retweeted and Quoted "statuses", X API v2 JSON refers to Retweeted and Quoted Tweets. Many legacy and deprecated fields, such as contributors and user.translator\_type are being removed.
* Instead of using both favorites (in Post object) and favourites (in user object), X API v2 uses the term like.
* X is adopting the convention that JSON values with no value (for example, null) are not written to the payload. Post and user attributes are only included if they have a non-null values.

We also introduced a new set of fields to the [Post object](/x-api/fundamentals/data-dictionary#tweet) including the following:

* A [conversation\_id](/x-api/fundamentals/conversation-id) field
* Two new [annotations](/x-api/fundamentals/post-annotations) fields, including context and entities
* Several new [metrics](/x-api/fundamentals/metrics) fields
* A new reply\_setting field, which shows you who can reply to a given Post

**Request parameters**

The following standard v1.1 request parameters have equivalents in X API v2:

|              |              |
| :----------- | :----------- |
| **Standard** | **X API v2** |
| user\_id     | ids          |
| screen\_name | username     |

There are also a set of standard users lookup request parameters **not** supported in X API v2:

| Standard          | Comment                                                                                                                                                |
| :---------------- | :----------------------------------------------------------------------------------------------------------------------------------------------------- |
| include\_entities | This parameter is used to remove the entities node from the Post payload.  It has been replaced with the additive fields and expansions functionality. |

***

### Code Examples

The following examples show standard v1.1 endpoints and their v2 equivalents.

**Single user lookup: v1.1 `GET users/show` → v2 `GET /users/by/username/:username`**

<CodeGroup dropdown>
  ```bash cURL (v1.1) theme={null}
  curl --request GET \
    --url 'https://api.x.com/1.1/users/show.json?screen_name=XDevelopers' \
    --header 'Authorization: Bearer $ACCESS_TOKEN'
  ```

  ```bash cURL (v2) theme={null}
  curl --request GET \
    --url 'https://api.x.com/2/users/by/username/XDevelopers?user.fields=created_at,description,public_metrics' \
    --header 'Authorization: Bearer $ACCESS_TOKEN'
  ```

  ```python Python (v2) theme={null}
  import requests

  bearer_token = "YOUR_BEARER_TOKEN"
  url = "https://api.x.com/2/users/by/username/XDevelopers"

  params = {
      "user.fields": "created_at,description,public_metrics"
  }

  headers = {"Authorization": f"Bearer {bearer_token}"}
  response = requests.get(url, headers=headers, params=params)

  print(response.json())
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Get user by username with additional fields
  response = client.users.get_by_username(
      "XDevelopers",
      user_fields=["created_at", "description", "public_metrics"]
  )

  print(f"Name: {response.data.name}")
  print(f"Followers: {response.data.public_metrics.followers_count}")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  const response = await client.users.getByUsername("XDevelopers", {
    userFields: ["created_at", "description", "public_metrics"],
  });

  console.log(`Name: ${response.data?.name}`);
  console.log(`Followers: ${response.data?.public_metrics?.followers_count}`);
  ```
</CodeGroup>

**Multiple users lookup: v1.1 `GET users/lookup` → v2 `GET /users/by`**

<CodeGroup dropdown>
  ```bash cURL (v1.1) theme={null}
  curl --request GET \
    --url 'https://api.x.com/1.1/users/lookup.json?screen_name=XDevelopers,X,XAPI' \
    --header 'Authorization: Bearer $ACCESS_TOKEN'
  ```

  ```bash cURL (v2) theme={null}
  curl --request GET \
    --url 'https://api.x.com/2/users/by?usernames=XDevelopers,X,XAPI&user.fields=created_at,public_metrics' \
    --header 'Authorization: Bearer $ACCESS_TOKEN'
  ```

  ```python Python (v2) theme={null}
  import requests

  bearer_token = "YOUR_BEARER_TOKEN"
  url = "https://api.x.com/2/users/by"

  params = {
      "usernames": "XDevelopers,X,XAPI",
      "user.fields": "created_at,public_metrics"
  }

  headers = {"Authorization": f"Bearer {bearer_token}"}
  response = requests.get(url, headers=headers, params=params)

  for user in response.json()["data"]:
      print(f"{user['username']}: {user['public_metrics']['followers_count']} followers")
  ```

  ```python Python SDK theme={null}
  from xdk import Client

  client = Client(bearer_token="YOUR_BEARER_TOKEN")

  # Get multiple users by usernames
  response = client.users.get_users_by_usernames(
      usernames=["XDevelopers", "X", "XAPI"],
      user_fields=["created_at", "public_metrics"]
  )

  for user in response.data:
      print(f"{user.username}: {user.public_metrics.followers_count} followers")
  ```

  ```javascript JavaScript SDK theme={null}
  import { Client } from "@xdevplatform/xdk";

  const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

  const response = await client.users.getUsersByUsernames({
    usernames: ["XDevelopers", "X", "XAPI"],
    userFields: ["created_at", "public_metrics"],
  });

  response.data?.forEach((user) => {
    console.log(`${user.username}: ${user.public_metrics?.followers_count} followers`);
  });
  ```
</CodeGroup>
