{"record":{"id":"b5ed4d6ca6703148","repo":"jackwener/OpenCLI","slug":"pinterest-request-returned-malformed-api-payload","errorCode":null,"errorMessage":"Pinterest request returned malformed API payload","messagePattern":"Pinterest request returned malformed API payload","errorType":"exception","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/pinterest/utils.js","lineNumber":233,"sourceCode":"      // 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\n/** POST an /update/ mutation; returns the updated resource_response.data. */\nexport async function pinterestResourceUpdate(page, resource, options, sourceUrl) {\n  const { data } = await pinterestResourceFetch(page, resource, options, sourceUrl, 'update');\n  return data;","sourceCodeStart":215,"sourceCodeEnd":251,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/pinterest/utils.js#L215-L251","documentation":"The raw response parsed as JSON but lacks the expected resource_response object that Pinterest's resource API normally returns. The library throws CommandExecutionError because it cannot extract data/results/bookmark without it.","triggerScenarios":"Pinterest changed or degraded the resource API response shape; the endpoint returned an error envelope without resource_response; a captcha/bot-detection JSON body instead of the normal envelope.","commonSituations":"Pinterest frontend API changes breaking scrapers; response intercepted by bot mitigation; requesting a resource that no longer exists with a changed response shape.","solutions":["Update the CLI/library in case Pinterest changed the response shape (check for newer version)","Log the raw response in Chrome DevTools Network tab for /resource/ calls and compare shape","Retry later — sometimes Pinterest returns degraded envelopes under load","Ensure no bot-detection wall is active (complete any captcha in Chrome)"],"exampleFix":null,"handlingStrategy":"fallback","validationCode":"null","typeGuard":"null","tryCatchPattern":"try { const r = await cmd.board(t); } catch (e) { if (/malformed API payload/.test(e.message)) { console.error('Pinterest response shape changed or degraded — update the CLI or retry later.'); } throw e; }","preventionTips":["Keep the CLI/library updated for Pinterest API shape changes","Watch for bot-detection walls and complete captchas in Chrome","Log unexpected payloads for debugging","Retry later when Pinterest returns degraded envelopes"],"tags":["api-contract","response-shape","pinterest"],"backgroundTag":"unexpected-response-shape","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}