# Usernames to IDs

`GET https://api.twittrapi.com/user/usernames/to/ids`

Numeric user IDs for up to 100 handles in one call.

HTML page: https://www.twittrapi.com/docs/reference/user-usernames-to-ids

## Parameters

| Name | In | Type | Required | Default | Description |
| --- | --- | --- | --- | --- | --- |
| `usernames` | query | string (comma-separated) | yes |  | Handles separated by commas, with or without @. At most 100. |

Every read endpoint also accepts `format=simple` (or the header `X-Response-Format: simple`) for compact, flat JSON with a fixed schema. Same price.

## Response

Built by the API: {"userIds": {"jack": "12", ...}}. Only resolved handles are keys of userIds. A handle that could not be resolved is left out of userIds and listed in errors: [{"username": "...", "error": "not_found" | "suspended" | "upstream_error", "message": "..."}]. errors is left out when every handle resolved. upstream_error means X could not be asked (retry later), not that the account is missing.

With `format=simple`: Unchanged inside {data: ...}: {userIds, errors} is already small, so the simple format only adds the envelope.

## Errors

| Status | When |
| --- | --- |
| 400 | usernames is missing, has more than 100 entries, or a handle contains characters X blocks. |
| 422 | A handle is not 2 to 15 letters, digits or underscores. |

Shared errors (401 missing key, 402 no balance, 429 rate limit, 5xx) are listed on https://www.twittrapi.com/docs/helpful-infos/error-handling. Calls that fail with 400, 408, 409 or a 5xx error are refunded.

## Example request

curl:

```bash
curl 'https://api.twittrapi.com/user/usernames/to/ids?usernames=jack,XDevelopers' \
  --header 'X-API-KEY: YOUR_API_KEY'
```

Python:

```python
import httpx

# No SDK method for this endpoint yet, so this is a plain HTTP call.
resp = httpx.get(
    "https://api.twittrapi.com/user/usernames/to/ids",
    headers={"X-API-KEY": "YOUR_API_KEY"},
    params={
        "usernames": "jack,XDevelopers",
    },
    timeout=60,
)
data = resp.json()
```

Node.js:

```js
import { TwittrAPI } from "twittrapi";

const client = new TwittrAPI({ apiKey: process.env.TWITTRAPI_API_KEY });
// No wrapper method for this endpoint yet; client.get() sends the same authenticated GET.
const data = await client.get({
  path: "/user/usernames/to/ids",
  query: {
    usernames: "jack,XDevelopers",
  },
});
```

RapidAPI:

```bash
curl 'https://twitter-aio.p.rapidapi.com/user/usernames/to/ids?usernames=jack,XDevelopers' \
  --header 'x-rapidapi-key: YOUR_RAPIDAPI_KEY' \
  --header 'x-rapidapi-host: twitter-aio.p.rapidapi.com'
```

## Example response

Shortened: arrays keep their first items and long strings are cut.

Raw (default):

```json
{
  "userIds": {
    "XDevelopers": "2244994945",
    "jack": "12"
  }
}
```

Simple (`format=simple`):

```json
{
  "data": {
    "userIds": {
      "XDevelopers": "2244994945",
      "jack": "12"
    }
  }
}
```
