jackwener/OpenCLI · error
Failed to list collections: HTTP ${listRes.status} - make su
Error message
Failed to list collections: HTTP ${listRes.status} - make sure you are logged in to Instagram What it means
Thrown when the GET to /api/v1/collections/list/ used to resolve the target to an id returns non-2xx. The message appends the HTTP status and hints at login problems because the most common cause is an unauthenticated session (401/403). This check runs before any name/id matching.
Source
Thrown at clis/instagram/collection-delete.js:39
if (!target || !String(target).trim()) {
throw new Error('Collection target (name or id) cannot be empty');
}
const raw = String(target).trim();
const csrf = document.cookie.match(/csrftoken=([^;]+)/)?.[1] || '';
if (!csrf) {
throw new Error('csrftoken cookie missing - make sure you are logged in to Instagram');
}
const headers = { 'X-IG-App-ID': '936619743392459' };
// Resolve name -> id via /collections/list/. Always go through this path so we can
// surface an explicit error on duplicate names or unknown names instead of relying
// on a 404.
const listRes = await fetch('https://www.instagram.com/api/v1/collections/list/?collection_types=%5B%22MEDIA%22%5D', {
credentials: 'include',
headers,
});
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 isNumericId = /^\\d{6,}$/.test(raw);
let id = '';
let resolvedName = '';
if (isNumericId) {
const hit = collections.find((c) => String(c?.collection_id) === raw);
if (!hit) {
throw new Error('Collection id not found in your account: ' + raw);
}
id = String(hit.collection_id);
resolvedName = String(hit.collection_name || '');
} else {
const wanted = raw.toLowerCase();
const matches = collections.filter((c) => String(c?.collection_name || '').trim().toLowerCase() === wanted);
if (matches.length === 0) {
const names = collections.map((c) => c?.collection_name).filter(Boolean);View on GitHub (pinned to 49907e53dc)
Solutions
- Log in again to refresh the session cookies
- Wait before retrying if status is 429
- Check the status code: 401/403 -> auth issue, 429 -> rate limit, 404 -> API change
- Verify the request includes credentials: 'include' and the X-IG-App-ID header
Example fix
// before
throw new Error('Failed to list collections: HTTP ' + listRes.status + ...);
// after
if (listRes.status === 429) { await sleep(60000); return deleteCollection(target); }
throw new Error('Failed to list collections: HTTP ' + listRes.status + ...); Defensive patterns
Strategy: retry
Validate before calling
const authed = await page.evaluate(() => document.cookie.includes('csrftoken='));
if (!authed) throw new Error('Login required before deleting collections'); Type guard
function isAuthedContext(cookies: string): boolean {
return /(?:^|;\s*)csrftoken=[^;]+/.test(cookies);
} Try / catch
try {
await deleteCollection(target);
} catch (e) {
const m = String(e.message).match(/HTTP (\d+)/);
if (m && m[1] === '429') { await sleep(60000); return deleteCollection(target); }
if (m && (m[1] === '401' || m[1] === '403')) { await relogin(); return deleteCollection(target); }
throw e;
} Prevention
- Refresh sessions before batch delete operations
- Add delays between list/delete calls to avoid rate limits
- Map status codes to actions: 401/403 re-login, 429 backoff, 404 API change
- Watch for Instagram private-API endpoint changes
When it happens
Trigger: Expired or invalid session cookies, missing/invalid X-IG-App-ID acceptance, 429 rate limiting on the list endpoint, or Instagram changing the collections/list API, all while resolving the delete target.
Common situations: Session expired between login and delete; heavy automation triggering rate limits; Instagram removing/altering the private list endpoint.
Understand the failure class
Background: 'Something went wrong' / 'Request failed (500)' / 'HTTP error! status: 404' — what failed HTTP requests actually mean and how to find the real cause — this error's family across 28 libraries.
Related errors
- ${label} returned HTTP ${resp.status}: ${summarizeApiError(p
- Failed to create collection: HTTP ${res.status}${body ? ' -
- Failed to delete collection: HTTP ${res.status}${body ? ' -
- 12306 queryByTrainNo returned HTTP ${resp.status}
- 12306 queryByTrainNo returned non-JSON body
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/4073051930d94398.
Report an issue: GitHub.