{"record":{"id":"1bed804bedb46e62","repo":"jackwener/OpenCLI","slug":"http-res-status-make-sure-you-are-logged-1bed80","errorCode":null,"errorMessage":"HTTP ' + res.status + ' - make sure you are logged in to Instagram","messagePattern":"HTTP ' \\+ res\\.status \\+ ' - make sure you are logged in to Instagram","errorType":"http","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/saved.js","lineNumber":37,"sourceCode":"  const opts = { credentials: 'include', headers };\n\n  let endpoint = 'https://www.instagram.com/api/v1/feed/saved/posts/';\n  if (collectionArg && String(collectionArg).trim()) {\n    const wanted = String(collectionArg).trim().toLowerCase();\n    const listRes = await fetch('https://www.instagram.com/api/v1/collections/list/?collection_types=%5B%22MEDIA%22%2C%22ALL_MEDIA_AUTO_COLLECTION%22%5D', opts);\n    if (!listRes.ok) throw new Error('Failed to list collections: HTTP ' + listRes.status + ' - make sure you are logged in to Instagram');\n    const listData = await listRes.json();\n    const collections = listData?.items || [];\n    const match = collections.find((c) => String(c?.collection_name || '').trim().toLowerCase() === wanted);\n    if (!match) {\n      const names = collections.map((c) => c?.collection_name).filter(Boolean);\n      throw new Error('Collection not found: ' + collectionArg + '. Available: ' + (names.length ? names.join(', ') : '(none)'));\n    }\n    endpoint = 'https://www.instagram.com/api/v1/feed/collection/' + encodeURIComponent(match.collection_id) + '/posts/';\n  }\n\n  const res = await fetch(endpoint, opts);\n  if (!res.ok) throw new Error('HTTP ' + res.status + ' - make sure you are logged in to Instagram');\n  const data = await res.json();\n  return (data?.items || []).slice(0, limit).map((item, i) => {\n    const m = item?.media;\n    return {\n      index: i + 1,\n      user: m?.user?.username || '',\n      caption: (m?.caption?.text || '').replace(/\\\\n/g, ' ').substring(0, 100),\n      likes: m?.like_count ?? 0,\n      comments: m?.comment_count ?? 0,\n      type: m?.media_type === 1 ? 'photo' : m?.media_type === 2 ? 'video' : 'carousel',\n    };\n  });\n})()\n` },\n    ],\n});\n","sourceCodeStart":19,"sourceCodeEnd":54,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/saved.js#L19-L54","documentation":"This error is thrown in clis/instagram/saved.js when the fetch to Instagram's collection-posts API (or saved-posts endpoint) returns a non-OK HTTP status. The CLI uses session credentials, so a failed status almost always means the stored cookie/session is invalid or expired and Instagram rejected the request as unauthenticated.","triggerScenarios":"res.ok is false on `await fetch(endpoint, opts)` where endpoint is the saved-posts URL or 'https://www.instagram.com/api/v1/feed/collection/<id>/posts/'. Any 401/403/429 response triggers it.","commonSituations":"Expired or missing Instagram session cookie, running without being logged in, Instagram rate-limiting or blocking the request, or an invalid collection_id producing a 404.","solutions":["Re-authenticate: log in to Instagram and refresh the session cookie/credentials used by the CLI","Print res.status before throwing to confirm whether it is 401 (login) or 429 (rate limit)","If 429, wait and retry later; reduce request frequency","Verify the collection exists by checking the names listed in the 'Collection not found' error"],"exampleFix":"// before\nconst res = await fetch(endpoint, opts);\nif (!res.ok) throw new Error('HTTP ' + res.status + ' - make sure you are logged in to Instagram');\n// after\nconst res = await fetch(endpoint, opts);\nif (!res.ok) {\n  if (res.status === 429) throw new Error('Rate limited by Instagram (HTTP 429); retry later');\n  throw new Error('HTTP ' + res.status + ' - session invalid, re-run `instagram login`');\n}","handlingStrategy":"try-catch","validationCode":"const cookie = opts.headers?.Cookie || '';\nif (!cookie.includes('sessionid')) throw new Error('No Instagram session cookie; run login first');","typeGuard":"function isOk(res) { return typeof res === 'object' && res !== null && typeof res.status === 'number' && res.status >= 200 && res.status < 300; }","tryCatchPattern":"try {\n  const saved = await getSaved({ limit: 10 });\n} catch (e) {\n  if (/HTTP 40[13]/.test(e.message)) { await login(); /* retry once */ }\n  else if (/HTTP 429/.test(e.message)) { await sleep(60000); }\n  else throw e;\n}","preventionTips":["Refresh the session cookie periodically and before long runs","Log res.status on failure to distinguish auth vs rate-limit","Reduce request frequency to avoid 429s","Validate collection names against the available list before fetching"],"tags":["http","authentication","instagram","session"],"backgroundTag":"http-401-unauthenticated","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}