Unipile Node.js SDK

1.9.3 · active · verified Sun Apr 19

The Unipile Node.js SDK (version 1.9.3) provides a unified interface for integrating with multiple communication platforms, including LinkedIn, WhatsApp, Instagram, Telegram, and a generic Email API. It allows developers to programmatically manage social connections, send and receive messages (including LinkedIn InMail), retrieve user and company profiles, handle invitations, manage posts, and control email communications. This SDK is particularly useful for applications requiring multi-channel outreach, unified inboxes, or automation across various professional and messaging platforms, abstracting the complexities and individual APIs of each service. The SDK is actively maintained with regular updates reflecting new features and API changes across its supported providers.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to initialize the Unipile client, generate a hosted authentication link for account connection, and retrieve a LinkedIn company profile using environment variables for secure credential management.

import { UnipileClient } from 'unipile-node-sdk';

// Initialize the Unipile client with your DSN and Access Token.
// Always use environment variables for sensitive credentials in production.
const client = new UnipileClient(
  process.env.UNIPIL_DSN ?? 'https://api.unipile.com', // Default or example DSN
  process.env.UNIPIL_ACCESS_TOKEN ?? '' // Your Unipile API Access Token
);

async function runUnipileExample() {
  try {
    console.log('Attempting to generate a Hosted Auth Link...');
    // Generates a link for users to connect their social accounts securely.
    const authLinkResponse = await client.account.createHostedAuthLink({
      type: 'create', // 'create' for new accounts, 'reconnect' for existing
      expiresOn: new Date(Date.now() + 3600 * 1000).toISOString(), // Link valid for 1 hour
      api_url: process.env.UNIPIL_API_URL ?? 'https://api.unipile.com', // Your Unipile API URL
      providers: '*', // '*' for all providers, or an array like ['LINKEDIN', 'WHATSAPP']
      success_redirect_url: 'https://your-app.com/auth-success', // Where to redirect after successful connection
      metadata: { userId: 'user-123', integrationType: 'onboarding' } // Optional metadata
    });
    console.log('Hosted Auth Link Generated:', authLinkResponse.url); 

    // Example: Retrieve a LinkedIn company profile (requires a connected LinkedIn account_id).
    // This account_id would typically be stored after a user successfully connects via the auth link.
    const linkedinAccountId = process.env.LINKEDIN_ACCOUNT_ID; // Example: 'acc_xyz123'
    if (linkedinAccountId) {
      console.log(`\nRetrieving LinkedIn company profile for account ${linkedinAccountId}...`);
      const companyProfile = await client.users.getCompanyProfile({
        account_id: linkedinAccountId,
        identifier: 'Unipile', // The company's name or LinkedIn ID
      });
      console.log('Retrieved Company Profile:', companyProfile);
    } else {
      console.warn('\nWarning: LINKEDIN_ACCOUNT_ID environment variable not set. Skipping company profile example.');
    }

  } catch (error) {
    console.error('\nAn error occurred during Unipile SDK operation:');
    if (error instanceof Error) {
      console.error('Error message:', error.message);
      // Log the full error object for debugging in development
      if (process.env.NODE_ENV !== 'production') {
        console.error(error);
      }
    } else {
      console.error(error);
    }
  }
}

runUnipileExample();

view raw JSON →