How to Batch Fetch X User Profiles with TwexAPI
When you already have a list of X handles, the next step is usually enrichment: turn elonmusk, sundarpichai, or a column of profile URLs into structured profile records your CRM, research database, or dashboard can use.
TwexAPI's Get Multiple Users endpoint does that in one request body. Send an array of usernames or X profile URLs to POST /twitter/users, then normalize the returned profile objects and keep a clear record of any accounts that were not found.
When This Endpoint Fits
Use POST /twitter/users when your input is a list of handles or profile URLs and you need profile metadata in bulk.
Good examples:
- Enriching an influencer spreadsheet with names, bios, locations, verification fields, and follower counts when present.
- Refreshing a KOL database before a campaign.
- Checking which handles in a community list still resolve to active profiles.
- Adding author metadata to a dataset collected from tweets, replies, lists, or search results.
If your input is numeric user IDs instead of usernames, use POST /twitter/users/by_ids for that workflow.
Endpoint and Request Body
Send a POST request to:
https://api.twexapi.io/twitter/usersThe request body is a JSON array of strings. Each string can be a username or a profile URL.
curl --request POST \
--url https://api.twexapi.io/twitter/users \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '[
"elonmusk",
"sundarpichai",
"https://x.com/tim_cook"
]'The API returns a response object with code, msg, and data. The data array contains user profile objects. If a username cannot be found, that position may be returned as null, so your code should handle missing rows explicitly.
1{
2 "code": 200,
3 "msg": "success",
4 "data": [
5 {
6 "userId": "44196397",
7 "username": "elonmusk",
8 "name": "Elon Musk",
9 "description": "<profile bio>",
10 "followersCount": 1000000,
11 "isBlueVerified": true,
12 "verified": true
13 },
14 null
15 ]
16}Treat field names as response data, not as a fixed database schema. Store the raw profile object first, then map the fields your product actually needs.
Python Batch Enrichment Script
This script reads handles from a list, calls POST /twitter/users in batches, writes normalized JSONL rows, and records missing inputs.
1import json
2import time
3from datetime import datetime, timezone
4from pathlib import Path
5
6import requests
7
8TOKEN = "<your_bearer_token>"
9URL = "https://api.twexapi.io/twitter/users"
10INPUTS = [
11 "elonmusk",
12 "sundarpichai",
13 "https://x.com/tim_cook",
14]
15BATCH_SIZE = 20
16OUT = Path("x-user-profiles.jsonl")
17MISSING = Path("x-user-profiles-missing.json")
18
19headers = {
20 "Authorization": f"Bearer {TOKEN}",
21 "Content-Type": "application/json",
22}
23
24def chunks(items, size):
25 for index in range(0, len(items), size):
26 yield items[index:index + size]
27
28missing = []
29
30with OUT.open("w", encoding="utf-8") as f:
31 for batch in chunks(INPUTS, BATCH_SIZE):
32 response = requests.post(URL, headers=headers, json=batch, timeout=30)
33 response.raise_for_status()
34 body = response.json()
35 profiles = body.get("data") or []
36
37 for original_input, profile in zip(batch, profiles):
38 if profile is None:
39 missing.append(original_input)
40 continue
41
42 row = {
43 "input": original_input,
44 "user_id": profile.get("userId") or profile.get("user_id"),
45 "username": profile.get("username") or profile.get("screen_name"),
46 "name": profile.get("name"),
47 "description": profile.get("description"),
48 "followers_count": profile.get("followersCount") or profile.get("followers_count"),
49 "verified": profile.get("verified"),
50 "is_blue_verified": profile.get("isBlueVerified") or profile.get("is_blue_verified"),
51 "fetched_at": datetime.now(timezone.utc).isoformat(),
52 "raw": profile,
53 }
54 f.write(json.dumps(row, ensure_ascii=False) + "\n")
55
56 time.sleep(1)
57
58MISSING.write_text(json.dumps({
59 "fetched_at": datetime.now(timezone.utc).isoformat(),
60 "missing": missing,
61}, ensure_ascii=False, indent=2), encoding="utf-8")
62
63print(f"Saved profiles to {OUT}; missing inputs: {len(missing)}")Choose a batch size that matches your plan and error tolerance. Smaller batches are easier to retry and make it clearer which inputs failed.
Handling Missing or Renamed Accounts
Bulk profile enrichment gets messy when handles change, accounts are suspended, or profile URLs have been copied with extra tracking characters. Keep the lookup process observable:
- Save the original input next to the normalized username returned by the API.
- Keep
nullresults in a separate missing file instead of silently dropping them. - Recheck missing accounts later before marking them permanently unavailable.
- Deduplicate inputs after normalizing case and stripping URL prefixes.
- Store the fetch timestamp because profile metadata can change.
This makes the output useful for both product workflows and later audits.
Use User IDs When You Have Them
If your source data already contains numeric user IDs, call:
POST https://api.twexapi.io/twitter/users/by_idsThe request body is also an array of strings, but each item is a user ID.
curl --request POST \
--url https://api.twexapi.io/twitter/users/by_ids \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--data '[
"44196397",
"1696160451770429440"
]'Use IDs for durable joins when you already have them. Use usernames when your input comes from spreadsheets, profile URLs, influencer lists, or manually curated research.
Where This Fits in a Data Pipeline
A clean profile enrichment pipeline usually has four stages:
- Collect candidate handles from search, list members, tweet authors, replies, or a spreadsheet.
- Normalize handles and remove duplicates.
- Call
POST /twitter/usersin batches and store raw responses. - Map the fields your application needs into a stable table.
For analytics, avoid making ranking decisions from follower count alone. Combine profile metadata with recent posting behavior, engagement quality, topic fit, and manual review when the decision affects outreach or spend.
Wrap-up
For username-based enrichment, use POST /twitter/users with a JSON array of handles or profile URLs. Store raw profiles, handle null results, and keep the original input beside the normalized profile.
That turns a messy list of X handles into a usable profile table without pretending the data is more stable than it is.