{"record":{"id":"1bf9a8cdf43be378","repo":"jackwener/OpenCLI","slug":"collection-id-not-found-in-your-account-raw","errorCode":null,"errorMessage":"Collection id not found in your account: ${raw}","messagePattern":"Collection id not found in your account: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/collection-delete.js","lineNumber":49,"sourceCode":"  // Resolve name -> id via /collections/list/. Always go through this path so we can\n  // surface an explicit error on duplicate names or unknown names instead of relying\n  // on a 404.\n  const listRes = await fetch('https://www.instagram.com/api/v1/collections/list/?collection_types=%5B%22MEDIA%22%5D', {\n    credentials: 'include',\n    headers,\n  });\n  if (!listRes.ok) {\n    throw new Error('Failed to list collections: HTTP ' + listRes.status + ' - make sure you are logged in to Instagram');\n  }\n  const listData = await listRes.json();\n  const collections = listData?.items || [];\n  const isNumericId = /^\\\\d{6,}$/.test(raw);\n  let id = '';\n  let resolvedName = '';\n  if (isNumericId) {\n    const hit = collections.find((c) => String(c?.collection_id) === raw);\n    if (!hit) {\n      throw new Error('Collection id not found in your account: ' + raw);\n    }\n    id = String(hit.collection_id);\n    resolvedName = String(hit.collection_name || '');\n  } else {\n    const wanted = raw.toLowerCase();\n    const matches = collections.filter((c) => String(c?.collection_name || '').trim().toLowerCase() === wanted);\n    if (matches.length === 0) {\n      const names = collections.map((c) => c?.collection_name).filter(Boolean);\n      throw new Error('Collection not found: ' + raw + '. Available: ' + (names.length ? names.join(', ') : '(none)'));\n    }\n    if (matches.length > 1) {\n      const ids = matches.map((c) => c.collection_id).join(', ');\n      throw new Error('Multiple collections share the name \"' + raw + '\" (ids: ' + ids + '). Pass the numeric collection_id explicitly to disambiguate.');\n    }\n    id = String(matches[0].collection_id);\n    resolvedName = String(matches[0].collection_name || raw);\n  }\n","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/collection-delete.js#L31-L67","documentation":"Thrown when the target looks like a numeric collection id (6+ digits) but no collection in the /collections/list/ response has that collection_id. The tool validates the id against the account's actual collections instead of letting the delete request fail with an opaque 404.","triggerScenarios":"Passing a collection_id that was deleted already, belongs to a different account, was typo'd, or is not a collection id at all (e.g. a media id) while it matches the /^\\d{6,}$/ heuristic.","commonSituations":"Stale id cached from a previous run; account switched mid-automation; confusing saved-collection ids with post/media ids; duplicates removed upstream.","solutions":["List your current collections and copy the correct numeric collection_id","Confirm you are logged into the same account that owns the collection","Check you didn't paste a media/post id instead of a collection id","Remove stale ids from any cached config or scripts"],"exampleFix":"// before\nnode collection-delete.js --target 17895600000000000 // stale id\n// after\nnode collection-delete.js --target \"My Collection\" // resolve fresh by name","handlingStrategy":"validation","validationCode":"// Pre-validate the id by listing collections first\nconst list = await listCollections();\nif (!list.some((c) => String(c.collection_id) === targetId)) {\n  throw new Error('Unknown collection id: ' + targetId);\n}","typeGuard":"function isKnownCollectionId(id: string, collections: {collection_id: string|number}[]): boolean {\n  return /^\\d{6,}$/.test(id) && collections.some((c) => String(c.collection_id) === id);\n}","tryCatchPattern":"try {\n  await deleteCollection(rawId);\n} catch (e) {\n  if (String(e.message).startsWith('Collection id not found')) {\n    const cols = await listCollections();\n    console.error('Valid ids:', cols.map((c) => c.collection_id).join(', '));\n    return;\n  }\n  throw e;\n}","preventionTips":["Always fetch fresh collection ids rather than caching them","Distinguish collection ids from media/post ids in your tooling","Verify account identity matches the account owning the collection","Delete by freshly listed id in scripts, not hand-copied ids"],"tags":["validation","instagram-api","id-resolution"],"backgroundTag":"entity-not-found","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}