jackwener/OpenCLI · error · AuthRequiredError
LinkedIn connections API authentication failed:
Error message
LinkedIn connections API authentication failed:
What it means
The in-page fetchConnections helper calls LinkedIn's Voyager /voyager/api/relationships/connections endpoint with the session CSRF token. When it returns HTTP 401/403 or an HTML login/checkpoint body, it reports authRequired and the command throws AuthRequiredError, appending the underlying error (e.g. 'HTTP 401', 'HTML auth/checkpoint response').
Source
Thrown at clis/linkedin/connections.js:102
],
columns: ['rank', 'name', 'occupation', 'public_id', 'connected_at', 'url'],
func: async (page, kwargs) => {
const limit = parseLimit(kwargs.limit, 20, 500);
await page.goto('https://www.linkedin.com/mynetwork/invite-connect/connections/');
await page.wait(2);
await assertLinkedInAuthenticated(page, 'linkedin connections');
const csrf = await requireLinkedInCookie(page, 'linkedin connections');
const rows = [];
let start = 0;
while (rows.length < limit) {
const remaining = limit - rows.length;
const count = remaining < PAGE_SIZE ? remaining : PAGE_SIZE;
const url = `${CONNECTIONS_PATH}?start=${start}&count=${count}`;
const fetched = unwrapEvaluateResult(
await page.evaluate(`(${fetchConnections.toString()})(${JSON.stringify(url)}, ${JSON.stringify(csrf)})`),
);
if (fetched && fetched.authRequired) {
throw new AuthRequiredError(LINKEDIN_DOMAIN, 'LinkedIn connections API authentication failed: ' + fetched.error);
}
if (!fetched || fetched.error || !fetched.json) {
throw new CommandExecutionError('LinkedIn connections API returned an unexpected response: ' + ((fetched && fetched.error) || 'no data'));
}
const elements = fetched.json.elements;
if (!Array.isArray(elements)) {
throw new CommandExecutionError('LinkedIn connections API returned a malformed payload: missing elements array');
}
if (elements.length === 0) break;
for (const element of elements) {
rows.push(mapConnection(element, rows.length));
if (rows.length >= limit) break;
}
start += elements.length;
if (elements.length < count) break;
}
if (rows.length === 0) {
throw new EmptyResultError('linkedin connections', 'No LinkedIn connections were found.');View on GitHub (pinned to 49907e53dc)
Solutions
- Re-authenticate: re-run the command and sign in when the browser opens, so fresh cookies and csrf token are captured.
- Resolve any LinkedIn security checkpoint in a normal browser, then retry the CLI.
- Clear cached LinkedIn cookies for the CLI and log in again from a residential IP / without VPN.
- Confirm JSESSIONID exists via requireLinkedInCookie — if it is missing, the session was dropped.
Example fix
// before (stale csrf/session) AuthRequiredError: LinkedIn connections API authentication failed: HTTP 401 // after $ opencli linkedin login # refresh session cookies $ opencli linkedin connections --limit 50
Defensive patterns
Strategy: try-catch
Validate before calling
const cookies = await page.context().cookies('https://www.linkedin.com');
const hasSession = cookies.some(c => c.name === 'li_at') && cookies.some(c => c.name === 'JSESSIONID');
if (!hasSession) throw new Error('LinkedIn session cookies (li_at / JSESSIONID) missing — authenticate first.'); Type guard
function isAuthRequired(result) {
return Boolean(result && result.authRequired);
} Try / catch
try {
const rows = await opencli.linkedin.connections({ limit: 50 });
} catch (e) {
if (e.name === 'AuthRequiredError') {
await opencli.linkedin.login(); // interactive re-auth
return opencli.linkedin.connections({ limit: 50 });
}
throw e;
} Prevention
- Refresh LinkedIn cookies before long or scheduled jobs.
- Avoid datacenter IPs / VPNs that trigger LinkedIn authwalls.
- Resolve security checkpoints immediately when LinkedIn flags the account.
- Detect the appended cause ('HTTP 401/403', 'HTML auth/checkpoint response') to confirm session state.
When it happens
Trigger: Running `linkedin connections` with expired/invalidated session cookies, a missing or stale JSESSIONID (csrf) cookie, or LinkedIn answering the API call with a login redirect / challenge page instead of JSON.
Common situations: Cookie jar not refreshed after LinkedIn rotated JSESSIONID; account restricted or rate-limited into a checkpoint; VPN/datacenter IP triggering the authwall; logged out in another tab.
Understand the failure class
- Authentication and authorization failures — expired tokens, bad credentials, and missing scopes.
Related errors
- bbs.hupu.com
- LinkedIn sent-invitations verification requires an active si
- LinkedIn JSESSIONID cookie not found. Please sign in to Link
- LinkedIn JSESSIONID cookie not found. Please sign in to Link
- ${label} authentication failed (HTTP ${result.status || 'aut
AI-assisted analysis of jackwener/OpenCLI@49907e53dc (2026-08-29).
Data as JSON: /api/errors/3ea57dad2cd76ae0.
Report an issue: GitHub.