Accounts
Manage your connected LinkedIn accounts programmatically. See the Admin overview for initialization.
Get all accounts
typescript
try {
const { accounts, pendingConnectionSessions } = await admin.accounts.getAll();
for (const account of accounts) {
console.log(`${account.name} (${account.status}) – ${account.id}`);
}
for (const session of pendingConnectionSessions) {
console.log(`Pending session: ${session.sessionId} (${session.status})`);
}
} catch (e) {
if (e instanceof LinkedApiError) {
console.error(`Critical Error - Type: ${e.type}, Message: ${e.message}`);
} else {
console.error('An unexpected, non-API error occurred:', e);
}
}Data
accounts– array of connected accounts, each containing:id– account UUID.name– LinkedIn account name.countryCode– country code selected during connection.identificationToken– token used in theidentification-tokenheader for Account API calls.status–active,frozen, orreconnection_required.connectedAt– ISO 8601 timestamp.
pendingConnectionSessions– array of pending sessions, each containingsessionIdandstatus.
Connect a new account
Connecting a LinkedIn account is a multi-step process:
typescript
// 1. Create a connection session
const { sessionId, connectionLink } = await admin.accounts.createConnectionSession();
console.log('Open this link to connect:', connectionLink);
// 2. Poll until the session completes
const POLL_INTERVAL_MS = 3000;
const MAX_WAIT_MS = 2 * 60 * 1000;
const deadline = Date.now() + MAX_WAIT_MS;
const sleep = (ms: number) => new Promise((resolve) => setTimeout(resolve, ms));
let session;
do {
if (Date.now() >= deadline) {
throw new Error('Timed out waiting for connection session completion');
}
await sleep(POLL_INTERVAL_MS);
session = await admin.accounts.getConnectionSession({ sessionId });
} while (session.session.status === 'pending' ||
session.session.status === 'preparing' ||
session.session.status === 'serving' ||
session.session.status === 'streaming');
if (session.session.status === 'success') {
console.log('Account connected successfully!');
// 3. Get the new account details
const { accounts } = await admin.accounts.getAll();
console.log('Total accounts:', accounts.length);
}createConnectionSession data
sessionId– session UUID for tracking.connectionLink– URL to open in a browser to complete the LinkedIn login.
createConnectionSession errors
noAvailableSeats– no available seats. All seats are occupied by active accounts or pending connection sessions.dailyConnectionAttemptsExceeded– too many connection attempts in the last 24 hours.
getConnectionSession params
sessionId– session UUID.
Session statuses
| Status | Description |
|---|---|
pending | Session created, waiting for user to open the link |
preparing | Browser is being provisioned |
serving | Browser is ready, waiting for user to connect |
streaming | User is connected and logging in |
success | Login completed, account is being created |
expired | Session timed out |
error | An error occurred |
cancelled | Session was cancelled |
Cancel connection session
typescript
await admin.accounts.cancelConnectionSession({ sessionId: '990eef7a-...' });Params
sessionId– session UUID.
Disconnect account
typescript
await admin.accounts.disconnect({ accountId: 'f9b4346a-...' });Params
accountId– UUID of the account to disconnect.
Warning: This action is irreversible. The account must be reconnected from scratch.
Regenerate identification token
typescript
const { token } = await admin.accounts.regenerateIdentificationToken({
accountId: 'f9b4346a-...',
});
console.log('New token:', token);Params
accountId– UUID of the account.
Data
token– the new identification token.
Important: Update the
identificationTokenin all your SDK instances immediately after regeneration.
Errors
All account methods may throw:
linkedApiTokenRequired– missing token.invalidLinkedApiToken– invalid or expired token.accountNotFound– account does not exist or does not belong to you.tooManyRequests– rate limit exceeded.
For the complete HTTP API reference, see Admin API: Accounts.