# Username to ID

`GET https://api.twittrapi.com/username/to/id/{username}`

Numeric user ID for one handle. Smaller response than the full profile.

HTML page: https://www.twittrapi.com/docs/reference/username-to-id-username

## Parameters

| Name | In | Type | Required | Default | Description |
| --- | --- | --- | --- | --- | --- |
| `username` | path | string | yes |  | Handle, with or without a leading @. 2 to 15 characters: letters, digits and underscore. |

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: {"userId": "12"}.

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

## Errors

| Status | When |
| --- | --- |
| 422 | The username is invalid, or no user was found (body has errorInfo with X's response). |
| 400 | The username contains characters X blocks, or X returned an error. |

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/username/to/id/jack' \
  --header 'X-API-KEY: YOUR_API_KEY'
```

Python:

```python
from twittrapi import TwittrAPI

client = TwittrAPI(api_key="YOUR_API_KEY")
data = client.users.username_to_id("jack")
```

Node.js:

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

const client = new TwittrAPI({ apiKey: process.env.TWITTRAPI_API_KEY });
const data = await client.users.usernameToId("jack");
```

RapidAPI:

```bash
curl 'https://twitter-aio.p.rapidapi.com/username/to/id/jack' \
  --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
{
  "userId": "2244994945"
}
```

Simple (`format=simple`):

```json
{
  "data": {
    "userId": "2244994945"
  }
}
```
