API Reference
Complete API reference for Quadrillian integration. All server-to-server API calls require your workspace's API key.
Authentication: API key required for all server-to-server calls
Content-Type: application/json
API Key Authentication
Include your API key in the request headers:
curl -H "api_key_name: your-api-key-name" -H "api_key_val: your-api-key-value" -H "Content-Type: application/json" ...
Authentication Endpoints
JWT Authentication Flow
The Quadrillian system uses JWT tokens for secure chat widget authentication.
A JWT (JSON Web Token) is a secure way to send information between parties. It contains:
- Header: Algorithm used for signing (e.g., HS256)
- Payload: The actual data (user info, expiration, etc.) - base64 encoded
- Signature: A cryptographic signature that proves the token is authentic
Here's how the authentication flow works:
- Your backend generates a JWT containing user info and signs it with your workspace secret
- Your frontend gets the JWT from your backend
- Quadrillian JS library calls quadrillian.com with the JWT to authenticate the user
- quadrillian.com verifies the JWT and signs the user into chat
Purpose
This endpoint is hosted on quadrillian.com and called by the Quadrillian JS library (running in the browser) to verify JWT tokens and authenticate users. The quadrillian.com server validates that:
- The JWT was signed with the correct workspace secret
- The JWT hasn't expired
- The workspace ID in the JWT matches the signing secret
API Request
The Quadrillian JS library sends the JWT token in the request body to quadrillian.com. The JWT already contains all the user data, so the request body only needs the JWT string:
JWT Token Structure
Before the Quadrillian JS library sends the JWT to quadrillian.com, your backend must create a JWT with this exact payload structure:
- workspace_id: Number - Your Quadrillian workspace ID (e.g., 456)
- external_user_id: String - Your internal user ID (e.g., "1234", "user_abc123")
- email: String - User's email address (optional, used for linking existing users)
- name: String - User's display name (optional)
- iat: Number - Issued at timestamp (when token was created)
- exp: Number - Unix timestamp when token expires (recommended: 24 hours from now)
API Response
If the JWT is valid, quadrillian.com returns the user information:
Error Responses
If something goes wrong, quadrillian.com returns an error:
User Provisioning
User provisioning happens automatically when users authenticate with JWT tokens. No separate API calls are required.
/api/chat/auth/verify endpoint, Quadrillian automatically handles user creation and management.
How Automatic User Provisioning Works
When the JWT verification endpoint processes a valid token, it automatically:
- Looks up the user by
external_user_idandworkspace_id - If user doesn't exist:
- Checks if a user with the same email already exists
- If found, links the existing user to your workspace with the
external_user_id - If not found, creates a new user with the provided information
- Returns the user information for the chat widget to use
- No need for separate user management API calls
- Handles user linking automatically (same email = same user)
- Works seamlessly with your existing user system
- Reduces integration complexity
JWT Token Requirements for User Provisioning
To enable automatic user provisioning, include these fields in your JWT token:
Topic Management
Manage chat topics using external keys for easy integration:
Look up a topic by its external key. This endpoint is used by the chat widget to resolve external keys to internal topic IDs.
Parameters
- external_key (query parameter) - The external key for the topic (e.g., "support-general")
- workspace_id (query parameter) - The workspace ID containing the topic
Response
Topic Creation
Create a new topic with an external key. This endpoint requires JWT authentication and should be called from your backend server.
Parameters
- external_key (required) - The external key for the topic (e.g., "support-ticket-12345")
- workspace_id (required) - The workspace ID containing the topic
- topic_name (optional) - Display name for the topic (defaults to external_key)
- ai_user_id (optional) - AI user ID to automatically add to the topic
Set User and Topic (SDK Endpoint)
Create or resolve a topic and ensure the user has access. This is the main endpoint used by the SDK for topic management. Automatically creates topics and users as needed.
Parameters
- external_key (required) - The external key for the topic
- workspace_id (required) - The workspace ID containing the topic
- topic_name (optional) - Display name for the topic (defaults to external_key)
- ai_user_id (optional) - AI user ID to automatically add to the topic
Add User to Topic
Add a user to an existing topic. This endpoint requires JWT authentication and should be called from your backend server.
Parameters
- external_key (required) - The external key for the topic
- workspace_id (required) - The workspace ID containing the topic
- user_id (optional) - User ID to add (defaults to the authenticated user from JWT)
Error Responses
All API endpoints return consistent error responses:
Common Error Codes
- INVALID_API_KEY - API key is missing or invalid
- INVALID_JWT - JWT token is malformed or expired
- WORKSPACE_MISMATCH - JWT workspace ID doesn't match the signing secret
- USER_NOT_FOUND - User doesn't exist in the workspace
- TOPIC_NOT_FOUND - Topic doesn't exist or user doesn't have access
- RATE_LIMITED - Too many requests, please slow down
- INVALID_REQUEST - Request body is malformed or missing required fields
- UNAUTHORIZED - User doesn't have permission for this action