jackwener/OpenCLI · error

Collection not found: ' + collectionArg + '. Available: ' +

Error message

Collection not found: ' + collectionArg + '. Available: ' + (names.length ? names.join(', ') : '(none)')

What it means

Thrown when the collections list succeeded but no collection's `collection_name` matches the requested --collection value (case-insensitive, trimmed). The error includes the list of available collection names, or '(none)' when the account has no named collections. Note the auto-collection 'All posts' is a special feed and may not appear as a named collection here.

Source

Thrown at clis/instagram/saved.js:31

    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 || '',
      caption: (m?.caption?.text || '').replace(/\\n/g, ' ').substring(0, 100),
      likes: m?.like_count ?? 0,
      comments: m?.comment_count ?? 0,
      type: m?.media_type === 1 ? 'photo' : m?.media_type === 2 ? 'video' : 'carousel',
    };
  });

View on GitHub (pinned to 49907e53dc)

Solutions

  1. Use one of the exact names printed in the error's 'Available:' list.
  2. Omit --collection entirely to read the default saved-posts feed instead of a named collection.
  3. Check the collection name in the Instagram app (Saved -> collection) — copy it exactly, matching is case-insensitive but otherwise literal.
  4. If the collection should exist but the list is '(none)' or stale, re-login/reload instagram.com so the collections endpoint returns fresh data.

Example fix

// before
instagram saved --collection "Recepies"
// after (using the actual name)
instagram saved --collection "Recipes"
Defensive patterns

Strategy: validation

Validate before calling

const available = await listCollectionNames(); // via /api/v1/collections/list/
const wanted = String(args.collection).trim().toLowerCase();
if (!available.some(n => String(n).trim().toLowerCase() === wanted)) {
  throw new Error(`Unknown collection '${args.collection}'. Available: ${available.join(', ') || '(none)'}`);
}

Try / catch

try {
  return await run(['instagram', 'saved', '--collection', name]);
} catch (e) {
  if (String(e.message).includes('Collection not found')) {
    // message lists available names — parse them and prompt/retry with a corrected name
    const available = String(e.message).split('Available:')[1]?.trim() || '(none)';
    console.error(`Pick a collection from: ${available}`);
  }
  throw e;
}

Prevention

When it happens

Trigger: Running `instagram saved --collection <name>` where the name does not exactly (case-insensitively) match any collection_name returned by /api/v1/collections/list/ — typos, stale collection names after a rename/deletion, or requesting 'All posts' which is not a named collection.

Common situations: Typo or extra whitespace/emoji differences in the collection name; the collection was renamed or deleted on another device; expecting the default 'All posts' pseudo-collection to be listed; Instagram truncating the collections list response.

Understand the failure class

Background: 'Could not be found', 'does not exist', 'not found in database': the resource-not-found family when an ID, slug, key, or URI lookup comes back empty — this error's family across 20 libraries.

Related errors


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