Skip to content

ConnectGain API Authentication Guide

This guide covers every authentication method supported by the ConnectGain API, and how to obtain and use a user JWT (JSON Web Token). The examples reference the Postman collection at ../07-api/connectgain.postman_collection.json — see the Postman guide for import instructions.

On this page:


Authentication Methods

ConnectGain supports 3 authentication methods for different use cases:

1. External API Authentication (X-API-Key)

Best for: External systems, third-party integrations, automation

X-API-Key: cg_abc123def456...

2. Supabase REST API Authentication (Anon Key)

Best for: Direct database operations, CRUD operations

apikey: eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...

3. User JWT Authentication (Login Required)

Best for: User-specific operations, subscriptions, organizations

Authorization: Bearer USER_JWT_TOKEN

Getting a JWT Token — Step by Step

Step 1: Use the Login Endpoint

POST {{url}}/auth/v1/token?grant_type=password
apikey: {{anon_key}}
Content-Type: application/json

{
 "email": "your_email@example.com",
 "password": "your_password"
}

Step 2: Automatic Token Extraction

The login endpoint includes a test script that automatically:

  • Extracts access_token from the response
  • Saves it as the user_jwt_token variable
  • Logs a success message

Step 3: Use the Token in Other Endpoints

Now you can use {{user_jwt_token}} in endpoints that require user authentication.

Method 2: Using Browser Dev Tools

Step 1: Log in to the ConnectGain Web App

  1. Go to dashboard.connectgain.cloud
  2. Log in with your credentials
  3. Wait for successful login

Step 2: Extract the Token from the Browser

  1. Open Developer Tools (F12)
  2. Go to the Application tab
  3. Navigate to Local Storage → your domain
  4. Find the Supabase session data
  5. Copy the JWT token value

Step 3: Set It in Postman

  1. Go to the collection Variables tab
  2. Set the user_jwt_token value
  3. Save the collection

Authentication Endpoints

1. Login (Sign In)

POST {{url}}/auth/v1/token?grant_type=password
apikey: {{anon_key}}
Content-Type: application/json

{
 "email": "user@example.com",
 "password": "your_password"
}

Response:

{
 "access_token": "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...",
 "token_type": "bearer",
 "expires_in": 3600,
 "expires_at": 1737123456,
 "refresh_token": "abc123def456...",
 "user": {
 "id": "user-uuid",
 "email": "user@example.com",
 "email_confirmed_at": "2025-01-17T10:30:00Z"
 }
}

Features:

  • Auto-extracts the JWT token and saves it to the user_jwt_token variable
  • Returns user info including verification status
  • Provides a refresh token for token renewal

2. Sign Up (Register)

POST {{url}}/auth/v1/signup
apikey: {{anon_key}}
Content-Type: application/json

{
 "email": "newuser@example.com",
 "password": "secure_password",
 "data": {
 "first_name": "John",
 "last_name": "Doe"
 }
}

3. Refresh Token

POST {{url}}/auth/v1/token?grant_type=refresh_token
apikey: {{anon_key}}
Content-Type: application/json

{
 "refresh_token": "{{refresh_token}}"
}

4. Get User Info

GET {{url}}/auth/v1/user
apikey: {{anon_key}}
Authorization: Bearer {{user_jwt_token}}

5. Logout (Sign Out)

POST {{url}}/auth/v1/logout
apikey: {{anon_key}}
Authorization: Bearer {{user_jwt_token}}
Content-Type: application/json

{}

Collection Variables

Add these variables to your collection:

// Authentication variables
user_jwt_token = (auto-populated by login endpoint)
refresh_token = (auto-populated by login endpoint)

// Base variables
url = https://txpaxbxhnvnhsjwwaeoy.supabase.co
anon_key = eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9...
api_key = cg_your_api_key_here
organization_id = 40e9bb4c-3b1c-4e5b-8c7d-2f5a9b8e1c3d

Complete Testing Workflow

Phase 1: Authentication Setup

  1. Login — get a JWT token
  2. Get User Info — verify the token works
  3. List Organizations — test a user-specific endpoint

Phase 2: API Testing

  1. Search Contacts — test X-API-Key auth
  2. List Contacts — test REST API auth
  3. Create Contact — test with a JWT token
  4. Check Subscription — test the subscription endpoint

Phase 3: Full Workflow

  1. Create resources (contacts, companies, deals)
  2. Send messages via multiple channels
  3. Import data via CSV
  4. Manage subscriptions

Which Method to Use

Endpoint Auth method
List Organizations User JWT token from login
Check Subscription User JWT token from login
Create Contact User JWT token from login
Search Contacts / Companies, Insert Message X-API-Key
Direct table CRUD and queries with relations Supabase REST (anon key + JWT)

Note: a 401 response for an invalid API key is the expected, correct behavior.

Quick Start

  1. Import the collection into Postman
  2. Set the base variables (url, anon_key, api_key, organization_id)
  3. Run the Login endpoint with your credentials
  4. The JWT token is auto-saved to the user_jwt_token variable
  5. Test any endpoint — all authentication methods are now available

For External Systems

Use X-API-Key endpoints:

  • Search Contacts
  • Search Companies
  • Insert Message

For Internal Operations

Use JWT token endpoints:

  • List Organizations
  • Check Subscription
  • User-specific operations

For Database Operations

Use REST API endpoints:

  • All CRUD operations
  • Complex queries with relations

See also


ConnectGain — omnichannel inbox, CRM & automation for WhatsApp, Messenger, Instagram, Telegram and more. Open the app · Docs home