Contacts · 3 min read
Bulk Upsert Contacts
Create or update up to 5,000 contacts in one contact list in a single request
Loads or refreshes a contact list in one request. For each contact:
- Lemu AI looks for an existing contact with the same
phone, then with the sameexternal_id. A row that has neither a phone nor anexternal_idis matched byemailinstead (ignoring upper and lower case), so sending the same email-only rows again updates them rather than creating duplicates. - If one is found, it is updated with the fields you send. If not, a new contact is created.
- The contact is added to the list named
list_name, which is created if it doesn't exist.
Each contact is handled on its own, so one bad row doesn't stop the rest. Rows that fail are reported in errors.
This endpoint matches rows by phone, external_id and email only. It does not merge contacts. To link activity from several identifiers (for example a website visitor id) to one person, use Send an event.
Bulk matching compares phone numbers exactly as stored. Send every number in the same international format (for example +919876543210) so existing contacts are found instead of duplicated.
POST
/api/v1/contacts/bulk-upsertHeaders#
| Name | Required | Description |
|---|---|---|
X-API-Key | Yes | An API key from your organization. See Authentication. |
Content-Type | Yes | application/json |
Request body#
| Field | Type | Required | Description |
|---|---|---|---|
list_name | string | Yes | The list to put the contacts in (1 to 255 characters). Created if it doesn't exist. |
contacts | array | Yes | Between 1 and 5,000 contacts. Each one accepts the fields below. |
Each contact:
| Field | Type | Description |
|---|---|---|
phone | string | Phone number in international format. |
external_id | string | Your own id for the person. |
email | string | Email address. |
first_name, last_name | string | Name. A single name (or full_name) is also accepted and split into first and last name. |
company | string | Company name. |
title | string | Job title. |
tags | array of strings | Replaces the contact's tags. |
custom_fields | object | Extra values, merged into the contact's custom fields. |
| any other key | any | Stored in custom_fields, so you can send a row from a spreadsheet or CRM as it is. A mobile key is used as phone and an id key as external_id when those aren't set. |
Example request:
curl -X POST https://app.lemuai.com/api/v1/contacts/bulk-upsert \
-H "X-API-Key: lemu_your_api_key" \
-H "Content-Type: application/json" \
-d '{
"list_name": "October renewals",
"contacts": [
{ "phone": "+919876543210", "first_name": "Priya", "plan": "Gold" },
{ "phone": "+919812345678", "name": "Rahul Verma", "id": "crm-58214", "tags": ["renewal"] },
{ "phone": "+919876543210", "first_name": "Priya S." }
]
}'Response#
200
{
"created": 1,
"updated": 1,
"failed": 1,
"errors": [
{ "index": 2, "error": "Duplicate phone +919876543210 in batch, skipped" }
],
"list_created": false,
"list_id": 42,
"contacts": [
{
"id": 901,
"organization_id": 7,
"external_id": "crm-58213",
"phone": "+919876543210",
"phone_last4": "3210",
"phone_masked": false,
"email": null,
"first_name": "Priya",
"last_name": "Sharma",
"company": null,
"title": null,
"tags": ["renewal", "gold"],
"custom_fields": { "plan": "Gold" },
"created_at": "2026-10-20T10:00:00Z",
"updated_at": "2026-10-24T09:20:03Z"
}
]
}| Field | Type | Description |
|---|---|---|
created | integer | Contacts created. |
updated | integer | Existing contacts updated. |
failed | integer | Rows that were skipped. |
errors | array | One entry per failed row: index (its position in your contacts array, starting at 0) and error (why). A phone number, external_id or email (for email-only rows) repeated within the same request is skipped after its first appearance. |
list_created | boolean | true if the list was created by this request. |
list_id | integer | The id of the list. Use it with List the contacts in one list, or to pick the list as a journey or campaign audience. |
contacts | array | The contacts that were created or updated. See contact fields. |
Errors#
| Status | When |
|---|---|
401 | The API key is missing or not valid |
402 | The contacts would take your organization over its plan's contact limit |
422 | list_name is missing, contacts is empty or has more than 5,000 items, or a field is too long |
Was this page helpful?
Docs