jackwener/OpenCLI · error · CommandExecutionError
Pinterest request returned malformed JSON payload
Error message
Pinterest request returned malformed JSON payload
What it means
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.
Source
Thrown at clis/pinterest/utils.js:229
// Reads work anonymously, so their 403 is a rejected request, not a login prompt;
// writes genuinely need login, so treat their 403 as auth too.
if (status === 401 || (WRITE_ACTIONS.has(action) && status === 403)) {
// Pinterest also answers 401 for writes it refuses on a logged-in session (e.g. editing the
// link of a scraped pin), so pass its own message through instead of only saying "log in".
throw new AuthRequiredError(
PINTEREST_DOMAIN,
raw.message
? `Pinterest refused this write: ${raw.message}`
: 'This action requires being logged in to Pinterest in Chrome',
);
}
const hint = status === 403 ? ' (missing or expired CSRF token — reload Pinterest in Chrome)' : '';
// Surface Pinterest's own error text (from resource_response.error.message) when present.
const detail = raw.message ? `: ${raw.message}` : '';
throw new CommandExecutionError(`Pinterest request failed (HTTP ${status})${detail}${hint}`);
}
if (!raw || typeof raw !== 'object' || raw.__malformed) {
throw new CommandExecutionError('Pinterest request returned malformed JSON payload');
}
const resourceResponse = raw.resource_response;
if (!resourceResponse || typeof resourceResponse !== 'object') {
throw new CommandExecutionError('Pinterest request returned malformed API payload');
}
const payload = resourceResponse.data;
const results = Array.isArray(payload)
? payload
: (payload && Array.isArray(payload.results) ? payload.results : []);
return { data: payload, results, bookmark: resourceResponse.bookmark || null };
}
/** POST a /create/ mutation; returns the created resource_response.data. */
export async function pinterestResourceCreate(page, resource, options, sourceUrl) {
const { data } = await pinterestResourceFetch(page, resource, options, sourceUrl, 'create');
return data;
}
View on GitHub (pinned to 49907e53dc)
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
Defensive patterns
Strategy: retry
Validate before calling
null
Type guard
null
Try / catch
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; } Prevention
- 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
When it happens
Trigger: 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.
Common situations: 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.
Understand the failure class
- Parsing and encoding errors: unexpected token, malformed input — why parsers reject input and how to find the real culprit.
Related errors
- Chess.com API returned malformed JSON for ${url}: ${error?.m
- coingecko returned malformed JSON: ${error?.message || error
- ${label} returned malformed JSON: ${err?.message ?? err}
- Gmail ${operation} returned malformed JSON
- ${label} returned malformed JSON: ${err?.message ?? err}
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/9a2cb8cb9fab8407.
Report an issue: GitHub.