{"record":{"id":"9a2cb8cb9fab8407","repo":"jackwener/OpenCLI","slug":"pinterest-request-returned-malformed-json-payload","errorCode":null,"errorMessage":"Pinterest request returned malformed JSON payload","messagePattern":"Pinterest request returned malformed JSON payload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pinterest/utils.js","lineNumber":229,"sourceCode":"    // Reads work anonymously, so their 403 is a rejected request, not a login prompt;\n    // writes genuinely need login, so treat their 403 as auth too.\n    if (status === 401 || (WRITE_ACTIONS.has(action) && status === 403)) {\n      // Pinterest also answers 401 for writes it refuses on a logged-in session (e.g. editing the\n      // link of a scraped pin), so pass its own message through instead of only saying \"log in\".\n      throw new AuthRequiredError(\n        PINTEREST_DOMAIN,\n        raw.message\n          ? `Pinterest refused this write: ${raw.message}`\n          : 'This action requires being logged in to Pinterest in Chrome',\n      );\n    }\n    const hint = status === 403 ? ' (missing or expired CSRF token — reload Pinterest in Chrome)' : '';\n    // Surface Pinterest's own error text (from resource_response.error.message) when present.\n    const detail = raw.message ? `: ${raw.message}` : '';\n    throw new CommandExecutionError(`Pinterest request failed (HTTP ${status})${detail}${hint}`);\n  }\n  if (!raw || typeof raw !== 'object' || raw.__malformed) {\n    throw new CommandExecutionError('Pinterest request returned malformed JSON payload');\n  }\n  const resourceResponse = raw.resource_response;\n  if (!resourceResponse || typeof resourceResponse !== 'object') {\n    throw new CommandExecutionError('Pinterest request returned malformed API payload');\n  }\n  const payload = resourceResponse.data;\n  const results = Array.isArray(payload)\n    ? payload\n    : (payload && Array.isArray(payload.results) ? payload.results : []);\n  return { data: payload, results, bookmark: resourceResponse.bookmark || null };\n}\n\n/** POST a /create/ mutation; returns the created resource_response.data. */\nexport async function pinterestResourceCreate(page, resource, options, sourceUrl) {\n  const { data } = await pinterestResourceFetch(page, resource, options, sourceUrl, 'create');\n  return data;\n}\n","sourceCodeStart":211,"sourceCodeEnd":247,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pinterest/utils.js#L211-L247","documentation":"The response from the injected in-page fetch was not a usable JSON object (empty, non-object, or flagged __malformed by the script's JSON parse). The library cannot even inspect status codes, so it throws CommandExecutionError about a malformed JSON payload.","triggerScenarios":"page.evaluate returned undefined/null because the script crashed before returning; the fetch returned HTML (login page, captcha, consent wall) instead of JSON so JSON.parse failed; response body truncated.","commonSituations":"Pinterest serving a login redirect or bot-detection page; an extension injecting HTML into the response; the Chrome tab was closed mid-evaluate; Pinterest A/B pages that don't expose the resource API the same way.","solutions":["Reload pinterest.com in Chrome (ensuring you're logged in, no captcha wall) and retry","Disable extensions that rewrite page content or block scripts","Check whether Pinterest is showing a captcha or consent page in Chrome and complete it","Retry — transient HTML error pages usually resolve"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { const pins = await cmd.boardPins(b); } catch (e) { if (/malformed JSON payload/.test(e.message)) { console.error('Reload pinterest.com in Chrome (check for captcha/login wall) and retry.'); } else throw e; }","preventionTips":["Ensure the Pinterest tab shows the normal logged-in page, not a captcha or consent wall","Disable content-injecting browser extensions","Keep the tab open during the call","Retry transient failures before investigating deeper"],"tags":["json","malformed-response","pinterest","chrome"],"backgroundTag":"malformed-json-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}