{"record":{"id":"cd73f38b757e32e6","repo":"jackwener/OpenCLI","slug":"failed-to-follow-http-r2-status","errorCode":null,"errorMessage":"Failed to follow: HTTP ' + r2.status","messagePattern":"Failed to follow: HTTP ' \\+ r2\\.status","errorType":"http","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clis/instagram/follow.js","lineNumber":33,"sourceCode":"        },\n    ],\n    columns: ['status', 'username'],\n    pipeline: [\n        { navigate: 'https://www.instagram.com' },\n        { evaluate: `(async () => {\n  const username = \\${{ args.username | json }};\n  const headers = { 'X-IG-App-ID': '936619743392459' };\n  const opts = { credentials: 'include', headers };\n\n  ${buildResolveInstagramUserIdJs()}\n\n  const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';\n  const r2 = await fetch('https://www.instagram.com/api/v1/friendships/create/' + userId + '/', {\n    method: 'POST',\n    credentials: 'include',\n    headers: { ...headers, 'X-CSRFToken': csrf, 'Content-Type': 'application/x-www-form-urlencoded' },\n  });\n  if (!r2.ok) throw new Error('Failed to follow: HTTP ' + r2.status);\n  let d2;\n  try {\n    d2 = await r2.json();\n  } catch {\n    throw new Error('Instagram follow returned invalid JSON');\n  }\n  if (!d2 || typeof d2 !== 'object' || d2.status !== 'ok' || !d2.friendship_status || typeof d2.friendship_status !== 'object') {\n    throw new Error('Instagram follow returned no success evidence');\n  }\n  const status = d2.friendship_status.following ? 'Following' : d2.friendship_status.outgoing_request ? 'Request sent' : '';\n  if (!status) throw new Error('Instagram follow returned no success evidence');\n  return [{ status, username }];\n})()\n` },\n    ],\n});\n","sourceCodeStart":15,"sourceCodeEnd":50,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/follow.js#L15-L50","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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"],"exampleFix":"// before: csrf silently defaults to ''\nconst csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';\n// after: fail fast with a clear auth message\nconst csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1];\nif (!csrf) throw new Error('Not logged in: csrftoken cookie missing');","handlingStrategy":"validation","validationCode":"// preflight: session + csrf must exist before attempting a write action\nconst pre = await browserPage.evaluate(() => ({\n  session: !!document.cookie.match(/sessionid=/),\n  csrf: !!document.cookie.match(/csrftoken=/),\n}));\nif (!pre.session || !pre.csrf) throw new Error('Instagram session/csrftoken missing - log in first');","typeGuard":null,"tryCatchPattern":"try {\n  await run(['instagram', 'follow', username]);\n} catch (e) {\n  const m = String(e.message).match(/Failed to follow: HTTP (\\d+)/);\n  if (m && (m[1] === '429' || m[1] === '403')) {\n    // likely action-blocked: stop following, wait 24-48h\n  } else throw e;\n}","preventionTips":["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"],"tags":["instagram","http-error","csrf","follow-action","rate-limit"],"backgroundTag":"instagram-api-http-error","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}