### Install SDK Source: https://developer.unipile.com/v2.0/docs/google-messages-quickstart Install the Unipile SDK using npm or pnpm. ```Text npm i @unipile/sdk ``` ```Text pnpm add unipile ``` -------------------------------- ### Setup Client (Python) Source: https://developer.unipile.com/v2.0/docs/gmail-quickstart Create a new file that setup the Unipile Client using your API Key generated previously generated. ```python import unipile configuration = unipile.Configuration() configuration.api_key["apiKey"] = "apikey" api_client = unipile.ApiClient(configuration) emails_api = unipile.EmailsApi(api_client) ``` -------------------------------- ### Install Unipile SDK with pnpm Source: https://developer.unipile.com/v2.0/docs/facebook-quickstart Install the Unipile SDK using pnpm. ```Text pnpm add unipile ``` -------------------------------- ### Install Unipile SDK with npm Source: https://developer.unipile.com/v2.0/docs/facebook-quickstart Install the Unipile SDK using npm. ```Text npm i @unipile/sdk ``` -------------------------------- ### Setup Client (Node.js) Source: https://developer.unipile.com/v2.0/docs/gmail-quickstart Create a new file that setup the Unipile Client using your API Key generated previously generated. ```typescript import { UnipileEmails } from "unipile"; const key = "apikey"; const emailsApi = new UnipileEmails({ key }); ``` -------------------------------- ### Send a first message (SDK) Source: https://developer.unipile.com/v2.0/docs/x-twitter-quickstart Start a new X conversation using the Unipile SDK. ```typescript await messagingApi.startChat({ path: { account_id: "acc_1234567890", }, body: { users_ids: "@jack", text: "Hello from Unipile!", }, }); ``` -------------------------------- ### Setup Unipile Client (Python) Source: https://developer.unipile.com/v2.0/docs/linkedin-quickstart Sets up the Unipile Client using an API Key for Python. ```python import unipile configuration = unipile.Configuration() configuration.api_key["apiKey"] = "apikey" api_client = unipile.ApiClient(configuration) messaging_api = unipile.MessagingApi(api_client) ``` -------------------------------- ### Provider Integration Example Source: https://developer.unipile.com/v2.0/docs/welcome This snippet demonstrates how to quickly start with a provider, showing the necessary configuration and initialization steps. ```typescript Ana+DwYiufbbb8zt/fbX7m47ebg4tZ1hwugewNAX/6SVtdd+luK3Uilho06OB5KgnM6Pl7X2TGXs2CoQYRuYUAAggggAACdQvo2wBQcuGhJI3e+ZEl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e2V/1IULKHiOpYYng2pfHjN69V5cmoiyU+eYuTeQukX6jQSmgYEEEAAAQQQiCgQbANAzWWGmkQkVtW/mGzEwDEUIntab2tKn/2f/fX/z/7lPs+nBg9oFroxRF5oTK2dRBIWCSLKUCmjbLA9sk8DuPrmvb0bU/j/z3nU8ssAChZfAv0h6oITjOnmNa9X5zETPtQsGGryREP35qLVldhQntxEAAEEEEAAgdoFxDcA1FxmqElEao1zr/AGJnKW7whxgX1a77Qe7/vaTnNgwYEiCBI2umCiWSjnSVNmDl1VVyrLMfid494wsgxVYmOefdpG054puGPoeRo4qP11vIN4JjkuI+95xwXybM+dN7eD54R0RwABBBBAAIHUBcQ2AFRdZmTJNObwk3X2djYas3H1jHn88dP59P/99oH/n15t//of6BhDHmg2gbBZwpUPXVVXymbC4E9+a5fJnj0yjcfWdW3zuOPWTC59gp1roGd3V4h ``` -------------------------------- ### List emails (Python) Source: https://developer.unipile.com/v2.0/docs/imap-quickstart Get the emails list of the account using List folder Emails. ```python emails = emails_api.get_folder_emails_list( "INBOX", "acc_123456789", limit=20, ) ``` -------------------------------- ### Send a first message (API) Source: https://developer.unipile.com/v2.0/docs/x-twitter-quickstart Start a new X conversation using the Unipile API. ```curl curl --request POST \ --url https://api.unipile.com/v2/acc_1234567890/chats/send \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data ' { "users_ids": "@jack", "text": "Hello from Unipile!" } ' ``` -------------------------------- ### List emails (Node.js) Source: https://developer.unipile.com/v2.0/docs/imap-quickstart Get the emails list of the account using List folder Emails. ```typescript const emails = await emailsApi.getFolderEmailsList({ path: { account_id: "acc_123456789", folder_id: "INBOX", }, query: { limit: 20, }, }); ``` -------------------------------- ### List emails (Python) Source: https://developer.unipile.com/v2.0/docs/gmail-quickstart To get the emails list of the account acc_1234567890, use List all Emails. ```python emails = emails_api.get_emails_list("acc_1234567890") ``` -------------------------------- ### Send a first message Source: https://developer.unipile.com/v2.0/docs/google-messages-quickstart Start a new conversation with a recipient. ```TypeScript await messagingApi.startChat({ path: { account_id: "acc_1234567890", }, body: { users_ids: "+33644556677", text: "Hello from Unipile!", }, }); ``` ```curl curl --request POST \ --url https://api.unipile.com/v2/acc_1234567890/chats \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data \ '{ "users_ids": "+33644556677", "text": "Hello from Unipile!" }' ``` -------------------------------- ### List emails (Node.js) Source: https://developer.unipile.com/v2.0/docs/gmail-quickstart To get the emails list of the account acc_1234567890, use List all Emails. ```typescript const emails = await emailsApi.getEmailsList({ path: { account_id: "acc_1234567890", }, }); ``` -------------------------------- ### List emails (curl) Source: https://developer.unipile.com/v2.0/docs/imap-quickstart Get the emails list of the account using List folder Emails. ```curl curl --request GET \ --url https://api.unipile.com/v2/acc_1234567890/folders/INBOX/emails \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' ``` -------------------------------- ### Get Job Posting Budget (Node.js) Source: https://developer.unipile.com/v2.0/docs/copy-of-list-job-postings Example of how to retrieve the recommended budget for a job posting using the Unipile API in Node.js. ```javascript const { data } = await linkedInApi.getRecruiterJobPostingBudget({ path: { account_id: "acc_123456789", job_id: "job_id", project_id: "project_id", }, }); ``` -------------------------------- ### Get Job Posting Budget (Python) Source: https://developer.unipile.com/v2.0/docs/copy-of-list-job-postings Example of how to retrieve the recommended budget for a job posting using the Unipile API in Python. ```python budget = linked_in_api.get_recruiter_job_posting_budget( "project_id", "job_id", "acc_123456789", ) ``` -------------------------------- ### Example cURL request to start an OAuth intent Source: https://developer.unipile.com/v2.0/docs/oauth-flow This cURL command demonstrates how to make a POST request to the Start Auth Intent endpoint with the necessary headers and JSON payload. ```curl curl --request POST \ --url https://api.unipile.com/v2/auth/intent \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data ' { "provider": "google", "oauth_callback_redirect_uri": "http\://localhost:3000/oauth-callback" } ' ``` -------------------------------- ### Example endpoint Source: https://developer.unipile.com/v2.0/docs/configure-a-webhook This example uses Express to receive webhooks ```javascript // This example uses Express to receive webhooks const express = require('express'); const app = express(); app.post('/endpoint', (request, response) => { const event = request.body; // Handle the event switch (event.type) { case 'message.new': const message = event.payload; // Then define and call a method to handle the ingestion of new messages. // handleNewMessage(message); break; default: console.log(`Unhandled event type ${event.type}`); } // Return a response to acknowledge receipt of the event response.json({received: true}); }); app.listen(8000, () => console.log('Running on port 8000')); ``` -------------------------------- ### Python example Source: https://developer.unipile.com/v2.0/docs/linkedin-edit-own-profile Example of how to update a user profile using Python. ```python profile = users_api.update_user_profile( "me", "acc_123456789", { "location": "01234", "specifics": { "headline": "Master of Unipile APIs", }, }, ) ``` -------------------------------- ### Node.js example Source: https://developer.unipile.com/v2.0/docs/linkedin-edit-own-profile Example of how to update a user profile using Node.js. ```javascript const { data } = await usersApi.updateUserProfile({ path: { account_id: "acc_123456789", user_id: "me", }, body: { location: '01234', specifics: { linkedin: { headline: "Master of Unipile APIs" } } }, }); ``` -------------------------------- ### Get Chat Source: https://developer.unipile.com/v2.0/docs/migration-messaging-api Migrating from GET /v1/chats/:chat_id to GET /v2/:account_id/chats/:chat_id. ```http GET /v1/chats/:chat_id GET /v2/:account_id/chats/:chat_id ``` -------------------------------- ### List all Chats Source: https://developer.unipile.com/v2.0/docs/migration-messaging-api Migrating from GET /v1/chats to GET /v2/:account_id/chats or GET /v2/:account_id/inboxes/:inbox_id/chat. ```http GET /v1/chats GET /v2/:account_id/chats GET /v2/:account_id/inboxes/:inbox_id/chat ``` -------------------------------- ### Get a User Chat (v2) Source: https://developer.unipile.com/v2.0/docs/migration-messaging-api The recommended v2 endpoint to get a user's chats. ```http GET /v2/:account_id/users/:user_id/chats ``` -------------------------------- ### List all messages from a chat Source: https://developer.unipile.com/v2.0/docs/migration-messaging-api Migrating from GET /v1/chats/:chat_id/messages to GET /v2/:account_id/chats/:chat_id/messages. ```http GET /v1/chats/:chat_id/messages GET /v2/:account_id/chats/:chat_id/messages ``` -------------------------------- ### Send an Email (Python) Source: https://developer.unipile.com/v2.0/docs/gmail-quickstart To send an Email, use Send Email. ```python emails_api.send_email( "acc_123456789", { "to": [{"email": "example@gmail.com"}], "plain_text": "Hello from Unipile!", }, ) ``` -------------------------------- ### Create a Unipile Messaging client Source: https://developer.unipile.com/v2.0/docs/facebook-quickstart Create a Unipile Messaging client instance using your API key. ```typescript import { UnipileMessaging } from "unipile"; const key = "apikey"; const messagingApi = new UnipileMessaging({ key }); ``` -------------------------------- ### Send an Email (Node.js) Source: https://developer.unipile.com/v2.0/docs/gmail-quickstart To send an Email, use Send Email. ```typescript await emailsApi.sendEmail({ path: { account_id: "acc_123456789", }, body: { to: [ { email: "example@gmail.com", }, ], plain_text: "Hello from Unipile!", }, }); ``` -------------------------------- ### List emails (curl) Source: https://developer.unipile.com/v2.0/docs/outlook-quickstart To get the emails list of the account acc_1234567890, use List all Emails. ```curl curl --request GET \ --url https://api.unipile.com/v2/acc_1234567890/emails \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json'" ``` -------------------------------- ### Client Initialization Source: https://developer.unipile.com/v2.0/docs/welcome How to initialize the Unipile client with provider configuration. ```javascript const unipile = require('unipile'); unipile.init({ provider: { name: 'aws', region: 'us-east-1', credentials: { access_key_id: 'AKIAIOSFODNN7EXAMPLE', secret_access_key: 'wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY' } } }); ``` -------------------------------- ### Provider Configuration Source: https://developer.unipile.com/v2.0/docs/welcome Example configuration for setting up a provider in Unipile. ```yaml provider: name: "aws" region: "us-east-1" credentials: access_key_id: "AKIAIOSFODNN7EXAMPLE" secret_access_key: "wJalrXUtnFEMI/K7MDENG/bPxRfiCYzEXAMPLEKEY" ``` -------------------------------- ### List emails (curl) Source: https://developer.unipile.com/v2.0/docs/gmail-quickstart To get the emails list of the account acc_1234567890, use List all Emails. ```curl curl --request GET \ --url https://api.unipile.com/v2/acc_1234567890/emails \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' \ --header 'content-type: application/json' ``` -------------------------------- ### Create Auth Link and redirect Source: https://developer.unipile.com/v2.0/docs/authenticate-with-hosted-auth This example demonstrates how to create an authentication link using the Unipile SDK and redirect the user to the Hosted Auth wizard. It includes defining a route, generating the link with specified providers, expiration, and redirect URI, and handling potential errors. ```typescript Node.js import { Unipile } from 'unipile'; const unipile = new Unipile('your-api-key'); // Define a route that users will visit to link an account app.get('/link-account', async (req, res) => { // Generate the Hosted Auth link const response = await unipile .hostedAuth .createAuthLink({ providers: "*", // Allow all providers to be linked expires_on: dayjs().add(10, 'minutes').toISOString(), // Make the Hosted Auth session expires after 10 minutes redirect_uri: "https://myapp.com/link-account/callback", // URL of you callback route }); if (response.error) return res.status(500); // Redirect the user to the given Hosted Auth URL. res.redirect(response.data.link); }); ``` ```curl curl --request POST \ --url https://api.unipile.com/v2/auth/link \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data ' { "providers": "*", "redirect_uri": "https://myapp.com/link-account/callback", "expires_on": "2025-05-05T00:00:00.000Z" } ' ``` -------------------------------- ### Send an Email (curl) Source: https://developer.unipile.com/v2.0/docs/gmail-quickstart To send an Email, use Send Email. ```curl curl --request POST \ --url https://api.unipile.com/v2/acc_1234567890/emails/send \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data \ '{ "plain_text": "Hello from Unipile!", "to": [ { "email": "example@gmail.com" } ] }' ``` -------------------------------- ### Send a first message (Node.js) Source: https://developer.unipile.com/v2.0/docs/facebook-quickstart Send a first message to a Facebook user using the Unipile SDK. ```typescript await messagingApi.startChat({ path: { account_id: "acc_1234567890", }, body: { users_ids: "https://www.facebook.com/zuck", text: "Hello from Unipile!", }, }); ``` -------------------------------- ### Python + FastAPI Server Source: https://developer.unipile.com/v2.0/docs/credentials-flow Example of a Python FastAPI server that handles the /auth-intent route to start the authentication process with Unipile. ```python import json import os from typing import Any, Optional import unipile import uvicorn from dotenv import load_dotenv from fastapi import Body, FastAPI from fastapi.middleware.cors import CORSMiddleware from fastapi.responses import JSONResponse, PlainTextResponse, Response from unipile.api.accounts_api import AccountsApi from unipile.api.custom_auth_api import CustomAuthApi from unipile.exceptions import ApiException load_dotenv() key = os.getenv("UNIPILE_API_KEY", "") configuration = unipile.Configuration() if key: configuration.api_key["apiKey"] = key api_client = unipile.ApiClient(configuration) custom_auth_api = CustomAuthApi(api_client) accounts_api = AccountsApi(api_client) app = FastAPI() app.add_middleware( CORSMiddleware, allow_origins=["*"], allow_credentials=True, allow_methods=["*"], allow_headers=["*"], ) def _to_response_data(value: Any) -> Any: if hasattr(value, "to_dict") and callable(value.to_dict): return value.to_dict() return value def _api_exception_to_body(exception: ApiException) -> Any: if exception.data is not None: return _to_response_data(exception.data) if exception.body: try: return json.loads(exception.body) except json.JSONDecodeError: return exception.body return exception.reason or "Unknown error" def _error_response(exception: ApiException) -> Response: status_code = exception.status or 500 body = _api_exception_to_body(exception) if isinstance(body, (dict, list)): return JSONResponse(status_code=status_code, content=body) return PlainTextResponse(status_code=status_code, content=str(body)) @app.post("/auth-intent") def auth_intent(body: Any = Body(...)) -> Response: try: params = custom_auth_api._start_auth_intent_serialize( start_auth_intent_request=body, _request_auth=None, _content_type=None, _headers=None, _host_index=0, ``` -------------------------------- ### List all Chats (Node.js) Source: https://developer.unipile.com/v2.0/docs/telegram-quickstart Retrieve the list of chats for a given Telegram account using the Unipile SDK. ```typescript const chats = await messagingApi.getChatsList({ path: { account_id: "acc_1234567890", }, }); ``` -------------------------------- ### Node.js + Express Server Source: https://developer.unipile.com/v2.0/docs/credentials-flow Example of a Node.js Express server that handles the /auth-intent route to start the authentication process with Unipile. ```typescript // index.ts import express, { Request, Response } from "express"; import cors from "cors"; import parser from "body-parser"; import "dotenv/config"; import { UnipileCustomAuth, UnipileAccounts } from "unipile"; const key = process.env.UNIPILE_API_KEY ?? ""; const customAuthApi = new UnipileCustomAuth({ key }); const accountsApi = new UnipileAccounts({ key }); const app = express(); app.use(cors()); app.use(parser.json()); app.use(parser.urlencoded({ extended: true })); app.use(express.json()); app.post("/auth-intent", async (req: Request, res: Response) => { const response = await customAuthApi.startAuthIntent({ body: req.body, }); // Handle Errors if (response.error) { res.status(response.response.status).send(response.error); return; } res.send(response.data); }); app.listen(3000, () => { console.log("Server is running on port 3000"); }); ``` -------------------------------- ### List all Chats (Python) Source: https://developer.unipile.com/v2.0/docs/telegram-quickstart Retrieve the list of chats for a given Telegram account using the Unipile SDK. ```python chats = messaging_api.get_chats_list("acc_1234567890") ``` -------------------------------- ### Send an Email (curl) Source: https://developer.unipile.com/v2.0/docs/outlook-quickstart To send an Email, use Send Email. ```curl curl --request POST \ --url https://api.unipile.com/v2/acc_1234567890/emails/send \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data ' { "plain_text": "Hello from Unipile!", "to": [ { "email": "example@gmail.com" } ] }' ``` -------------------------------- ### Start a new Chat Source: https://developer.unipile.com/v2.0/docs/migration-messaging-api Migrating from POST /v1/chats to POST /v2/:account_id/chats/send or POST /v2/:account_id/inboxes/:inbox_id/chat. ```http POST /v1/chats POST /v2/:account_id/chats/send POST /v2/:account_id/inboxes/:inbox_id/chat ``` -------------------------------- ### List Users Followed by a User (Node.js) Source: https://developer.unipile.com/v2.0/docs/linkedin-fetch-users-profiles Example of how to list users followed by a user using Node.js. ```node const { data } = await usersApi.listUserFollowing({ path: { account_id: "acc_123456789", user_id: "me", }, }); ``` -------------------------------- ### Collect credentials using cookies Source: https://developer.unipile.com/v2.0/docs/linkedin-link-accounts Example of starting an authentication intent for LinkedIn using 'access_token' and 'premium_access_token' cookies. ```typescript const data = await startAuthIntent({ provider: "linkedin", credentials: { access_token, premium_access_token, }, config: { products: ["classic", "sales_navigator"], } }); ``` -------------------------------- ### Handle the callback Source: https://developer.unipile.com/v2.0/docs/authenticate-with-hosted-auth This example shows how to create a callback route to handle the redirection after user authentication. It parses the query parameters to check for errors or successful linking, logging relevant information. ```typescript Node.js app.get('/link-account/callback', async (req, res) => { let q = url.parse(req.url, true).query; if (q.error_type) { console.log('Error:' + q.error_title); if (q.error_type === "api/already_exists") { // Handle duplicate accounts console.log("Existing account", q.error_detail) // acc_xxxxx } if (q.error_type === "api/restricted_account") { // Handle restricted accounts console.log("Reason", q.error_detail) // reason } } else { console.log(`${q.provider} account successfully linked`); } }); ``` -------------------------------- ### Collect credentials with specified products Source: https://developer.unipile.com/v2.0/docs/linkedin-link-accounts Example of starting an authentication intent for LinkedIn, specifying 'classic' and 'sales_navigator' products. ```typescript const data = await startAuthIntent({ provider: "linkedin", credentials: { username, password, }, config: { products: ["classic", "sales_navigator"], } }); ``` -------------------------------- ### Get folders and labels Source: https://developer.unipile.com/v2.0/docs/manage-mailboxes Retrieves a list of folders or Gmail labels using the `getFoldersList` method. Includes example implementations in Node.js, Python, and cURL. ```Node.js const { data } = await emailsApi.getFoldersList({ path: { account_id: "acc_123456789", }, query: { limit: 20, }, }); ``` ```Python folders = emails_api.get_folders_list( "acc_123456789", limit=20, ) ``` ```cURL curl --request GET \ --url https://api.unipile.com/v2/account_id/folders \ --header 'accept: application/json' ``` -------------------------------- ### Start Auth Intent with Cookies (Client-side TypeScript) Source: https://developer.unipile.com/v2.0/docs/link-instagram-accounts Example of initiating an authentication intent for Instagram using a sessionid cookie in client-side TypeScript. ```TypeScript const data = await startAuthIntent({ provider: "instagram", credentials: { sessionid, }, }); ``` -------------------------------- ### Node.js Example Source: https://developer.unipile.com/v2.0/docs/fetch-company-profile Fetches a company profile using the Unipile API in Node.js. ```node const { data } = await linkedInApi.getClassicCompanyProfile({ path: { account_id: "acc_123456789", company_id: "company_id", }, }); ``` -------------------------------- ### Python API Client Example Source: https://developer.unipile.com/v2.0/docs/credentials-flow A Python snippet demonstrating how to call the Unipile API to collect credentials and handle the response. ```python ) response_data = custom_auth_api.api_client.call_api(*params) response_data.read() response = custom_auth_api.api_client.response_deserialize( response_data=response_data, response_types_map={"200": "SolveCheckpoint200Response"}, ).data return JSONResponse(content=_to_response_data(response)) except ApiException as exception: return _error_response(exception) if __name__ == "__main__": uvicorn.run("src.main:app", host="0.0.0.0", port=4000, reload=True) ``` -------------------------------- ### Request First QR Code using cURL Source: https://developer.unipile.com/v2.0/docs/qr-code-flow Example cURL command to call the Start Auth Intent endpoint for a QR code-based authentication. ```curl curl --request POST \ --url https://api.unipile.com/v2/auth/intent \ --header 'X-API-KEY: api-key' \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data ' { "provider": "google_messages", "credentials": { "qrcode": true } } ' ``` -------------------------------- ### Weekly recurring event example Source: https://developer.unipile.com/v2.0/docs/recurring-events An event that happens from 6am until 7am every Tuesday and Friday starting from September 15th, 2015 and stopping after the fifth occurrence on September 29th. ```json "start": { "date_time": "2015-09-15T06:00:00", "timeZone": "Europe/Zurich" }, "end": { "dateTime": "2015-09-15T07:00:00", "timeZone": "Europe/Zurich" }, "recurrence": [ "RRULE:FREQ=WEEKLY;COUNT=5;BYDAY=TU,FR" ] ``` -------------------------------- ### Node.js + Express webhook handler Source: https://developer.unipile.com/v2.0/docs/configure-a-webhook This example demonstrates how to set up a webhook handler using Node.js and Express to verify the signature and process incoming events. ```javascript const crypto = require('crypto'); const express = require('express'); const app = express(); // Secret from dashboard const endpointSecret = process.env.UNIPILE_WEBHOOK_SECRET; app.post('/endpoint', express.raw({ type: 'application/json' }), (request, response) => { const signatureHeader = request.get('unipile-signature'); if (!endpointSecret || !signatureHeader) { return response.status(400).send('Missing secret or signature header'); } const parts = Object.fromEntries( signatureHeader.split(',').map((part) => { const [key, value] = part.split('='); return [key, value]; }), ); const timestamp = parts.t; const receivedSignature = parts.v0; if (!timestamp || !receivedSignature) { return response.status(400).send('Invalid signature header'); } const rawBody = request.body.toString('utf8'); const signedPayload = `${timestamp}.${rawBody}`; const expectedSignature = crypto.createHmac('sha256', endpointSecret).update(signedPayload).digest('hex'); const isValidSignature = receivedSignature.length === expectedSignature.length && crypto.timingSafeEqual(Buffer.from(receivedSignature), Buffer.from(expectedSignature)); if (!isValidSignature) { return response.status(400).send('Invalid signature'); } const maxAgeInSeconds = 300; const ageInSeconds = Math.abs(Math.floor(Date.now() / 1000) - Number(timestamp)); if (!Number.isFinite(Number(timestamp)) || ageInSeconds > maxAgeInSeconds) { return response.status(400).send('Expired signature'); } const event = JSON.parse(rawBody); switch (event.type) { case 'message.new': { const message = event.payload; // handleNewMessage(message); break; } default: console.log(`Unhandled event type ${event.type}`); } response.json({ received: true }); }); app.listen(8000, () => console.log('Running on port 8000')); ``` -------------------------------- ### Start Auth Intent with Credentials (Client-side TypeScript) Source: https://developer.unipile.com/v2.0/docs/link-instagram-accounts Example of initiating an authentication intent for Instagram using username and password credentials in client-side TypeScript. ```TypeScript const data = await startAuthIntent({ provider: "instagram", credentials: { username, password, }, }); ``` -------------------------------- ### Create an auth link with a custom proxy for Google Source: https://developer.unipile.com/v2.0/docs/authenticate-with-hosted-auth This example shows how to create an authentication link and specify a custom proxy configuration for the Google provider. ```Node.js const response = await unipile .hostedAuth .createAuthLink({ providers: "*", expires_on: dayjs().add(10, 'minutes').toISOString(), redirect_uri: "https://myapp.com/link-account/callback", config: { // If a google account is linked, use the given custom proxy google: { custom_proxy: { host: "1.1.1.1", port: 5100, protocol: "https", } } } }); ``` ```curl curl --request POST \ --url https://api.unipile.com/v2/auth/link \ --header 'accept: application/json' \ --header 'content-type: application/json' \ --data ' { "config": { "google": { "custom_proxy": { "protocol": "https", "host": "1.1.1.1", "port": 5100 } } }, "providers": "*", "redirect_uri": "https://myapp.com/link-account/callback", "expires_on": "2025-05-05T00:00:00.000Z" }' ``` -------------------------------- ### Retrieve an email v1 vs v2 Source: https://developer.unipile.com/v2.0/docs/migration-emails-api Comparison of GET endpoints for retrieving a single email between v1 and v2 APIs, noting the removal of `account_id` and `include_headers` query parameters. ```text GET /v1/emails/:email_id Use GET /v2/:account_id/emails/:email_id [Get an Email] Query param `account_id` is removed Specify in the path param Query param `include_headers` is removed Headers are always present Response shape has changed (see Email object changes) ``` -------------------------------- ### List Users Followed by a User (Python) Source: https://developer.unipile.com/v2.0/docs/linkedin-fetch-users-profiles Example of how to list users followed by a user using Python. ```python following = users_api.list_user_following("me", "acc_123456789") ``` -------------------------------- ### List all emails v1 vs v2 Source: https://developer.unipile.com/v2.0/docs/migration-emails-api Comparison of GET endpoints for listing emails between v1 and v2 APIs, including notes on IMAP specific requirements and parameter changes. ```text GET /v1/emails For Google and Outlook, use GET /v2/:account_id/emails [List all Emails]. For IMAP, [Initial Sync](https://developer.unipile.com/docs/initial-sync) must be enabled to use this route, otherwise use GET /v2/:account_id/folders/:folder_id/emails [List folder Emails]. Query param `account_id` is removed Specify in the path param Query param `folder` is removed Use GET /v2/:account_id/folders/:folder_id/emails [List folder Emails] to get emails from a specific folder Query param `role` is removed Sync folders list on your side and use `folder_id` in [List folder Emails] Query param `include_headers` is removed Headers are always present Response shape has changed (see Email object changes) ```