{"record":{"id":"8dd372c63f04b243","repo":"jackwener/OpenCLI","slug":"multiple-collections-share-the-name-raw-ids","errorCode":null,"errorMessage":"Multiple collections share the name \"${raw}\" (ids: ${ids}). Pass the numeric collection_id explicitly to disambiguate.","messagePattern":"Multiple collections share the name \"(.+?)\" \\(ids: (.+?)\\)\\. Pass the numeric collection_id explicitly to disambiguate\\.","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"clis/instagram/collection-delete.js","lineNumber":62,"sourceCode":"  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\n  const fd = new FormData();\n  fd.append('module_name', 'collection_settings');\n  const res = await fetch('https://www.instagram.com/api/v1/collections/' + encodeURIComponent(id) + '/delete/', {\n    method: 'POST',\n    credentials: 'include',\n    headers: { ...headers, 'X-CSRFToken': csrf },\n    body: fd,\n  });\n  if (!res.ok) {\n    const body = await res.text().catch(() => '');\n    throw new Error('Failed to delete collection: HTTP ' + res.status + (body ? ' - ' + body.slice(0, 200) : ''));\n  }\n  const d = await res.json().catch(() => ({}));","sourceCodeStart":44,"sourceCodeEnd":80,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/collection-delete.js#L44-L80","documentation":"Thrown when more than one collection in the account has the same name (case-insensitive match). Name-based deletion would be ambiguous, so the tool refuses and asks for the numeric collection_id. This protects against deleting the wrong duplicate.","triggerScenarios":"Instagram allows duplicate collection names; calling delete by name when two or more collections share that exact trimmed/lowercased name.","commonSituations":"Users creating same-named collections over time (e.g. 'Travel' twice); automation accidentally creating duplicates previously; syncing across devices duplicating collections.","solutions":["Re-run passing the numeric collection_id of the specific collection to delete (ids are listed in the error)","List collections to map ids to creation dates and pick the right one","Rename duplicates in the Instagram UI to unique names for future name-based operations","Dedupe collections before running name-based deletes"],"exampleFix":"// before\nnode collection-delete.js --target \"Travel\" // ambiguous\n// after\nnode collection-delete.js --target 17895600000000001 // explicit id from error message","handlingStrategy":"validation","validationCode":"const list = await listCollections();\nconst matches = list.filter((c) => c.collection_name.trim().toLowerCase() === name.toLowerCase());\nif (matches.length > 1) {\n  throw new Error('Ambiguous name; pass one of ids: ' + matches.map((m) => m.collection_id).join(', '));\n}","typeGuard":"function isUnambiguousName(name: string, collections: {collection_name: string}[]): boolean {\n  const w = name.trim().toLowerCase();\n  return collections.filter((c) => c.collection_name.trim().toLowerCase() === w).length === 1;\n}","tryCatchPattern":"try {\n  await deleteCollection(name);\n} catch (e) {\n  if (String(e.message).startsWith('Multiple collections share the name')) {\n    console.error(e.message); // contains candidate ids\n    return; // require explicit id from operator\n  }\n  throw e;\n}","preventionTips":["Use numeric collection_id for all automated deletes","Keep collection names unique in the account","Dedupe same-named collections before running batch deletes","Parse candidate ids out of the error message when it does fire"],"tags":["ambiguity","id-resolution","instagram-api"],"backgroundTag":"ambiguous-identifier","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}