jackwener/OpenCLI · error

Failed to list collections: HTTP ' + listRes.status + ' - ma

Error message

Failed to list collections: HTTP ' + listRes.status + ' - make sure you are logged in to Instagram

What it means

Thrown by the `saved` command when the collections list request (GET /api/v1/collections/list/) returns a non-2xx status. Because this Instagram web API requires an authenticated session, the message appends 'make sure you are logged in to Instagram'. It only fires when a --collection argument was supplied, since the collections list is fetched solely to resolve the collection name to an id.

Source

Thrown at clis/instagram/saved.js:25

    domain: 'www.instagram.com',
    args: [
        { name: 'limit', type: 'int', default: 20, help: 'Number of saved posts' },
        { name: 'collection', help: 'Collection name (case-insensitive). Omit for the default "All posts" feed.' },
    ],
    columns: ['index', 'user', 'caption', 'likes', 'comments', 'type'],
    pipeline: [
        { navigate: 'https://www.instagram.com' },
        { evaluate: `(async () => {
  const limit = \${{ args.limit }};
  const collectionArg = \${{ args.collection | json }};
  const headers = { 'X-IG-App-ID': '936619743392459' };
  const opts = { credentials: 'include', headers };

  let endpoint = 'https://www.instagram.com/api/v1/feed/saved/posts/';
  if (collectionArg && String(collectionArg).trim()) {
    const wanted = String(collectionArg).trim().toLowerCase();
    const listRes = await fetch('https://www.instagram.com/api/v1/collections/list/?collection_types=%5B%22MEDIA%22%2C%22ALL_MEDIA_AUTO_COLLECTION%22%5D', opts);
    if (!listRes.ok) throw new Error('Failed to list collections: HTTP ' + listRes.status + ' - make sure you are logged in to Instagram');
    const listData = await listRes.json();
    const collections = listData?.items || [];
    const match = collections.find((c) => String(c?.collection_name || '').trim().toLowerCase() === wanted);
    if (!match) {
      const names = collections.map((c) => c?.collection_name).filter(Boolean);
      throw new Error('Collection not found: ' + collectionArg + '. Available: ' + (names.length ? names.join(', ') : '(none)'));
    }
    endpoint = 'https://www.instagram.com/api/v1/feed/collection/' + encodeURIComponent(match.collection_id) + '/posts/';
  }

  const res = await fetch(endpoint, opts);
  if (!res.ok) throw new Error('HTTP ' + res.status + ' - make sure you are logged in to Instagram');
  const data = await res.json();
  return (data?.items || []).slice(0, limit).map((item, i) => {
    const m = item?.media;
    return {
      index: i + 1,
      user: m?.user?.username || '',

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Log into instagram.com in the browser profile the CLI drives, then re-run the command.
  2. If 429, wait a few minutes and reduce how often you call the command.
  3. If you don't actually need a specific collection, omit --collection to use the default saved-posts feed, which avoids the collections call entirely.
  4. Verify cookies (sessionid/csrftoken) are present and not blocked by proxy/privacy settings.

Example fix

// before (no session)
instagram saved --collection "recipes"  // -> Failed to list collections: HTTP 401...
// after: log into instagram.com in the CLI browser profile, then
instagram saved --collection "recipes"
Defensive patterns

Strategy: fallback

Try / catch

try {
  return await run(['instagram', 'saved', '--collection', name]);
} catch (e) {
  if (String(e.message).includes('Failed to list collections')) {
    await refreshInstagramLogin();
    // fall back to the default saved feed, which skips the collections call
    return run(['instagram', 'saved']);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `instagram saved --collection <name>` while the browser session is expired or absent (401/403), while rate-limited (429), or when Instagram challenges the request (400) — any non-ok response from the collections/list endpoint.

Common situations: Session cookies expired since the last use; running the command from a fresh browser profile that was never logged in; heavy scripted usage triggering 429; corporate proxy stripping cookies causing a 401.

Related errors


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