{"record":{"id":"e0a40c4322763d16","repo":"jackwener/OpenCLI","slug":"user-not-found-username-http-r1-status","errorCode":null,"errorMessage":"User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram","messagePattern":"User not found: ' \\+ username : 'HTTP ' \\+ r1\\.status \\+ ' - make sure you are logged in to Instagram","errorType":"http","errorClass":null,"httpStatus":404,"severity":"error","filePath":"clis/instagram/save.js","lineNumber":53,"sourceCode":"      throw new Error(label + ' returned malformed items payload');\n    }\n    if (idx >= feed.items.length) throw new Error('Post index ' + (idx + 1) + ' not found');\n    const post = feed.items[idx];\n    const pkRaw = post?.pk ?? post?.id;\n    const pk = typeof pkRaw === 'number' ? String(pkRaw) : (typeof pkRaw === 'string' ? pkRaw.trim() : '');\n    if (!/^\\\\d+$/.test(pk)) throw new Error(label + ' returned malformed post row');\n    const caption = typeof post?.caption?.text === 'string' ? post.caption.text.substring(0, 60) : '';\n    return { pk, caption };\n  }\n  function assertOkStatus(payload, label) {\n    if (!payload || typeof payload !== 'object' || payload.status !== 'ok') {\n      throw new Error(label + ' returned no success evidence');\n    }\n  }\n\n  // web_profile_info answers HTTP 400 for business accounts; feed-by-username needs no user id. See #2234.\n  const r1 = await fetch('https://www.instagram.com/api/v1/feed/user/' + encodeURIComponent(username) + '/username/?count=' + (idx + 1), opts);\n  if (!r1.ok) throw new Error(r1.status === 404 ? 'User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram');\n  const { pk, caption } = getPostFromFeed(await readInstagramJson(r1, 'Instagram feed-by-username'), 'Instagram feed-by-username');\n\n  const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';\n  const r2 = await fetch('https://www.instagram.com/api/v1/web/save/' + pk + '/save/', {\n    method: 'POST', 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 save: HTTP ' + r2.status);\n  assertOkStatus(await readInstagramJson(r2, 'Instagram save'), 'Instagram save');\n  return [{ status: 'Saved', user: username, post: caption || '(post #' + (idx+1) + ')' }];\n})()\n` },\n    ],\n});\n","sourceCodeStart":35,"sourceCodeEnd":68,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/save.js#L35-L68","documentation":"Thrown when the feed-by-username request (GET /api/v1/feed/user/<username>/username/) returns a non-2xx status. If the status is 404 the message is 'User not found: <username>'; for any other status it is 'HTTP <status> - make sure you are logged in to Instagram'. Most non-404 failures here are authentication problems, since this private web API requires a logged-in session with valid cookies.","triggerScenarios":"Calling the feed-by-username endpoint with an invalid/typo'd username (404), or with an expired/absent Instagram session (401/403), or while rate-limited or bot-challenged (429/400).","commonSituations":"Username misspelled or the account was renamed/deleted; the CLI browser profile's session expired so Instagram returns 401/403; running many commands quickly triggers 429 rate limiting; the private account does not follow you (restricted feed).","solutions":["If 404: double-check the username spelling and confirm the account still exists on instagram.com.","If 401/403 or the login hint appears: re-login to Instagram in the browser profile the CLI uses, then retry.","If 429: wait several minutes before retrying; reduce command frequency.","If the account is private, follow it from the logged-in profile so its feed is accessible."],"exampleFix":"// before: expired session\ninstagram save someuser --index 1  // -> HTTP 403 - make sure you are logged in...\n// after: re-authenticate in the CLI browser profile, then\ninstagram save someuser --index 1","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  await run(['instagram', 'save', username, '--index', String(i)]);\n} catch (e) {\n  const msg = String(e.message);\n  if (msg.includes('User not found')) {\n    console.error(`Check the username '${username}' — account may be renamed or deleted`);\n  } else if (msg.includes('HTTP 4')) {\n    await refreshInstagramLogin();\n    return retryWithBackoff(() => run(['instagram', 'save', username, '--index', String(i)]), { attempts: 2 });\n  }\n  throw e;\n}","preventionTips":["Validate the username exists on instagram.com before scripting against it.","Keep the CLI browser profile logged in; 401/403 mean the session is stale.","Back off on 429 — space out Instagram commands."],"tags":["network","authentication","http-error","instagram"],"backgroundTag":"http-401-unauthorized","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}