LemuAIDocs

Contacts · 3 min read

Bulk Upsert Contacts

Create or update up to 5,000 contacts in one contact list in a single request

Open in ChatGPTOpen in ClaudeMarkdown

Loads or refreshes a contact list in one request. For each contact:

  1. Lemu AI looks for an existing contact with the same phone, then with the same external_id. A row that has neither a phone nor an external_id is matched by email instead (ignoring upper and lower case), so sending the same email-only rows again updates them rather than creating duplicates.
  2. If one is found, it is updated with the fields you send. If not, a new contact is created.
  3. 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-upsert

Headers#

NameRequiredDescription
X-API-KeyYesAn API key from your organization. See Authentication.
Content-TypeYesapplication/json

Request body#

FieldTypeRequiredDescription
list_namestringYesThe list to put the contacts in (1 to 255 characters). Created if it doesn't exist.
contactsarrayYesBetween 1 and 5,000 contacts. Each one accepts the fields below.

Each contact:

FieldTypeDescription
phonestringPhone number in international format.
external_idstringYour own id for the person.
emailstringEmail address.
first_name, last_namestringName. A single name (or full_name) is also accepted and split into first and last name.
companystringCompany name.
titlestringJob title.
tagsarray of stringsReplaces the contact's tags.
custom_fieldsobjectExtra values, merged into the contact's custom fields.
any other keyanyStored 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
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

JSON
{
  "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"
    }
  ]
}
FieldTypeDescription
createdintegerContacts created.
updatedintegerExisting contacts updated.
failedintegerRows that were skipped.
errorsarrayOne 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_createdbooleantrue if the list was created by this request.
list_idintegerThe id of the list. Use it with List the contacts in one list, or to pick the list as a journey or campaign audience.
contactsarrayThe contacts that were created or updated. See contact fields.

Errors#

StatusWhen
401The API key is missing or not valid
402The contacts would take your organization over its plan's contact limit
422list_name is missing, contacts is empty or has more than 5,000 items, or a field is too long