{"record":{"id":"e65be6b7b25cfb3a","repo":"jackwener/OpenCLI","slug":"http-res-status-make-sure-you-are-logged-e65be6","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/search.js","lineNumber":25,"sourceCode":"    domain: 'www.instagram.com',\n    args: [\n        { name: 'query', required: true, positional: true, help: 'Search query' },\n        { name: 'limit', type: 'int', default: 10, help: 'Number of results' },\n    ],\n    columns: ['rank', 'username', 'name', 'verified', 'private', 'url'],\n    pipeline: [\n        { navigate: 'https://www.instagram.com' },\n        { evaluate: `(async () => {\n  const query = \\${{ args.query | json }};\n  const limit = \\${{ args.limit }};\n  const res = await fetch(\n    'https://www.instagram.com/web/search/topsearch/?query=' + encodeURIComponent(query) + '&context=user',\n    {\n      credentials: 'include',\n      headers: { 'X-IG-App-ID': '936619743392459' }\n    }\n  );\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  const users = (data?.users || []).slice(0, limit);\n  return users.map((item, i) => ({\n    rank: i + 1,\n    username: item.user?.username || '',\n    name: item.user?.full_name || '',\n    verified: item.user?.is_verified ? 'Yes' : 'No',\n    private: item.user?.is_private ? 'Yes' : 'No',\n    url: 'https://www.instagram.com/' + (item.user?.username || ''),\n  }));\n})()\n` },\n    ],\n});\n","sourceCodeStart":7,"sourceCodeEnd":40,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/search.js#L7-L40","documentation":"Thrown in clis/instagram/search.js when the topsearch user-lookup request to Instagram returns a non-OK status. The request relies on 'credentials: include' and the X-IG-App-ID header, so failures indicate the browser/session context is not authenticated or Instagram refused the request.","triggerScenarios":"res.ok is false after `fetch('https://www.instagram.com/web/search/topsearch/?query=...&context=user', { credentials: 'include', headers: { 'X-IG-App-ID': '936619743392459' } })` — typically 302-to-login, 401, 403, or 429 responses.","commonSituations":"Session cookie expired or not sent (e.g. running outside the authenticated browser context), Instagram changing the web endpoint or rejecting the hardcoded app ID, or query rate-limiting.","solutions":["Re-authenticate and ensure the fetch runs in a context where Instagram cookies are included (credentials: 'include' with a valid session)","Check res.status: 401/403 means login problem, 429 means slow down","Verify the X-IG-App-ID value is still accepted by Instagram (it rotates occasionally)","Retry with a simpler query to rule out query-specific blocking"],"exampleFix":"// before\nif (!res.ok) throw new Error('HTTP ' + res.status + ' - make sure you are logged in to Instagram');\n// after\nif (!res.ok) {\n  const body = await res.text().catch(() => '');\n  throw new Error(`Instagram search failed: HTTP ${res.status} ${body.slice(0, 200)}`);\n}","handlingStrategy":"try-catch","validationCode":"if (!query || !query.trim()) throw new Error('Search query is required');\n// ensure fetch runs inside an authenticated page context with cookies","typeGuard":"function hasUsers(data) { return Array.isArray(data?.users) && data.users.length > 0; }","tryCatchPattern":"try {\n  const results = await searchUsers(query, limit);\n} catch (e) {\n  if (/HTTP 40[13]/.test(e.message)) throw new Error('Re-login required: ' + e.message);\n  if (/HTTP 429/.test(e.message)) throw new Error('Rate limited; retry later');\n  throw e;\n}","preventionTips":["Always run searches within the authenticated browser context","Back off on repeated searches to avoid rate limits","Verify the session works with a cheap authenticated call before batch operations","Handle empty user lists gracefully (valid query, zero results)"],"tags":["http","authentication","instagram","search"],"backgroundTag":"http-401-unauthenticated","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}