{"record":{"id":"988d806ebc59cce3","repo":"jackwener/OpenCLI","slug":"linkedin-messaging-api-returned-an-unexpected-resp","errorCode":null,"errorMessage":"LinkedIn messaging API returned an unexpected response: ","messagePattern":"LinkedIn messaging API returned an unexpected response: ","errorType":"error_code","errorClass":"CommandExecutionError","httpStatus":null,"severity":"error","filePath":"clis/linkedin/inbox.js","lineNumber":201,"sourceCode":"    }\n\n    const cookies = await page.getCookies({ url: 'https://www.linkedin.com' });\n    const jsession = cookies.find((c) => c.name === 'JSESSIONID')?.value;\n    if (!jsession) {\n      throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn JSESSIONID cookie not found. Please sign in to LinkedIn.');\n    }\n    const csrf = jsession.replace(/^\"|\"$/g, '');\n\n    // Widen the page size to the requested limit where the query supports it.\n    const targetUrl = located.url.replace(/count:\\d+/, 'count:' + limit);\n    const fetched = unwrapEvaluateResult(\n      await page.evaluate(`(${fetchMessagingApi.toString()})(${JSON.stringify(targetUrl)}, ${JSON.stringify(csrf)})`),\n    );\n    if (fetched && fetched.authRequired) {\n      throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn messaging API authentication failed: ' + fetched.error);\n    }\n    if (!fetched || fetched.error || !fetched.json) {\n      throw new CommandExecutionError(\n        'LinkedIn messaging API returned an unexpected response: ' + ((fetched && fetched.error) || 'no data'),\n      );\n    }\n\n    let conversations = parseConversations(fetched.json, located.mailboxUrn || '');\n    if (unreadOnly) conversations = conversations.filter((c) => c.unread);\n    if (conversations.length === 0) {\n      if (unreadOnly) return [];\n      throw new EmptyResultError('linkedin inbox', 'No LinkedIn conversations were found in the inbox.');\n    }\n\n    return conversations.slice(0, limit).map((c, index) => ({\n      rank: index + 1,\n      thread_url: threadUrl(c.thread_id),\n      thread_id: c.thread_id,\n      person_name: c.person_name,\n      last_message_preview: c.last_message_preview,\n      unread: c.unread,","sourceCodeStart":183,"sourceCodeEnd":219,"githubUrl":"https://github.com/jackwener/OpenCLI/blob/49907e53dc3ade5c223ff0c4c2c2785687cec4e6/clis/linkedin/inbox.js#L183-L219","documentation":"If the messaging API call neither requested auth nor returned usable JSON (fetch failed, non-JSON response, or returned an error field), the CLI throws a CommandExecutionError describing the unexpected response, appending fetched.error or 'no data'. It guards downstream parsers from undefined payloads.","triggerScenarios":"During `linkedin inbox`, unwrapEvaluateResult(page.evaluate(fetchMessagingApi(...))) yields null/undefined, an object with an error property, or no json field — e.g. network failure inside the page, HTTP 5xx, or HTML error page instead of JSON.","commonSituations":"LinkedIn rate limiting with an HTML/JSON error body, transient network drop inside the browser, LinkedIn API returning an unexpected shape after a version change, or the evaluated fetch being blocked by CSP/extensions.","solutions":["Read the appended detail ('no data' vs fetched.error) to distinguish network failure from an API error body.","Retry the command — transient fetch failures are the most common cause.","Verify the account/API works by loading messaging manually in the profile; check for LinkedIn incident/429 responses.","If persistent with a working session, the API response shape likely changed — update the library."],"exampleFix":"// before\nconst convos = await inbox(); // CommandExecutionError: unexpected response\n\n// after\ntry { const convos = await inbox(); }\ncatch (e) {\n  if (e instanceof CommandExecutionError) await sleep(5000), retry();\n  else throw e;\n}","handlingStrategy":"retry","validationCode":"async function apiHealthy() {\n  try {\n    const r = await fetch('https://www.linkedin.com/voyager/api/identity', { headers: { 'csrf-token': csrf } });\n    return r.status !== 502 && r.status !== 503;\n  } catch { return false; }\n}","typeGuard":"const isUnexpectedApiResponse = (e) => e instanceof CommandExecutionError && /unexpected response/i.test(e?.message || '');","tryCatchPattern":"try {\n  return await linkedinInbox();\n} catch (e) {\n  if (isUnexpectedApiResponse(e)) return retry(linkedinInbox, { attempts: 3, backoff: 'exponential' });\n  throw e;\n}","preventionTips":["Treat 'no data' in the message as a transport failure (retry) and an appended error as an API body issue (inspect).","Back off on repeated failures — often LinkedIn throttling or an incident.","Keep the browser profile free of extensions that can block fetch requests.","Update the library when LinkedIn changes the messaging API response envelope."],"tags":["network","api","linkedin","unexpected-response"],"backgroundTag":"unexpected-api-response","analyzedSha":"49907e53dc3ade5c223ff0c4c2c2785687cec4e6","analyzedAt":"2026-08-29T08:14:47.543Z","schemaVersion":2},"datasetVersion":"2026-08-29T12:17:43.993Z"}