jackwener/OpenCLI · error · Error
Failed to follow: HTTP ' + r2.status
Error message
Failed to follow: HTTP ' + r2.status
What it means
The instagram follow command's in-page script POSTs to friendships/create/<userId>/ with the session's CSRF token; if the response is not ok it throws 'Failed to follow: HTTP <status>'. This indicates Instagram rejected the follow request at the HTTP level — auth, CSRF mismatch, rate limiting, or a blocked/disallowed action.
Source
Thrown at clis/instagram/follow.js:33
},
],
columns: ['status', 'username'],
pipeline: [
{ navigate: 'https://www.instagram.com' },
{ evaluate: `(async () => {
const username = \${{ args.username | json }};
const headers = { 'X-IG-App-ID': '936619743392459' };
const opts = { credentials: 'include', headers };
${buildResolveInstagramUserIdJs()}
const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
const r2 = await fetch('https://www.instagram.com/api/v1/friendships/create/' + userId + '/', {
method: 'POST',
credentials: 'include',
headers: { ...headers, 'X-CSRFToken': csrf, 'Content-Type': 'application/x-www-form-urlencoded' },
});
if (!r2.ok) throw new Error('Failed to follow: HTTP ' + r2.status);
let d2;
try {
d2 = await r2.json();
} catch {
throw new Error('Instagram follow returned invalid JSON');
}
if (!d2 || typeof d2 !== 'object' || d2.status !== 'ok' || !d2.friendship_status || typeof d2.friendship_status !== 'object') {
throw new Error('Instagram follow returned no success evidence');
}
const status = d2.friendship_status.following ? 'Following' : d2.friendship_status.outgoing_request ? 'Request sent' : '';
if (!status) throw new Error('Instagram follow returned no success evidence');
return [{ status, username }];
})()
` },
],
});
View on GitHub (pinned to 49907e53dc)
Solutions
- Ensure the session is logged in and the csrftoken cookie exists (the script reads it from document.cookie)
- If 429/403 'action blocked', wait 24-48h and reduce follow frequency
- Retry with a valid, existing username; verify the resolved userId is correct
- Use a warmed, regular-use account rather than a fresh one
Example fix
// before: csrf silently defaults to ''
const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
// after: fail fast with a clear auth message
const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1];
if (!csrf) throw new Error('Not logged in: csrftoken cookie missing'); Defensive patterns
Strategy: validation
Validate before calling
// preflight: session + csrf must exist before attempting a write action
const pre = await browserPage.evaluate(() => ({
session: !!document.cookie.match(/sessionid=/),
csrf: !!document.cookie.match(/csrftoken=/),
}));
if (!pre.session || !pre.csrf) throw new Error('Instagram session/csrftoken missing - log in first'); Try / catch
try {
await run(['instagram', 'follow', username]);
} catch (e) {
const m = String(e.message).match(/Failed to follow: HTTP (\d+)/);
if (m && (m[1] === '429' || m[1] === '403')) {
// likely action-blocked: stop following, wait 24-48h
} else throw e;
} Prevention
- Verify the session is logged in and csrftoken exists before write actions
- Keep follow rates low; bulk following quickly triggers action blocks
- Use a warmed, regularly-used account for write operations
- Confirm the username resolves to an existing user before following
When it happens
Trigger: The POST to https://www.instagram.com/api/v1/friendships/create/<userId>/ returns non-2xx — 403 when csrftoken cookie is missing/empty (regex found no csrftoken), 401 for a dead session, 429 for too many follow actions, 400 for invalid userId or already-blocked action.
Common situations: Automated bulk following triggering Instagram's action blocks (429/403 'action blocked'); missing csrftoken because the session never visited a page setting it; targeting a user id that no longer resolves; writing access from a session flagged for automation.
Related errors
- ${label} failed: HTTP ${response.status}
- HTTP ${result.httpStatus} from Instagram /users/info
- HTTP ' + res.status + ' - make sure you are logged in to Ins
- Failed to save: HTTP ' + r2.status
- Failed to unsave: HTTP ' + r2.status
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/cd73f38b757e32e6.
Report an issue: GitHub.