Build with TRMesh social data APIs by example
Move from your first request to pagination, CSV export and concurrent collection with practical templates. Every request goes through TRMesh's /openapi/* proxy path and remains governed by tokens, balance, rate limits, billing and usage logs.
import os
import requests
url = "https://api.trmesh.com/openapi/api/v1/instagram/web_app/fetch_user_info_by_username"
headers = {
"accept": "application/json",
"Authorization": f"Bearer {os.environ['TRMESH_API_TOKEN']}",
}
params = {"username": "instagram"}
response = requests.get(url, headers=headers, params=params, timeout=30)
print(response.status_code)
print(response.json())Create a developer token from the authenticated TRMesh workspace.
Confirm that the account has free quota or USD balance before calling paid endpoints.
Use the API docs to verify route status, parameters and the /openapi/* proxy path.
Code examples
The examples use public social-data lookup scenarios. Replace the route, parameters and processing logic with your own workflow.
- Set TRMESH_API_TOKEN to a developer token from the workspace.
- Install dependencies before running locally: pip install requests.
import os
import requests
url = "https://api.trmesh.com/openapi/api/v1/instagram/web_app/fetch_user_info_by_username"
headers = {
"accept": "application/json",
"Authorization": f"Bearer {os.environ['TRMESH_API_TOKEN']}",
}
params = {"username": "instagram"}
response = requests.get(url, headers=headers, params=params, timeout=30)
print(response.status_code)
print(response.json())- Pagination fields differ by route, so follow the API docs for the selected endpoint.
- Always cap the maximum page count for worker jobs.
const token = process.env.TRMESH_API_TOKEN;
const collected = [];
let cursor = "0";
for (let page = 0; page < 3; page += 1) {
const url = new URL("https://api.trmesh.com/openapi/api/v1/tiktok/web/fetch_user_post_videos");
url.searchParams.set("secUid", "example-sec-uid");
url.searchParams.set("cursor", cursor);
url.searchParams.set("count", "20");
const response = await fetch(url, {
headers: { Authorization: `Bearer ${token}`, accept: "application/json" },
});
if (!response.ok) throw new Error(`TRMesh request failed: ${response.status}`);
const payload = await response.json();
collected.push(...(payload.data?.items ?? []));
cursor = payload.data?.cursor ?? "";
if (!cursor) break;
}
console.log(collected.length);- Persist only the fields needed by your workflow.
- Normalize empty values before importing into downstream systems.
import csv
import os
import requests
response = requests.get(
"https://api.trmesh.com/openapi/api/v1/instagram/web_app/fetch_user_info_by_username",
headers={"Authorization": f"Bearer {os.environ['TRMESH_API_TOKEN']}"},
params={"username": "instagram"},
timeout=30,
)
response.raise_for_status()
profile = response.json().get("data", {})
with open("sdcenter_profiles.csv", "w", newline="", encoding="utf-8") as file:
writer = csv.DictWriter(file, fieldnames=["username", "nickname", "followers"])
writer.writeheader()
writer.writerow({
"username": profile.get("username", ""),
"nickname": profile.get("nickname", ""),
"followers": profile.get("follower_count", 0),
})- Keep concurrency below the workspace RPS configuration.
- Use retry and backoff for 429, 500 and 502 responses.
const token = process.env.TRMESH_API_TOKEN;
const usernames = ["instagram", "youtube", "tiktok"];
const concurrency = 2;
async function fetchProfile(username) {
const url = new URL("https://api.trmesh.com/openapi/api/v1/instagram/web_app/fetch_user_info_by_username");
url.searchParams.set("username", username);
const response = await fetch(url, {
headers: { Authorization: `Bearer ${token}`, accept: "application/json" },
});
if (response.status === 429) throw new Error("rate limited");
if (!response.ok) throw new Error(`request failed: ${response.status}`);
return response.json();
}
for (let index = 0; index < usernames.length; index += concurrency) {
const batch = usernames.slice(index, index + concurrency);
const results = await Promise.all(batch.map(fetchProfile));
console.log(results.map((item) => item.data?.username));
}HTTP status codes
Start troubleshooting with the status code, then check usage logs, wallet records and error details in the workspace.
Bad Request
The request format is invalid, required parameters are missing, or values do not match the selected route.
Unauthorized
The token is missing, invalid, expired or cannot be matched to an active user.
Payment Required
The account does not have enough free quota or USD balance for this paid request.
Forbidden
The account, email verification state, token permission or route access does not allow the request.
Not Found
The route is not registered, not online, or the requested data does not exist.
Too Many Requests
The request rate exceeded the account's RPS level. Lower concurrency or upgrade the level before retrying.
Server / Data Service Error
The platform or data-service provider is temporarily unavailable. Retry or degrade based on business tolerance.
Frequently asked questions
Common development questions around tokens, balance, rate limits, payments and data responsibility.
What should I do when a request times out?
Reduce the request scope, lower page size and add retry logic. Worker jobs should persist cursor and progress so they do not restart from the beginning.
Why do I get a 402 response?
The selected route is paid and the account does not have enough free quota or USD balance to cover this request.
Why do I get a 403 response?
Common causes include an unverified account, frozen account, insufficient token permission or route access not enabled for the user.
Can I test the API for free?
New users can use trial quota for validation. Whether a specific API accepts trial quota is reflected in the API details and account request result.
How many tokens should I create?
Follow the workspace token limits. For production, split tokens by application or environment so access can be audited and deleted cleanly.
Who is responsible for downstream data use?
TRMesh provides access, orchestration and governance. Users remain responsible for how retrieved data is stored, exported and processed downstream.