{"record":{"id":"12fab3fa7117b5ed","repo":"jackwener/OpenCLI","slug":"instagram-private-route-could-not-derive-x-instagr","errorCode":null,"errorMessage":"Instagram private route could not derive X-Instagram-AJAX from instagram runtime","messagePattern":"Instagram private route could not derive X-Instagram-AJAX from instagram runtime","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/instagram/_shared/private-publish.js","lineNumber":116,"sourceCode":"                page.evaluate(buildReadInstagramRuntimeInfoJs()),\n                typeof page.readNetworkCapture === 'function'\n                    ? page.readNetworkCapture()\n                    : Promise.resolve([]),\n            ]);\n            const captureEntries = (Array.isArray(entries) ? entries : []);\n            const capturedContext = derivePrivateApiContextFromCapture(captureEntries)\n                ?? derivePartialPrivateApiContextFromCapture(captureEntries);\n            const csrfToken = runtime?.csrfToken || getCookieValue(cookies, 'csrftoken') || capturedContext.csrfToken || '';\n            const igAppId = runtime?.appId || capturedContext.igAppId || '';\n            const instagramAjax = runtime?.instagramAjax || capturedContext.instagramAjax || '';\n            if (!csrfToken) {\n                throw new CommandExecutionError('Instagram private route could not derive CSRF token from browser session');\n            }\n            if (!igAppId) {\n                throw new CommandExecutionError('Instagram private route could not derive X-IG-App-ID from instagram runtime');\n            }\n            if (!instagramAjax) {\n                throw new CommandExecutionError('Instagram private route could not derive X-Instagram-AJAX from instagram runtime');\n            }\n            const asbdId = capturedContext.asbdId || '';\n            const igWwwClaim = capturedContext.igWwwClaim || '';\n            const webSessionId = capturedContext.webSessionId || '';\n            return {\n                apiContext: {\n                    asbdId,\n                    csrfToken,\n                    igAppId,\n                    igWwwClaim,\n                    instagramAjax,\n                    webSessionId,\n                },\n                jazoest: deriveInstagramJazoest(csrfToken),\n            };\n        }\n        catch (error) {\n            lastError = error;","sourceCodeStart":98,"sourceCodeEnd":134,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/instagram/_shared/private-publish.js#L98-L134","documentation":"The private API route must send the X-Instagram-AJAX header (the rolling request-version value). It comes from the instagram runtime instagramAjax field or captured context; when both are empty this error is thrown before any request is made.","triggerScenarios":"resolveInstagramPrivatePublishConfig finds csrfToken and appId but no instagramAjax value in runtime or capture entries.","commonSituations":"Runtime config built manually without instagramAjax, private call issued before the browser session captured any instagram.com request headers.","solutions":["Let the CLI capture headers by loading an instagram.com page in the automation browser first","Provide instagramAjax explicitly in the instagram runtime config","Re-login / hard reload to refresh session-captured values","Use the UI route instead, which does not require manually derived headers"],"exampleFix":"// before\nruntime = { csrfToken, appId: '936619743392459' };\n// after\nruntime = { csrfToken, appId: '936619743392459', instagramAjax: '1029384756%3A%3A...' };","handlingStrategy":"validation","validationCode":"if (!runtime.instagramAjax) {\n  await page.goto('https://www.instagram.com/'); // triggers header capture\n}","typeGuard":"function hasInstagramAjax(rt) {\n  return typeof rt?.instagramAjax === 'string' && rt.instagramAjax.length > 0;\n}","tryCatchPattern":"try {\n  await publishPrivate(cfg);\n} catch (e) {\n  if (/could not derive X-Instagram-AJAX/.test(e.message)) {\n    await page.goto('https://www.instagram.com/'); // recapture then retry\n  } else throw e;\n}","preventionTips":["Capture headers by loading instagram.com before private-route calls","Provide instagramAjax explicitly in runtime config for headless setups","Avoid clearing browser context between capture and publish"],"tags":["instagram","headers","configuration","private-api"],"backgroundTag":"missing-required-header","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}