ID Conversion
Convert between X (formerly Twitter) usernames, numeric user IDs, and profile URLs. Three lightweight utility endpoints, one request each.Note: For a fuller explainer on usernames, user IDs, and profile links, see Twitter ID Converter: Username, User ID, and Profile Link on the blog.
No-code option: for one-off conversions, use the free Sorsa ID Converter web tool. Paste a username, ID, or profile URL and get the result instantly, no API key required.
Why User IDs Matter
A username (handle) can be changed at any time, and once released, can be claimed by someone else. A numeric user ID is assigned at account creation and never changes. If you are building anything that stores or references X accounts, work with user IDs:- Handle changes do not break your system. The ID points to the same account regardless of how many times the user renames.
- Indexes are faster. Integer keys outperform variable-length string keys.
- Cross-time joins are clean. When matching accounts across datasets collected at different times, IDs are the only safe key.
- Some Sorsa endpoints accept only IDs.
/info-batchacceptsuser_ids, and several community and list endpoints reference accounts by numeric ID.
How User IDs Are Formatted
X uses Snowflake IDs: 64-bit integers that pack a timestamp, a machine ID, and a sequence number into a single value. Tweet IDs have used this format since 2010. User IDs are different. X kept assigning sequential integer IDs to accounts for years after Snowflake launched, and only migrated user IDs to the Snowflake format around 2020. This is why older accounts have short IDs (Jack Dorsey’s account is12) while accounts created after 2020 have 19-digit IDs. The practical consequence: you cannot decode a creation timestamp from older user IDs. If you need a registration date for an older account, fetch the profile and read created_at.
Endpoint 1: Username to User ID
@) into the permanent numeric user ID.
Endpoint 2: User ID to Username
Endpoint 3: Profile Link to User ID
Tip: if you need both the user ID and the full profile, skip the conversion step and call/infowith theusernameparameter. It returns the complete profile (includingid) in a single request. See Optimizing API Usage for more patterns like this.
Common Patterns
Batch Conversion
When you have a list of handles (CRM export, competitor list, spreadsheet) and need to convert them all to IDs:/id-to-username/{user_id} and read the handle field from the response. This is useful for refreshing a database that may have stale display names.
Normalizing Mixed Input
When users submit account references in different formats (some as handles, some as URLs, some as IDs), normalize everything to user IDs. The check below skips the API call entirely when the input is already an ID:Detecting Handle Changes
If you stored both the user ID and the handle at collection time, you can periodically re-resolve the IDs and detect which accounts have renamed:/about endpoint returns username_change_count and last_username_change_at. That tells you not just the current handle but how many times the account has renamed and when the most recent change happened.
Next Steps
- Followers & Following: most follower-extraction workflows start with ID conversion.
- Audience Geography: the
/aboutendpoint acceptsuser_idand returns country data plus username change history. - Optimizing API Usage: avoid unnecessary conversion calls by using
/infodirectly when you need the full profile. - API Reference: full specification for
/username-to-id,/id-to-username,/link-to-id, and every other Sorsa endpoint.