jackwener/OpenCLI · error
Post index not found
Error message
Post index not found
What it means
Thrown by `getPostFromFeed` when `idx` (the 0-based requested post position) is greater than or equal to `feed.items.length`, i.e. the user's feed returned fewer posts than the requested position. The command requests `count=<idx+1>` posts, but Instagram may return fewer (private account, deleted posts, partial feeds), leaving no item at the requested index.
Source
Thrown at clis/instagram/save.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
- Lower the --index value to a position within the number of posts the profile actually shows.
- Verify on instagram.com how many posts the account visibly has and pick an index within that range.
- If you need an older post beyond the feed window, open the post on the web and save it manually, or paginate the feed first.
Example fix
// before: account only has 12 visible posts instagram save someuser --index 40 // after instagram save someuser --index 5
Defensive patterns
Strategy: validation
Validate before calling
const visiblePosts = countVisiblePostsOnProfile(username); // e.g. from profile page
if (Number(args.index) > visiblePosts) {
throw new Error(`--index ${args.index} exceeds the ${visiblePosts} visible posts for ${username}`);
} Try / catch
try {
await run(['instagram', 'save', username, '--index', String(i)]);
} catch (e) {
if (String(e.message).includes('not found')) {
console.error(`Post #${i} does not exist; the feed returned fewer posts. Lower --index.`);
}
throw e;
} Prevention
- Check the profile's visible post count before using a large --index.
- Prefer small indexes (recent posts); old posts may fall outside the feed window.
- Remember deleted/archived/restricted posts shrink the accessible feed.
When it happens
Trigger: Running `instagram save <username> --index N` where the user's visible feed has fewer than N posts: index 25 on an account with 10 posts, or an index beyond what the feed endpoint returned despite the count parameter.
Common situations: Targeting an account with very few posts; some posts are deleted/archived or hidden (e.g. restricted content) so the feed is shorter than the profile post count; a large index (e.g. 50+) where Instagram caps or truncates the feed response.
Related errors
- Instagram private publish only supports single-video uploads
- ${label}
- Collection name cannot be empty
- index must be a positive integer
- ${label} returned malformed items payload
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/5e586eccf131e571.
Report an issue: GitHub.