### Install Unipile Node.js SDK Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Install the Unipile Node.js SDK using npm. Ensure your Node.js version is 18 or higher. ```bash npm install unipile-node-sdk ``` -------------------------------- ### Delete Account Example Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/account-resource.md Example demonstrating how to delete an account by providing its ID. ```typescript await client.account.delete('t5XY4yQzR9WVrlNFyzPMhw'); console.log('Account deleted'); ``` -------------------------------- ### Handle Code Checkpoint Example Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/account-resource.md Example demonstrating how to handle verification codes for account connection or reconnection. Catches UnsuccessfulRequestError for invalid codes. ```typescript try { await client.account.solveCodeCheckpoint({ account_id: 'account_123', provider: 'LINKEDIN', code: '123456', }); } catch (err) { if (err instanceof UnsuccessfulRequestError) { console.log('Invalid code:', err.body); } } ``` -------------------------------- ### Create Hosted Auth Link Example Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/account-resource.md Example demonstrating the creation of a hosted authentication link for connecting new accounts. Specifies link type, expiration, API URL, and allowed providers. ```typescript const link = await client.account.createHostedAuthLink({ type: 'create', expiresOn: '2024-12-31T23:59:59Z', api_url: 'https://api.example.com', providers: ['LINKEDIN', 'WHATSAPP'], success_redirect_url: 'https://example.com/success', }); console.log('Share this link:', link.link_url); ``` -------------------------------- ### Full Webhook Usage Example Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/webhook-resource.md Demonstrates a complete workflow: creating a webhook, setting up an Express.js endpoint to handle incoming events, retrieving all webhooks, and finally deleting a webhook. This example illustrates both client-side and server-side webhook integration. ```typescript // Create a webhook for message events const webhook = await client.webhook.create({ url: 'https://api.example.com/webhooks/messages', events: ['message.received'], }); // Your webhook endpoint should process incoming requests // Example Express.js handler: app.post('/webhooks/messages', (req, res) => { const event = req.body; console.log('Event type:', event.type); console.log('Event data:', event.data); // Process the event if (event.type === 'message.received') { handleIncomingMessage(event.data); } res.json({ success: true }); }); // Later, retrieve all webhooks const webhooks = await client.webhook.getAll(); console.log('Total webhooks:', webhooks.data.length); // Delete a webhook when no longer needed await client.webhook.delete(webhook.id); ``` -------------------------------- ### Basic UnipileClient Initialization Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/configuration.md Instantiate the UnipileClient with the base URL and API token. This is the most basic setup. ```typescript import { UnipileClient } from 'unipile-node-sdk'; const client = new UnipileClient( 'https://api.unipile.com', 'your-access-token' ); ``` -------------------------------- ### GET /webhooks Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of all configured webhooks. ```APIDOC ## GET /webhooks ### Description Retrieves a list of all configured webhooks. ### Method GET ### Endpoint /api/v1/webhooks ### Response #### Success Response (200) List of webhooks ``` -------------------------------- ### Start a New Chat with LinkedIn Recruiter Options Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/messaging-resource.md Starts a new chat with specific options for LinkedIn Recruiter, including signature, hiring project ID, and email address. Requires provider-specific options. ```typescript const chat = await client.messaging.startNewChat({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', attendees_ids: ['user_provider_id'], text: 'Message from recruiter', options: { linkedin: { api: 'recruiter', signature: 'Your Name', hiring_project_id: 'project_123', email_address: 'email@example.com', }, }, }); ``` -------------------------------- ### Start New Chat Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/README.md Start a new chat with specified attendees and an initial text message. Requires the account ID and attendee IDs. ```javascript await client.messaging.startNewChat({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', attendees_ids: ['user id OR provider id'], text: 'new chat with message', }); ``` -------------------------------- ### Default Client Configuration Object Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/configuration.md An example of the default configuration object used for the Unipile client, specifying API version and validation settings. ```json { "apiVersion": "v1", "logRequestResult": false, "logRequestPayload": false, "validateRequestPayload": true, "validateRequestPayloadLevel": "error" } ``` -------------------------------- ### Retrieve All Webhooks Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/unipile-client.md Get a list of all configured webhooks using the `webhook` property. ```typescript client.webhook.getAll() ``` -------------------------------- ### Start a New Chat with LinkedIn InMail Options Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/messaging-resource.md Starts a new chat specifically for sending a LinkedIn InMail using the classic API. Requires provider-specific options. ```typescript const chat = await client.messaging.startNewChat({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', attendees_ids: ['user_provider_id'], text: 'send an inmail', options: { linkedin: { api: 'classic', inmail: true, }, }, }); ``` -------------------------------- ### Send Raw Data Request in JavaScript Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/README.md This example shows how to send a raw HTTP request using the Unipile SDK for endpoints not directly packaged within the SDK. It's useful for interacting with external APIs or specific Unipile functionalities not exposed through standard methods. ```javascript const client = new UnipileClient(BASE_URL, "ACCESS_TOKEN", {}); await client.request.send({ path: ["linkedin"], method: "POST", parameters: { account_id: "!!YOURACCOUNTID!!" }, body: { "body": {"patch":{"$set":{"following":true}}}, "account_id": "dfR-rG0tQfGhfeP2l5_Bdw", "method": "POST", "request_url": "https://www.linkedin.com/voyager/api/feed/dash/followingStates/urn:li:fsd_followingState:urn:li:fsd_profile:ACoAAAcDMMQBODyLwZrRcgYhrkCafURGqva0U4E", "encoding": false }, }); ``` -------------------------------- ### Get Own Profile Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves the profile details for the currently authenticated user. ```APIDOC ## GET /users/me ### Description Retrieves the profile details for the currently authenticated user. ### Method GET ### Endpoint /api/v1/users/me ### Parameters #### Query Parameters - **account_id** (string) - Required - Account ID ### Response #### Success Response (200) Authenticated user's profile ``` -------------------------------- ### GET /folders Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of all email folders. Can be filtered by account. ```APIDOC ## GET /folders ### Description Retrieves a list of all email folders. Can be filtered by account. ### Method GET ### Endpoint /api/v1/folders ### Parameters #### Query Parameters - **account_id** (string) - Optional - Filter by account ### Response #### Success Response (200) List of email folders ``` -------------------------------- ### Get All Relations Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of relations or connections for a given account, with pagination options. ```APIDOC ## GET /users/relations ### Description Retrieves a list of relations or connections for a given account. ### Method GET ### Endpoint /api/v1/users/relations ### Parameters #### Query Parameters - **account_id** (string) - Required - Account ID - **limit** (number) - Optional - Maximum relations - **cursor** (string) - Optional - Pagination cursor ### Response #### Success Response (200) List of relations/connections ``` -------------------------------- ### Get All Relations Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of relations or connections for a given account. Supports limiting the number of results and pagination. ```javascript UsersResource.getAllRelations(input) ``` -------------------------------- ### Get Own Profile Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves the profile details for the currently authenticated user. Requires the account ID. ```javascript UsersResource.getOwnProfile(account_id) ``` -------------------------------- ### Start a New Chat Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/messaging-resource.md Initiates a new chat conversation with an initial message. Requires account ID, recipient IDs, and message text. Supports optional subject and attachments. ```typescript const chat = await client.messaging.startNewChat({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', attendees_ids: ['user_id_123'], text: 'new chat with message', }); console.log('Chat created:', chat.chat_id); ``` -------------------------------- ### List Sent LinkedIn Invitations in JavaScript Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/README.md This code example shows how to retrieve a list of all pending LinkedIn invitations sent by the user using the Unipile SDK. It requires the account ID. ```javascript await client.users.getAllInvitationsSent({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', }); ``` -------------------------------- ### UnipileClient Initialization and Basic Usage Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Demonstrates how to initialize the UnipileClient and perform basic operations like connecting an account, sending a message, retrieving a profile, and sending an email. ```APIDOC ## UnipileClient Initialization and Basic Usage ### Description This section shows how to initialize the `UnipileClient` and provides examples for common operations across different resources. ### Initialization ```typescript import { UnipileClient } from 'unipile-node-sdk'; // Initialize client const client = new UnipileClient( 'https://api.unipile.com', 'your-access-token' ); ``` ### Account Connection Connect a LinkedIn account. ```typescript // Connect LinkedIn account const account = await client.account.connectLinkedin({ username: 'your-email@example.com', password: 'your-password', }); ``` ### Messaging Send a message through the messaging resource. ```typescript // Send a message await client.messaging.sendMessage({ chat_id: 'vISKyHtDUmagrk6vrnlXhw', text: 'Hello World', }); ``` ### User Profile Retrieve user profile information. ```typescript // Get profile information const profile = await client.users.getProfile({ account_id: account.account_id, identifier: 'user_provider_id', }); ``` ### Email Sending Send an email using the email resource. ```typescript // Send email await client.email.send({ account_id: account.account_id, to: [{ identifier: 'recipient@example.com' }], subject: 'Hello', body: 'Welcome!', }); ``` ``` -------------------------------- ### Chat & Messaging Endpoints Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Endpoints for retrieving and managing chats, including listing, getting details, starting new chats, and updating chat status. ```APIDOC ## GET /chats ### Description Retrieves a list of chats, with options for filtering and pagination. ### Method GET ### Endpoint /api/v1/chats ### Query Parameters #### Query Parameters - **account_id** (string) - Optional - Filter by account. - **account_type** (string) - Optional - Filter by provider (LINKEDIN, WHATSAPP, etc.). - **limit** (number) - Optional - Maximum chats to return. - **cursor** (string) - Optional - Pagination cursor. - **before** (string) - Optional - Filter before timestamp. - **after** (string) - Optional - Filter after timestamp. - **unread** (boolean) - Optional - Filter unread chats. ### Response #### Success Response (200) List of chats with pagination ``` ```APIDOC ## GET /chats/{chat_id} ### Description Retrieves details for a specific chat. ### Method GET ### Endpoint /api/v1/chats/{chat_id} ### Response #### Success Response (200) Single chat details ``` ```APIDOC ## POST /chats ### Description Starts a new chat conversation. ### Method POST ### Endpoint /api/v1/chats ### Request Body FormData with account_id, text, attendees_ids, optional attachments ### Response #### Success Response (200) Created chat details with chat_id ``` ```APIDOC ## PATCH /chats/{chat_id} ### Description Updates the status of a chat, such as marking it as read or unread. ### Method PATCH ### Endpoint /api/v1/chats/{chat_id} ### Request Body - **action** (string) - Required - The action to perform, e.g., "setReadStatus". - **value** (boolean) - Required - The value for the action, e.g., true to mark as read. ### Response #### Success Response (200) Updated chat details ``` -------------------------------- ### Get Sent Invitations Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of invitations that have been sent from a specific account. Supports limiting results and pagination. ```javascript UsersResource.getAllInvitationsSent(input) ``` -------------------------------- ### GET /posts/{post_id} Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Fetches the details of a specific post using its ID. Requires an account ID for context. ```APIDOC ## GET /posts/{post_id} ### Description Fetches the details of a specific post using its ID. Requires an account ID for context. ### Method GET ### Endpoint /api/v1/posts/{post_id} ### Parameters #### Query Parameters - **account_id** (string) - Required - Account ID ### Response #### Success Response (200) Single post details ``` -------------------------------- ### Get All Sent Invitations Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/users-resource.md List all pending connection invitations sent from an account. Supports pagination with limit and cursor parameters. ```typescript const sentInvitations = await client.users.getAllInvitationsSent({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', }); sentInvitations.data.forEach(inv => { console.log('Sent to:', inv.recipient_id); }); ``` -------------------------------- ### Get All Relations Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/users-resource.md Retrieve all contacts or connections for a given account ID. Supports pagination with limit and cursor parameters. ```typescript const relations = await client.users.getAllRelations({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', limit: 50, }); relations.data.forEach(relation => { console.log(relation.name); }); ``` -------------------------------- ### Get All Chats with Pagination Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Fetch all chats using pagination. Use the 'cursor' parameter to retrieve subsequent pages of results. ```typescript const chats = await client.messaging.getAllChats({ limit: 20, cursor: 'next-cursor-value', }); // Use cursor for next page const nextChats = await client.messaging.getAllChats({ cursor: chats.paging.cursors.next, }); ``` -------------------------------- ### Initialize Unipile Client and Perform Basic Operations Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Demonstrates initializing the UnipileClient, connecting a LinkedIn account, sending a message, retrieving user profile information, and sending an email. Requires an API endpoint and access token. ```typescript import { UnipileClient } from 'unipile-node-sdk'; // Initialize client const client = new UnipileClient( 'https://api.unipile.com', 'your-access-token' ); // Connect LinkedIn account const account = await client.account.connectLinkedin({ username: 'your-email@example.com', password: 'your-password', }); // Send a message await client.messaging.sendMessage({ chat_id: 'vISKyHtDUmagrk6vrnlXhw', text: 'Hello World', }); // Get profile information const profile = await client.users.getProfile({ account_id: account.account_id, identifier: 'user_provider_id', }); // Send email await client.email.send({ account_id: account.account_id, to: [{ identifier: 'recipient@example.com' }], subject: 'Hello', body: 'Welcome!', }); ``` -------------------------------- ### Load Credentials using dotenv Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/configuration.md Load environment variables from a .env file using the dotenv library and then initialize the UnipileClient. This simplifies local development credential management. ```typescript import dotenv from 'dotenv'; dotenv.config(); const client = new UnipileClient( process.env.UNIPILE_BASE_URL, process.env.UNIPILE_API_TOKEN ); ``` -------------------------------- ### Initialize Client for Development Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Configure the client for development with logging and payload validation enabled. ```typescript const client = new UnipileClient(baseUrl, token, { apiVersion: 'v2', logRequestResult: true, logRequestPayload: true, validateRequestPayload: true, validateRequestPayloadLevel: 'error', }); ``` -------------------------------- ### Get Attendee Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves details for a specific attendee. ```APIDOC ## GET /chat_attendees/{attendee_id} ### Description Retrieves details for a specific attendee. ### Method GET ### Endpoint /api/v1/chat_attendees/{attendee_id} ### Response #### Success Response (200) Single attendee details ``` -------------------------------- ### SDK Main Entry Point Import Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/types.md Imports common client and input types from the main SDK entry point. ```typescript import { // Client types SupportedProvider, MessagingProvider, ApiVersion, // Input types GetAllChatsInput, PostMessageInput, GetProfileInput, SendEmailInput, RequestOptions, // Configuration ClientInstantiationOptions, } from 'unipile-node-sdk'; ``` -------------------------------- ### UnipileClient Initialization to Use API v2 Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/configuration.md Configure the client to use the 'v2' version of the Unipile API. ```typescript const client = new UnipileClient( 'https://api.unipile.com', 'your-access-token', { apiVersion: 'v2', } ); ``` -------------------------------- ### Get All Attendees From Chat Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of attendees for a specific chat. ```APIDOC ## GET /chats/{chat_id}/attendees ### Description Retrieves a list of attendees for a specific chat. ### Method GET ### Endpoint /api/v1/chats/{chat_id}/attendees ### Response #### Success Response (200) List of attendees in chat ``` -------------------------------- ### Get All Attendees Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of all attendees, with options for filtering and pagination. ```APIDOC ## GET /chat_attendees ### Description Retrieves a list of all attendees. ### Method GET ### Endpoint /api/v1/chat_attendees ### Parameters #### Query Parameters - **account_id** (string) - Optional - Filter by account - **limit** (number) - Optional - Maximum attendees - **cursor** (string) - Optional - Pagination cursor ### Response #### Success Response (200) List of attendees ``` -------------------------------- ### UnipileClient Initialization with Logging Enabled Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/configuration.md Configure the client to log request results and payloads to the console. Useful for debugging. ```typescript const client = new UnipileClient( 'https://api.unipile.com', 'your-access-token', { logRequestResult: true, logRequestPayload: true, } ); ``` -------------------------------- ### Initialize Unipile Client Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/README.md Initialize the UnipileClient with your DSN and Access Token. This client is used to interact with Unipile APIs. ```javascript import { UnipileClient } from 'unipile-node-sdk'; const client = new UnipileClient('https://{YOUR_DSN}', '{YOUR_ACCESS_TOKEN}'); ``` -------------------------------- ### GET /emails/{email_id} Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Fetches the details of a single email using its ID. ```APIDOC ## GET /emails/{email_id} ### Description Fetches the details of a single email using its ID. ### Method GET ### Endpoint /api/v1/emails/{email_id} ### Response #### Success Response (200) Single email details ``` -------------------------------- ### UnipileClient Constructor Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/unipile-client.md Initializes a new instance of the UnipileClient. This client is used to interact with the Unipile API. ```APIDOC ## new UnipileClient(baseUrl: string, token: string, options?: ClientInstantiationOptions) ### Description Initializes a new UnipileClient instance to interact with the Unipile API. ### Parameters #### Path Parameters - **baseUrl** (string) - Required - The base URL of the Unipile API (e.g., `https://api.unipile.com`) - **token** (string) - Required - API access token for authentication - **options** (ClientInstantiationOptions) - Optional - Optional configuration settings for the client #### Query Parameters None #### Request Body None ### Options Available client configuration options (all optional): - **apiVersion** (string) - Optional - API version to use. Defaults to 'v1'. Can be 'v1' or 'v2'. - **logRequestResult** (boolean) - Optional - Whether to log request results. Defaults to `false`. - **logRequestPayload** (boolean) - Optional - Whether to log request payloads. Defaults to `false`. - **validateRequestPayload** (boolean) - Optional - Whether to validate request payloads. Defaults to `true`. - **validateRequestPayloadLevel** (string) - Optional - Validation error level. Defaults to 'error'. Can be 'warn' or 'error'. ### Throws - `InvalidBaseUrlError` - If the baseUrl is invalid or malformed - `InvalidProtocolError` - If the baseUrl uses an unsupported protocol - `InvalidDomainError` - If the baseUrl contains an invalid domain - `InvalidTokenError` - If the token is invalid ### Usage Example ```typescript import { UnipileClient } from 'unipile-node-sdk'; const client = new UnipileClient( 'https://api.unipile.com', 'your-access-token', { apiVersion: 'v2', logRequestResult: true, validateRequestPayload: true, } ); ``` ``` -------------------------------- ### Get All Sent Invitations Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of invitations that have been sent, with pagination options. ```APIDOC ## GET /users/invite/sent ### Description Retrieves a list of invitations that have been sent. ### Method GET ### Endpoint /api/v1/users/invite/sent ### Parameters #### Query Parameters - **account_id** (string) - Required - Account ID - **limit** (number) - Optional - Maximum invitations - **cursor** (string) - Optional - Pagination cursor ### Response #### Success Response (200) List of sent invitations ``` -------------------------------- ### Initiate WhatsApp Connection Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/account-resource.md Initiates a WhatsApp connection by generating a QR code. The returned object contains the QR code string and the new account ID. ```typescript const result = await client.account.connectWhatsapp(); console.log('Scan this QR code:', result.qrCodeString); console.log('Account ID:', result.account_id); ``` -------------------------------- ### Get Message Attachment Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a binary file attachment for a specific message. ```APIDOC ## GET /messages/{message_id}/attachments/{attachment_id} ### Description Retrieves a binary file attachment for a specific message. ### Method GET ### Endpoint /api/v1/messages/{message_id}/attachments/{attachment_id} ### Response #### Success Response (200) Binary file (Blob) ``` -------------------------------- ### Get All Attendees from Chat Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of attendees associated with a specific chat. ```javascript MessagingResource.getAllAttendeesFromChat(chat_id) ``` -------------------------------- ### Initialize Client for Production Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Configure the client for production with logging disabled and payload validation enabled. ```typescript const client = new UnipileClient(baseUrl, token, { apiVersion: 'v2', logRequestResult: false, logRequestPayload: false, validateRequestPayload: true, validateRequestPayloadLevel: 'error', }); ``` -------------------------------- ### UnipileClient Initialization with Validation as Warning Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/configuration.md Set up the client to validate request payloads but treat validation failures as warnings instead of errors. ```typescript const client = new UnipileClient( 'https://api.unipile.com', 'your-access-token', { validateRequestPayload: true, validateRequestPayloadLevel: 'warn', } ); ``` -------------------------------- ### startNewChat Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/messaging-resource.md Creates a new chat and sends an initial message. Supports various provider-specific options for platforms like LinkedIn. ```APIDOC ## startNewChat ### Description Create a new chat and send an initial message. ### Method POST (assumed, based on creation action) ### Endpoint /messaging/chats ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body - **input.account_id** (string) - Yes - The account ID to send from - **input.text** (string) - Yes - Initial message text - **input.attendees_ids** (string[]) - Yes - Array of recipient user IDs or provider IDs - **input.subject** (string) - No - Chat subject (if supported by provider) - **input.attachments** (Array<[string, Buffer]>) - No - File attachments - **input.options** (PostNewChatInputOptions) - No - Provider-specific options - **options** (RequestOptions) - No - Request options ### Request Example ```json { "account_id": "t5XY4yQzR9WVrlNFyzPMhw", "attendees_ids": ["user_id_123"], "text": "new chat with message" } ``` ### Response #### Success Response (200) - **chat_id** (string) - The ID of the newly created chat #### Response Example ```json { "chat_id": "new_chat_id_123" } ``` ``` -------------------------------- ### GET /folders/{folder_id} Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Fetches the details of a single email folder using its ID. ```APIDOC ## GET /folders/{folder_id} ### Description Fetches the details of a single email folder using its ID. ### Method GET ### Endpoint /api/v1/folders/{folder_id} ### Response #### Success Response (200) Single folder details ``` -------------------------------- ### Initialize Client with API Version Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Specify the API version during client initialization to use a specific version of the Unipile API. ```typescript const client = new UnipileClient(baseUrl, token, { apiVersion: 'v2', }); ``` -------------------------------- ### Production Client Configuration Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/configuration.md Recommended client configuration for production environments, emphasizing security and validation. ```typescript const client = new UnipileClient( process.env.UNIPILE_BASE_URL, process.env.UNIPILE_API_TOKEN, { apiVersion: 'v2', // Use latest API version logRequestResult: false, // Avoid logging sensitive data logRequestPayload: false, validateRequestPayload: true, // Always validate validateRequestPayloadLevel: 'error', // Fail on invalid input } ); ``` -------------------------------- ### Get Attendee Details Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves the details for a specific attendee using their attendee ID. ```javascript MessagingResource.getAttendee(attendee_id) ``` -------------------------------- ### Load Credentials from Environment Variables Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/configuration.md Retrieve the Unipile API base URL and token from environment variables. This is a recommended practice for secure credential management. ```typescript // Load from environment variables const baseUrl = process.env.UNIPILE_BASE_URL; const token = process.env.UNIPILE_API_TOKEN; const client = new UnipileClient(baseUrl, token); ``` -------------------------------- ### Get All Attendees Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of all attendees. Supports filtering by account ID and pagination. ```javascript MessagingResource.getAllAttendees(input) ``` -------------------------------- ### Get Chat by ID Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/messaging-resource.md Retrieves details for a specific chat using its unique identifier. ```typescript const chat = await client.messaging.getChat('vISKyHtDUmagrk6vrnlXhw'); console.log('Chat:', chat.subject, 'Attendees:', chat.attendees_ids.length); ``` -------------------------------- ### Create a Webhook Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Use this endpoint to create a new webhook subscription. Provide the URL to receive events and a list of events to subscribe to. ```json { "url": "string", "events": ["string"] } ``` -------------------------------- ### Get All Chats From Attendee Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves all chats associated with a specific attendee, with filtering and pagination options. ```APIDOC ## GET /chat_attendees/{attendee_id}/chats ### Description Retrieves all chats associated with a specific attendee. ### Method GET ### Endpoint /api/v1/chat_attendees/{attendee_id}/chats ### Parameters #### Query Parameters - **account_id** (string) - Optional - Filter by account - **limit** (number) - Optional - Maximum chats - **cursor** (string) - Optional - Pagination cursor - **before** (string) - Optional - Filter before timestamp - **after** (string) - Optional - Filter after timestamp ### Response #### Success Response (200) Chats with attendee ``` -------------------------------- ### Get All Messages From Attendee Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves messages sent by a specific attendee, with filtering and pagination options. ```APIDOC ## GET /chat_attendees/{attendee_id}/messages ### Description Retrieves messages sent by a specific attendee. ### Method GET ### Endpoint /api/v1/chat_attendees/{attendee_id}/messages ### Parameters #### Query Parameters - **limit** (number) - Optional - Maximum messages - **cursor** (string) - Optional - Pagination cursor - **before** (string) - Optional - Filter before timestamp - **after** (string) - Optional - Filter after timestamp ### Response #### Success Response (200) Messages from attendee ``` -------------------------------- ### Initiate Telegram Connection Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/account-resource.md Initiates a Telegram connection by generating a QR code. The returned object contains the QR code string and the new account ID. ```typescript const result = await client.account.connectTelegram(); console.log('Scan this QR code:', result.qrCodeString); console.log('Account ID:', result.account_id); ``` -------------------------------- ### Connect Whatsapp Account Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/README.md Initiate the connection process for a Whatsapp account. This method may require further steps depending on the API. ```javascript await client.account.connectWhatsapp(); ``` -------------------------------- ### Get All Messages From Chat Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves a list of messages from a specific chat, with options for filtering and pagination. ```APIDOC ## GET /chats/{chat_id}/messages ### Description Retrieves a list of messages from a specific chat. ### Method GET ### Endpoint /api/v1/chats/{chat_id}/messages ### Parameters #### Query Parameters - **sender_id** (string) - Optional - Filter by sender - **limit** (number) - Optional - Maximum messages - **cursor** (string) - Optional - Pagination cursor - **before** (string) - Optional - Filter before timestamp - **after** (string) - Optional - Filter after timestamp ### Response #### Success Response (200) List of messages in chat ``` -------------------------------- ### Define GetAllPostsInput Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/types.md Parameters for listing user or company posts, with options for filtering by account, identifier, and pagination. ```typescript type GetAllPostsInput = { account_id: string; identifier: string; limit?: number; is_company?: boolean; cursor?: string; }; ``` -------------------------------- ### connectWhatsapp Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/account-resource.md Initiates the connection process for a WhatsApp account by providing QR code data. Users can scan this QR code to link their account. ```APIDOC ## connectWhatsapp ### Description Initiate WhatsApp connection via QR code. ### Method POST (assumed based on 'connect' operation) ### Endpoint /accounts/whatsapp/connect ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```typescript const result = await client.account.connectWhatsapp(); console.log('Scan this QR code:', result.qrCodeString); console.log('Account ID:', result.account_id); ``` ### Response #### Success Response (200) - **qrCodeString** (string) - QR code as SVG string - **code** (string) - Raw QR code data - **account_id** (string) - ID of the newly created account #### Response Example { "qrCodeString": "...", "code": "RAW_QR_DATA", "account_id": "t5XY4yQzR9WVrlNFyzPMhw" } ``` -------------------------------- ### getAll Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/account-resource.md Lists all connected accounts with optional pagination support. Useful for retrieving a collection of accounts with control over the number of results and pagination. ```APIDOC ## getAll ### Description Lists all connected accounts with optional pagination. ### Method GET (assumed based on 'list' operation) ### Endpoint /accounts ### Parameters #### Query Parameters - **limit** (number) - Optional - Maximum number of accounts to return - **cursor** (string) - Optional - Cursor for pagination #### Request Body None ### Request Example ```typescript const accounts = await client.account.getAll({ limit: 10 }); accounts.data.forEach(account => { console.log(account.id, account.provider); }); ``` ### Response #### Success Response (200) - **data** (array) - List of connected accounts - **data[].id** (string) - The unique identifier for the account - **data[].provider** (string) - The messaging or email platform provider #### Response Example { "data": [ { "id": "t5XY4yQzR9WVrlNFyzPMhw", "provider": "linkedin" } ] } ``` -------------------------------- ### GET /emails/{email_id}/attachments/{attachment_id} Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Downloads a specific attachment from an email. Returns binary data. ```APIDOC ## GET /emails/{email_id}/attachments/{attachment_id} ### Description Downloads a specific attachment from an email. Returns binary data. ### Method GET ### Endpoint /api/v1/emails/{email_id}/attachments/{attachment_id} ### Response #### Success Response (200) Binary file (Blob) ``` -------------------------------- ### Extra parameters Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/README.md How to pass extra parameters to SDK methods. ```APIDOC ## Extra parameters If you want to pass some extra parameters for a request beyond what the SDK input defines, all methods allow an `extra_params` options. ```javascript await client.messaging.getMessageAttachment( { attachment_id: '5882031366722404334', message_id: '3aRdnf34UiympaebB4-NRA', }, { extra_params: { my_param_name: 'my param value' }, }, ); ``` Depending on the underlying HTTP request mode used, `extra_params` will be added to the request query string or json or formData body. This may be useful if you know about and want to use a parameter that is either omitted or not yet defined in the sdk. ``` -------------------------------- ### GET /linkedin/company/{identifier} Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves the LinkedIn company profile for a given identifier. Requires an account ID. ```APIDOC ## GET /linkedin/company/{identifier} ### Description Retrieves the LinkedIn company profile for a given identifier. Requires an account ID. ### Method GET ### Endpoint /api/v1/linkedin/company/{identifier} ### Parameters #### Query Parameters - **account_id** (string) - Required - Account ID ### Response #### Success Response (200) Company profile details ``` -------------------------------- ### API URL Structure Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md The SDK constructs API URLs based on a defined pattern including protocol, domain, API version, resource path, and query parameters. ```text {protocol}://{domain}/api/{apiVersion}{path}?{parameters} ``` -------------------------------- ### GET /posts/{post_id}/comments Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves comments for a specific post. Supports pagination and filtering by account. ```APIDOC ## GET /posts/{post_id}/comments ### Description Retrieves comments for a specific post. Supports pagination and filtering by account. ### Method GET ### Endpoint /api/v1/posts/{post_id}/comments ### Parameters #### Query Parameters - **account_id** (string) - Required - Account ID - **limit** (number) - Optional - Maximum comments - **cursor** (string) - Optional - Pagination cursor ### Response #### Success Response (200) List of comments ``` -------------------------------- ### Get All Attendees from a Chat Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/messaging-resource.md Retrieves a list of all attendees participating in a specified chat. Requires the chat ID. ```typescript const attendees = await client.messaging.getAllAttendeesFromChat('vISKyHtDUmagrk6vrnlXhw'); attendees.data.forEach(attendee => { console.log(attendee.display_name, attendee.provider_id); }); ``` -------------------------------- ### Create a Webhook Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/unipile-client.md Register a new webhook using the `webhook` property. Requires the `url` for notifications and a list of `events` to subscribe to. ```typescript client.webhook.create({ url: '...', events: [...] }) ``` -------------------------------- ### Message Endpoints Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Endpoints for retrieving messages, including listing all messages and getting details for a specific message. ```APIDOC ## GET /messages ### Description Retrieves a list of messages, with options for filtering and pagination. ### Method GET ### Endpoint /api/v1/messages ### Query Parameters #### Query Parameters - **account_id** (string) - Optional - Filter by account. - **sender_id** (string) - Optional - Filter by sender. - **limit** (number) - Optional - Maximum messages. - **cursor** (string) - Optional - Pagination cursor. - **before** (string) - Optional - Filter before timestamp. - **after** (string) - Optional - Filter after timestamp. ### Response #### Success Response (200) List of messages ``` ```APIDOC ## GET /messages/{message_id} ### Description Retrieves details for a specific message. ### Method GET ### Endpoint /api/v1/messages/{message_id} ### Response #### Success Response (200) Single message details ``` -------------------------------- ### Get Own Profile Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/users-resource.md Retrieve the authenticated account owner's profile details using the account ID. ```typescript const ownProfile = await client.users.getOwnProfile('t5XY4yQzR9WVrlNFyzPMhw'); console.log('My name:', ownProfile.name); console.log('My headline:', ownProfile.headline); ``` -------------------------------- ### Handle Unipile SDK Errors Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Illustrates how to handle specific Unipile SDK errors, such as UnsuccessfulRequestError and InvalidInputTypeError, using a try-catch block. This pattern is useful for debugging and graceful error management. ```typescript import { UnsuccessfulRequestError, InvalidInputTypeError, } from 'unipile-node-sdk'; try { await client.messaging.sendMessage({ ... }); } catch (err) { if (err instanceof UnsuccessfulRequestError) { console.log('API Error:', err.body.status); } else if (err instanceof InvalidInputTypeError) { console.log('Invalid input:', err.body); } } ``` -------------------------------- ### Get All Chats with Extra Parameters Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Pass additional parameters not defined in the SDK by using the 'extra_params' option. ```typescript const result = await client.messaging.getAllChats( { account_id: 'acc_123' }, { extra_params: { custom_field: 'value', }, } ); ``` -------------------------------- ### POST /posts Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Creates a new post. Supports text content and optional attachments. An account ID can also be provided. ```APIDOC ## POST /posts ### Description Creates a new post. Supports text content and optional attachments. An account ID can also be provided. ### Method POST ### Endpoint /api/v1/posts ### Parameters #### Request Body - **FormData** - Required - Contains text, optional account_id, optional attachments ### Response #### Success Response (200) Created post details ``` -------------------------------- ### Create Webhook Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/webhook-resource.md Creates a new webhook subscription to receive event notifications at a specified URL. ```APIDOC ## Create Webhook ### Description Create a new webhook subscription. ### Method POST (implied by SDK method) ### Endpoint Not explicitly defined, accessed via `client.webhook.create()` ### Parameters #### Request Body - **input** (WebhookCreateBody) - Required - Webhook configuration. - **url** (string) - Required - Webhook endpoint URL. - **events** (string[]) - Required - Array of events to subscribe to. Supported events include `account.connected`, `account.disconnected`, `message.received`, `message.sent`, `email.received`, `email.sent`, `account.checkpoint_required`. - **options** (RequestOptions) - Optional - Request options for the API call. ### Request Example ```json { "url": "https://api.example.com/webhooks/unipile", "events": ["message.received", "email.received"] } ``` ### Response #### Success Response (200) - **id** (string) - The ID of the newly created webhook. - **url** (string) - The URL of the created webhook. - **events** (string[]) - The events the webhook is subscribed to. ### Response Example ```json { "id": "wh_def456", "url": "https://api.example.com/webhooks/unipile", "events": ["message.received", "email.received"] } ``` ``` -------------------------------- ### getAllInvitationsSent Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/users-resource.md List all pending connection invitations sent from an account, with support for pagination. ```APIDOC ## getAllInvitationsSent ### Description List all pending connection invitations sent from an account, with support for pagination. ### Method Not applicable (SDK method) ### Endpoint Not applicable (SDK method) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None #### SDK Method Signature `getAllInvitationsSent(input: GetAllInvitationsSentInput, options?: RequestOptions): Promise` #### Input Parameters - **input.account_id** (string) - Yes - The account ID - **input.limit** (number) - No - Maximum invitations to return - **input.cursor** (string) - No - Pagination cursor - **options** (RequestOptions) - No - Request options ### Request Example ```typescript const sentInvitations = await client.users.getAllInvitationsSent({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', }); sentInvitations.data.forEach(inv => { console.log('Sent to:', inv.recipient_id); }); ``` ### Response #### Success Response - **data** (array) - List of sent invitations - **next_cursor** (string) - Cursor for the next page of results (Each invitation object contains fields like `recipient_id`, `status`, etc. as defined in `UserInvitationSentListApiResponse`) ``` -------------------------------- ### Get Messages from Attendee Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Retrieves messages sent by a specific attendee. Supports filtering by time range and pagination. ```javascript MessagingResource.getAllMessagesFromAttendee(input) ``` -------------------------------- ### AccountResource Methods Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/README.md Manages account connections across all platforms, including connecting/disconnecting messaging and email accounts, handling 2FA/OTP, listing accounts, and creating hosted auth links. ```APIDOC ## AccountResource ### Description Manages account connections across all platforms. Used to: - Connect/disconnect messaging accounts (LinkedIn, WhatsApp, Telegram, etc.) - Connect email accounts (Gmail, Outlook, IMAP) - Handle 2FA/OTP verification - List connected accounts - Create hosted auth links for user-driven connection ### Key Methods - `connectLinkedin()` - `connectWhatsapp()` - `sendMessage()` - `solveCodeCheckpoint()` - `getAll()` ``` -------------------------------- ### Get Message Attachment Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/endpoints.md Downloads a specific attachment associated with a message. Returns the attachment as a binary file (Blob). ```javascript MessagingResource.getMessageAttachment(input) ``` -------------------------------- ### RequestOptions Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/types.md Configurable options for individual SDK requests, allowing overrides for logging and payload validation. ```APIDOC ## RequestOptions ### Description Options for individual requests. Can override client-level settings and add extra parameters. ### Type Definition ```typescript type RequestOptions = { logRequestResult?: boolean; logRequestPayload?: boolean; validateRequestPayload?: boolean; validateRequestPayloadLevel?: 'warn' | 'error'; extra_params?: Record; }; ``` ### Fields #### logRequestResult - **Type**: boolean - **Required**: No - **Description**: Whether to log the result of the request. #### logRequestPayload - **Type**: boolean - **Required**: No - **Description**: Whether to log the payload of the request. #### validateRequestPayload - **Type**: boolean - **Required**: No - **Description**: Whether to validate the request payload. #### validateRequestPayloadLevel - **Type**: 'warn' | 'error' - **Required**: No - **Description**: The level at which to validate the request payload ('warn' or 'error'). #### extra_params - **Type**: Record - **Required**: No - **Description**: Additional parameters to include in the request. ``` -------------------------------- ### Create a New LinkedIn Post with Attachments Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/users-resource.md Creates a new post on LinkedIn with file attachments. Ensure the file is read into a buffer before passing it in the attachments array. ```typescript import fs from 'fs'; const imageBuffer = await fs.promises.readFile('./image.jpg'); const post = await client.users.createPost({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', text: 'Check out this image', attachments: [['image.jpg', imageBuffer]], }); ``` -------------------------------- ### Get All User Posts Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/unipile-client.md Retrieve all posts for a specific user via the `users` property. Requires `account_id` and `identifier`. ```typescript client.users.getAllPosts({ account_id: '...', identifier: '...' }) ``` -------------------------------- ### Define PostInvitationInput Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/types.md Parameters for sending a connection invitation, including account ID, provider ID, and an optional message. ```typescript type PostInvitationInput = { account_id: string; provider_id: string; message?: string; }; ``` -------------------------------- ### Get All Chats Source: https://github.com/hanson-cheng/unipile-node-sdk/blob/develop/_autodocs/api-reference/messaging-resource.md Retrieves a list of all chats, supporting filtering by account ID, provider, and time range, along with pagination. ```typescript const chats = await client.messaging.getAllChats({ account_id: 't5XY4yQzR9WVrlNFyzPMhw', limit: 20, }); chats.data.forEach(chat => { console.log(chat.id, chat.subject); }); ```