Contact Introduction and Integration
What Is a Contact?
A Contact represents an end user who interacts with the AI assistant. Once you map users from your own system to MaiAgent Contacts, the AI can identify "who is asking" — correctly retrieving that person's conversation history and permission settings, rather than someone else's.
Contacts do not need a MaiAgent account (this is the key difference from Members/Roles), and users are not aware of their existence — a Contact is simply an identity mapping between your system and MaiAgent.
What Can Be Attached to a Contact
Basic info (name, email, avatar)
Displayed in the backend contact list and conversation logs
See API documentation below on this page
Custom attributes (metadata)
Background data such as department and membership tier — the AI reads and incorporates this into responses
Query metadata (query_metadata)
Restrict the knowledge base/document/tag scope this user can search
MCP/API tool credentials
Allow the AI to call external tools with that user's identity and permissions
Conversation history
Continue conversations across devices
Takes effect when the frontend includes contactId
Three Paths to Create and Sync Contacts
Identity Sync API (setup-contact-credentials)
Syncing on user login, binding tool credentials, bulk backfilling from existing systems
Idempotent (no duplicates for the same sourceId), no API Key required. Includes a version that Web Chat frontend auth calls automatically. Recommended for most integration scenarios — see Contact Identity Sync and Token Update
Contact API (POST /api/v1/contacts/)
Full backend control over the contact lifecycle, need to set query_metadata at creation time
Requires an API Key; use PATCH /api/v1/contacts/{contact_id}/ for updates (only updates the fields provided). See schema at API Documentation - Contacts
Bulk Import (Excel)
First-time integration with existing systems, backfilling large numbers of users at once
Limit of 10,000 rows; can include query_metadata and API tool credentials simultaneously — see details below
All four paths create the same type of Contact and can be mixed (e.g., use bulk import for initial integration, then identity sync for daily logins).
Integration Flow
Three steps:
Check mapping: Use the enterprise system's user ID to look up member data and confirm whether a MaiAgent
contact_idalready existsCreate or update: If none exists, create one (and store the
contact_id); when the user changes their name/email or permissions change, sync-update the contact (PATCH /api/v1/contacts/{contact_id}/), to ensure subsequent conversations have correct personalized content and permissionsInitialize Web Chat: Include
contactIdin the frontend config — see Web Chat Embedding and SDK
Contact Bulk Import (Excel)
For first-time integration with existing systems, use Excel to bulk create (or update) contacts:
Fill In the Data
Name(required)
✅
Contact display name
Email(required)
✅
One of the matching keys (case-insensitive)
Phone Number
Phone number
Source ID(required)
✅
User identifier from the enterprise system, one of the matching keys; use a non-guessable value (same as the Identity Sync API security note)
Query Metadata
JSON object written to the contact's knowledge query scope; empty cell = preserve existing value. See JSON Format Guide for formatting
API Credentials
JSON array [{"tool": "<tool ID>", "headers": {...}}] to bind API tool credentials; empty = preserve existing credentials
Upload and Import
POST /api/v1/contacts/bulk-import/ (multipart/form-data, Authorization: Api-Key authentication, same as the Contact API):
file: The completed.xlsxfile (limit: 10 MB, 10,000 rows)inboxes: List of inbox UUIDs — each imported contact's inbox set will be entirely replaced with this list; if you plan to use Web Chat login sync afterwards, make sure to include the corresponding Web Chat inbox
Response: { "created": N, "updated": M }
Import matching and update rules:
Upsert using (
Source ID,Email) as the key: if an existing contact matches, update the name/phone/Query Metadata (empty cells are left unchanged); if no match, create a new contactAPI Credentialsupsert using (contact, tool) as the key; tool credentials not mentioned in the file are left untouchedThe entire batch completes within a single transaction: if any row has a format error (e.g., mismatched field names, invalid JSON), the entire batch is not written, and the error message indicates the row number
Create Contacts via the GUI
Go to the contact management interface
Click Add Contact
The following page appears after clicking:
Enter the contact name, select the conversation platform, and create the contact. After creation, click the copy button to retrieve the contact ID (the contactId parameter for Web Chat initialization).
Implementation Recommendations
Add a mapping field to the member data table (e.g.,
maiagent_contact_id, UUID, nullable), and record creation/update timestamps to ensure the enterprise user ID ↔ Contact ID mapping is traceableImplement idempotency: Check the mapping before creating, or use the Identity Sync API directly (
sourceIdis idempotent — re-running does not create duplicate contacts)Log API calls for easier troubleshooting of mapping issues
Call asynchronously: Execute contact-related API calls in parallel with other login flow requests; failures should not block user login — retry on the next login
Last updated
Was this helpful?
