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

# User Lookup Quickstart

> This guide walks you through looking up users by their ID or username. Reference for the X API v2 standard tier covering quickstart.

This guide walks you through looking up users by their ID or username.

> [!NOTE]
>
> **Prerequisites**
>
> Before you begin, you'll need:
>
> * A [developer account](https://developer.x.com/en/portal/petition/essential/basic-info) with an approved App
> * Your App's Bearer Token

***

## Look up by ID

### Single user

```bash cURL theme={null}
curl "https://api.x.com/2/users/2244994945?\
user.fields=created_at,description,verified,public_metrics" \
  -H "Authorization: Bearer $BEARER_TOKEN"
```

```python title="Python SDK" lines wrap icon="python" theme={null}
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Get user by ID
response = client.users.get(
    "2244994945",
    user_fields=["created_at", "description", "verified", "public_metrics"]
)

print(f"Name: {response.data.name}")
print(f"Username: {response.data.username}")
print(f"Followers: {response.data.public_metrics.followers_count}")
```

```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
import { Client } from "@xdevplatform/xdk";

const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

// Get user by ID
const response = await client.users.get("2244994945", {
  userFields: ["created_at", "description", "verified", "public_metrics"],
});

console.log(`Name: ${response.data?.name}`);
console.log(`Username: ${response.data?.username}`);
console.log(`Followers: ${response.data?.public_metrics?.followers_count}`);
```

### Response

```json title="Example response" lines wrap icon="https://mintcdn.com/x-preview/Vn2KEkZaPF9LiPi3/icons/xds/icon-brackets.svg?fit=max&auto=format&n=Vn2KEkZaPF9LiPi3&q=85&s=ed2428e77bab43e57800e1a590e982fa" theme={null}
{
  "data": {
    "id": "2244994945",
    "name": "X Developers",
    "username": "XDevelopers",
    "created_at": "2013-12-14T04:35:55.000Z",
    "description": "The voice of the X developer community",
    "verified": true,
    "public_metrics": {
      "followers_count": 583423,
      "following_count": 2048,
      "tweet_count": 14052,
      "listed_count": 1672
    }
  }
}
```

### Multiple users

Look up to 100 users at once:

```bash cURL theme={null}
curl "https://api.x.com/2/users?\
ids=2244994945,783214,6253282&\
user.fields=username,verified" \
  -H "Authorization: Bearer $BEARER_TOKEN"
```

```python title="Python SDK" lines wrap icon="python" theme={null}
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Get multiple users by ID
response = client.users.get_users(
    ids=["2244994945", "783214", "6253282"],
    user_fields=["username", "verified"]
)

for user in response.data:
    print(f"{user.username} - Verified: {user.verified}")
```

```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
import { Client } from "@xdevplatform/xdk";

const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

// Get multiple users by ID
const response = await client.users.getUsers({
  ids: ["2244994945", "783214", "6253282"],
  userFields: ["username", "verified"],
});

response.data?.forEach((user) => {
  console.log(`${user.username} - Verified: ${user.verified}`);
});
```

***

## Look up by username

### Single user

```bash cURL theme={null}
curl "https://api.x.com/2/users/by/username/XDevelopers?\
user.fields=created_at,description,verified" \
  -H "Authorization: Bearer $BEARER_TOKEN"
```

```python title="Python SDK" lines wrap icon="python" theme={null}
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Get user by username
response = client.users.get_by_username(
    "XDevelopers",
    user_fields=["created_at", "description", "verified"]
)

print(f"ID: {response.data.id}")
print(f"Name: {response.data.name}")
```

```javascript JavaScript SDK theme={null}
import { Client } from "@xdevplatform/xdk";

const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

// Get user by username
const response = await client.users.getByUsername("XDevelopers", {
  userFields: ["created_at", "description", "verified"],
});

console.log(`ID: ${response.data?.id}`);
console.log(`Name: ${response.data?.name}`);
```

### Multiple users

```bash cURL theme={null}
curl "https://api.x.com/2/users/by?\
usernames=XDevelopers,X,elonmusk&\
user.fields=created_at,verified" \
  -H "Authorization: Bearer $BEARER_TOKEN"
```

```python title="Python SDK" lines wrap icon="python" theme={null}
from xdk import Client

client = Client(bearer_token="YOUR_BEARER_TOKEN")

# Get multiple users by username
response = client.users.get_users_by_usernames(
    usernames=["XDevelopers", "X", "elonmusk"],
    user_fields=["created_at", "verified"]
)

for user in response.data:
    print(f"{user.username} - {user.created_at}")
```

```javascript title="JavaScript SDK" lines wrap icon="square-js" theme={null}
import { Client } from "@xdevplatform/xdk";

const client = new Client({ bearerToken: "YOUR_BEARER_TOKEN" });

// Get multiple users by username
const response = await client.users.getUsersByUsernames({
  usernames: ["XDevelopers", "X", "elonmusk"],
  userFields: ["created_at", "verified"],
});

response.data?.forEach((user) => {
  console.log(`${user.username} - ${user.created_at}`);
});
```

***

## Available fields

| Field | Description |
| :- | :- |
| `created_at` | Account creation date |
| `description` | User bio |
| `profile_image_url` | Avatar URL |
| `verified` | Verification status |
| `public_metrics` | Follower/following counts |
| `location` | User-defined location |
| `url` | User's website |
| `protected` | Protected account status |
| `pinned_tweet_id` | Pinned Post ID |

***

## Handle errors

### User not found

```json theme={null}
{
  "errors": [
    {
      "resource_type": "user",
      "title": "Not Found Error",
      "detail": "Could not find user with username: [nonexistent_user]."
    }
  ]
}
```

### Protected user

Protected users' data is still returned, but you won't be able to access their Posts unless you follow them.

***

## Next steps

> [card] [Authenticated user](https://docs.x.com/x-api/users/lookup/quickstart/authenticated-lookup.md)
>
> Get the current user

> [card] [Integration guide](https://docs.x.com/x-api/users/lookup/integrate.md)
>
> Key concepts and best practices

> [card] [API Reference](https://docs.x.com/x-api/users/get-user-by-id.md)
>
> Full endpoint documentation
