jackwener/OpenCLI · error · Error
Failed to fetch followers: HTTP ' + r2.status
Error message
Failed to fetch followers: HTTP ' + r2.status
What it means
The followers command GETs https://www.instagram.com/api/v1/friendships/<userId>/followers/?count=<limit> with session credentials and the hardcoded X-IG-App-ID header. If the HTTP response status is not ok (4xx/5xx), the CLI throws this error carrying the status code. It means Instagram refused the followers request at the transport/status level before any payload validation.
Source
Thrown at clis/instagram/followers.js:29
{ name: 'limit', type: 'int', default: 20, help: 'Number of followers' },
],
columns: ['rank', 'username', 'name', 'verified', 'private'],
pipeline: [
{ navigate: 'https://www.instagram.com' },
{ evaluate: `(async () => {
const username = \${{ args.username | json }};
const limit = \${{ args.limit }};
if (!Number.isInteger(limit) || limit < 1) throw new Error('limit must be a positive integer');
const headers = { 'X-IG-App-ID': '936619743392459' };
const opts = { credentials: 'include', headers };
${buildResolveInstagramUserIdJs()}
const r2 = await fetch(
'https://www.instagram.com/api/v1/friendships/' + userId + '/followers/?count=' + limit,
opts
);
if (!r2.ok) throw new Error('Failed to fetch followers: HTTP ' + r2.status);
const d2 = await r2.json();
if (!d2 || typeof d2 !== 'object' || !Array.isArray(d2.users)) {
throw new Error('Instagram followers returned malformed users payload');
}
return d2.users.slice(0, limit).map((u, i) => {
if (!u || typeof u !== 'object') {
throw new Error('Instagram followers returned malformed user row');
}
const pkRaw = u.pk ?? u.pk_id ?? u.id;
const pk = typeof pkRaw === 'number' ? String(pkRaw) : (typeof pkRaw === 'string' ? pkRaw.trim() : '');
const usernameValue = typeof u.username === 'string' ? u.username.trim() : '';
if (!/^\\d+$/.test(pk) || !usernameValue) {
throw new Error('Instagram followers returned malformed user row');
}
return {
rank: i + 1,
username: usernameValue,
name: typeof u.full_name === 'string' ? u.full_name : '',View on GitHub (pinned to 49907e53dc)
Solutions
- Log into instagram.com in the browser session to restore cookies (401/403).
- Back off and retry after delays; reduce request rate / limit to avoid 429.
- Verify the target username resolves to the right userId (404 suggests bad id).
- Check whether Instagram changed the required X-IG-App-ID or endpoint and update the hardcoded header.
Example fix
// before
if (!r2.ok) throw new Error('Failed to fetch followers: HTTP ' + r2.status);
// after (caller-side backoff)
try { await listFollowers(user, limit); }
catch (e) {
const m = /HTTP (\d+)/.exec(e.message);
if (m && m[1] === '429') await sleep(60000);
else throw e;
} Defensive patterns
Strategy: retry
Validate before calling
// Pre-flight session check before fetching followers:
const authed = document.cookie.includes('ds_user_id');
if (!authed) throw new Error('Log into instagram.com first (would get HTTP 401/403)'); Try / catch
async function withRetry(fn, tries = 3) {
for (let i = 0; i < tries; i++) {
try { return await fn(); }
catch (e) {
const m = /HTTP (\d+)/.exec(String(e.message));
const code = m && +m[1];
if (code === 429 || code >= 500) { await new Promise(r => setTimeout(r, 2 ** i * 1000)); continue; }
throw e;
}
}
throw new Error('retries exhausted');
} Prevention
- Maintain a valid logged-in session before bulk reads.
- Throttle follower scraping; back off on 429 with exponential delays.
- Validate usernames resolve to userIds before hitting the friendships endpoint.
- Watch for Instagram App-ID/endpoint changes; pin and monitor the hardcoded header.
When it happens
Trigger: 401/403 from missing or expired session cookies; 429 rate limited; 404 when userId resolved incorrectly; 5xx from Instagram side; request blocked by anti-bot challenge.
Common situations: Not logged into instagram.com in the browser session; scraping too many followers rapidly (429); private/deleted account yielding 404/403; IG App-ID header no longer accepted after Instagram frontend update.
Understand the failure class
Background: "API error: {status}" and "HTTP 401/403/404/429/5xx" errors: non-2xx HTTP responses explained — this error's family across 27 libraries.
Related errors
- Failed to fetch following: HTTP ' + r2.status
- archive snapshots failed: HTTP ${resp.status}
- Instagram private publish ${stage} failed: ${response.status
- ${label} failed: HTTP ${response.status}
- HTTP ' + res.status + ' - make sure you are logged in to Ins
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/a2eaad7d932fb3c3.
Report an issue: GitHub.