jackwener/OpenCLI · error

User not found: ' + username : 'HTTP ' + r1.status + ' - mak

Error message

User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram

What it means

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.

Source

Thrown at clis/instagram/save.js:53

      throw new Error(label + ' returned malformed items payload');
    }
    if (idx >= feed.items.length) throw new Error('Post index ' + (idx + 1) + ' not found');
    const post = feed.items[idx];
    const pkRaw = post?.pk ?? post?.id;
    const pk = typeof pkRaw === 'number' ? String(pkRaw) : (typeof pkRaw === 'string' ? pkRaw.trim() : '');
    if (!/^\\d+$/.test(pk)) throw new Error(label + ' returned malformed post row');
    const caption = typeof post?.caption?.text === 'string' ? post.caption.text.substring(0, 60) : '';
    return { pk, caption };
  }
  function assertOkStatus(payload, label) {
    if (!payload || typeof payload !== 'object' || payload.status !== 'ok') {
      throw new Error(label + ' returned no success evidence');
    }
  }

  // web_profile_info answers HTTP 400 for business accounts; feed-by-username needs no user id. See #2234.
  const r1 = await fetch('https://www.instagram.com/api/v1/feed/user/' + encodeURIComponent(username) + '/username/?count=' + (idx + 1), opts);
  if (!r1.ok) throw new Error(r1.status === 404 ? 'User not found: ' + username : 'HTTP ' + r1.status + ' - make sure you are logged in to Instagram');
  const { pk, caption } = getPostFromFeed(await readInstagramJson(r1, 'Instagram feed-by-username'), 'Instagram feed-by-username');

  const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
  const r2 = await fetch('https://www.instagram.com/api/v1/web/save/' + pk + '/save/', {
    method: 'POST', credentials: 'include',
    headers: { ...headers, 'X-CSRFToken': csrf, 'Content-Type': 'application/x-www-form-urlencoded' },
  });
  if (!r2.ok) throw new Error('Failed to save: HTTP ' + r2.status);
  assertOkStatus(await readInstagramJson(r2, 'Instagram save'), 'Instagram save');
  return [{ status: 'Saved', user: username, post: caption || '(post #' + (idx+1) + ')' }];
})()
` },
    ],
});

View on GitHub (pinned to 49907e53dc)

Solutions

  1. If 404: double-check the username spelling and confirm the account still exists on instagram.com.
  2. If 401/403 or the login hint appears: re-login to Instagram in the browser profile the CLI uses, then retry.
  3. If 429: wait several minutes before retrying; reduce command frequency.
  4. If the account is private, follow it from the logged-in profile so its feed is accessible.

Example fix

// before: expired session
instagram save someuser --index 1  // -> HTTP 403 - make sure you are logged in...
// after: re-authenticate in the CLI browser profile, then
instagram save someuser --index 1
Defensive patterns

Strategy: try-catch

Try / catch

try {
  await run(['instagram', 'save', username, '--index', String(i)]);
} catch (e) {
  const msg = String(e.message);
  if (msg.includes('User not found')) {
    console.error(`Check the username '${username}' — account may be renamed or deleted`);
  } else if (msg.includes('HTTP 4')) {
    await refreshInstagramLogin();
    return retryWithBackoff(() => run(['instagram', 'save', username, '--index', String(i)]), { attempts: 2 });
  }
  throw e;
}

Prevention

When it happens

Trigger: 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).

Common situations: 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).

Related errors


AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29). Data as JSON: /api/errors/e0a40c4322763d16. Report an issue: GitHub.