jackwener/OpenCLI · warning

Post index ' + (idx + 1) + ' not found

Error message

Post index ' + (idx + 1) + ' not found

What it means

The 1-based post index supplied is beyond the number of items Instagram returned in the feed. The script throws with the 1-based index so you can match what you passed. Instagram only returns as many posts as exist (bounded by ?count=).

Source

Thrown at clis/instagram/unsave.js:37

        { navigate: 'https://www.instagram.com' },
        { evaluate: `(async () => {
  const username = \${{ args.username | json }};
  const idx = \${{ args.index }} - 1;
  if (!Number.isInteger(idx) || idx < 0) throw new Error('index must be a positive integer');
  const headers = { 'X-IG-App-ID': '936619743392459' };
  const opts = { credentials: 'include', headers };
  async function readInstagramJson(response, label) {
    try {
      return await response.json();
    } catch {
      throw new Error(label + ' returned invalid JSON');
    }
  }
  function getPostFromFeed(feed, label) {
    if (!feed || typeof feed !== 'object' || !Array.isArray(feed.items)) {
      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');

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Lower --index to a value within the account's post count.
  2. List the user's posts first to find the correct 1-based index.
  3. Confirm the account still has that many posts.

Example fix

// before
npx cli instagram unsave --username someuser --index 12
// after
npx cli instagram user someuser   # list posts to pick a valid index
npx cli instagram unsave --username someuser --index 3
Defensive patterns

Strategy: validation

Validate before calling

const postCount = await getPostCount(username);
if (index > postCount) throw new Error(`index ${index} exceeds ${postCount} posts`);

Try / catch

try {
  await cli.unsave(user, index);
} catch (e) {
  if (e.message.includes('not found')) {
    const posts = await cli.user(user);
    console.log('Valid indices:', posts.map(p => p.index));
  } else throw e;
}

Prevention

When it happens

Trigger: unsave --index 5 when the user has only 3 posts, or the feed returned fewer items than requested (private/restricted visibility).

Common situations: Saved list shrank since the user last checked; guessing an index without listing posts first; account deleted posts.

Related errors


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