> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.levrage.ai/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.levrage.ai/_mcp/server.

# Create or upsert up to 500 leads

POST https://api.levrage.ai/v1/crm/leads/bulk
Content-Type: application/json

Each row succeeds or fails on its own; `results` has one entry per row in order. `on_conflict`, `match_on` and `create_missing_fields` apply to every row unless the row sets its own. For a large sheet, send chunks of 500 with one Idempotency-Key each.

Reference: https://docs.levrage.ai/api-reference/crm/bulk-upsert

## Request

### Headers

- `Idempotency-Key` (string, optional) — Your unique id for this request (≤ 255 characters). Repeating it within 24 h replays the first answer instead of writing twice.

### Body (application/json)

This endpoint expects an object.

- `leads` (list of CrmLeadsBulkPostRequestBodyContentApplicationJsonSchemaLeadsItems, required)
- `on_conflict` (enum, optional, nullable)
  - Allowed values: `error`, `update`, `ignore`
- `match_on` (list of enum, optional, nullable)
  - Allowed values: `external_id`, `phone`, `email`
- `create_missing_fields` (boolean, optional, nullable)

## Response

### 200

Successful Response

- `results` (list of CrmBulkRow, required)
- `created` (integer, required)
- `updated` (integer, required)
- `unchanged` (integer, required)
- `failed` (integer, required)
- `created_fields` (list of CrmCreatedField, optional, nullable)
- `missing_fields` (list of string, optional, nullable) — Every custom field name sent that doesn't exist, once (rows naming them failed).

## Errors

### 400 Bad Request Error

Something in the request is wrong — `message` says what.

- `error` (CrmErrorBody, required)

### 401 Unauthorized Error

No key, or an unknown / revoked / expired key.

- `error` (CrmErrorBody, required)

### 403 Forbidden Error

The key has no CRM access, or read-only access.

- `error` (CrmErrorBody, required)

### 429 Too Many Requests Error

Over 600 requests a minute for this key — wait Retry-After seconds.

- `error` (CrmErrorBody, required)

## Types

### CrmLeadsBulkPostRequestBodyContentApplicationJsonSchemaLeadsItems

A lead to create or change. Send only what you have; custom fields go inside `fields`.

- `name` (string, optional, nullable)
- `phone` (string, optional, nullable) — Indian numbers in any common shape: 9876543210, +91 98765 43210.
- `email` (string, optional, nullable)
- `external_id` (string, optional, nullable) — Your id for the person (customer no., loan no., employee id) — the best key to upsert on.
- `company` (string, optional, nullable)
- `city` (string, optional, nullable)
- `stage_id` (string, optional, nullable) — From GET /crm/stages.
- `pipeline_id` (string, optional, nullable) — From GET /crm/pipelines; without stage_id the lead goes to that pipeline's first stage.
- `owner_user_id` (string, optional, nullable)
- `tags` (list of string, optional, nullable)
- `score` (integer, optional, nullable)
- `score_label` (enum, optional, nullable)
  - Allowed values: `hot`, `warm`, `cold`
- `expected_close_at` (string, optional, nullable)
- `probability` (integer, optional, nullable)
- `lost_reason` (string, optional, nullable)
- `next_action_at` (string, optional, nullable)
- `consent` (CrmLeadsBulkPostRequestBodyContentApplicationJsonSchemaLeadsItemsConsent, optional, nullable)
- `fields` (CrmLeadsBulkPostRequestBodyContentApplicationJsonSchemaLeadsItemsFields, optional, nullable) — Custom fields by key or by label, in any case (GET /crm/fields lists them): \{"Zone": "Madhapur"}.
- `source` (string, optional, nullable) — On create only: a short lower-case word (default "api").
- `source_detail` (CrmLeadsBulkPostRequestBodyContentApplicationJsonSchemaLeadsItemsSourceDetail, optional, nullable) — On create only, e.g. \{"form": "Contact us"}.
- `on_conflict` (enum, optional, nullable) — When the person is already a lead: error (default, 409), update, or ignore.
  - Allowed values: `error`, `update`, `ignore`
- `match_on` (list of enum, optional, nullable) — What makes two leads the same person (default all three, in that order).
  - Allowed values: `external_id`, `phone`, `email`
- `create_missing_fields` (boolean, optional, nullable) — Custom field names that don't exist become text fields instead of a 400.

### CrmBulkRow

- `index` (integer, required)
- `result` (enum, required)
  - Allowed values: `created`, `updated`, `unchanged`, `error`
- `lead_id` (string, optional, nullable)
- `error` (CrmBulkRowError, optional, nullable)

### CrmCreatedField

- `key` (string, required)
- `label` (string, required)

### CrmErrorBody

- `code` (string, required)
- `message` (string, required)
- `existing_id` (string, optional, nullable)

### CrmLeadsBulkPostRequestBodyContentApplicationJsonSchemaLeadsItemsConsent

- `call` (boolean, optional, nullable)
- `whatsapp` (boolean, optional, nullable)
- `email` (boolean, optional, nullable)

### CrmLeadsBulkPostRequestBodyContentApplicationJsonSchemaLeadsItemsFields

Custom fields by key or by label, in any case (GET /crm/fields lists them): \{"Zone": "Madhapur"}.

### CrmLeadsBulkPostRequestBodyContentApplicationJsonSchemaLeadsItemsSourceDetail

On create only, e.g. \{"form": "Contact us"}.

### CrmBulkRowError

## Examples

**Request**

```json
{
  "leads": [
    {
      "name": "Amit Kumar",
      "phone": "9876543210",
      "external_id": "12345",
      "city": "Hyderabad",
      "fields": {
        "Zone": "Madhapur",
        "Week": "43",
        "Plan": "Gold"
      },
      "source": "google_sheet",
      "on_conflict": "update"
    },
    {
      "name": "Ravi Teja",
      "phone": "9876500002",
      "external_id": "12346",
      "city": "Hyderabad",
      "fields": {
        "Zone": "Madhapur",
        "Week": "43",
        "Plan": "Gold"
      },
      "source": "google_sheet",
      "on_conflict": "update"
    }
  ],
  "on_conflict": "update",
  "create_missing_fields": true
}
```

**Response**

```json
{
  "results": [
    {
      "index": 1,
      "result": "created",
      "lead_id": "string",
      "error": {}
    }
  ],
  "created": 1,
  "updated": 1,
  "unchanged": 1,
  "failed": 1,
  "created_fields": [
    {
      "key": "string",
      "label": "string"
    }
  ],
  "missing_fields": [
    "string"
  ]
}
```

**SDK Code**

```python CRM_bulk_upsert_example
import requests

url = "https://api.levrage.ai/v1/crm/leads/bulk"

payload = {
    "leads": [
        {
            "name": "Amit Kumar",
            "phone": "9876543210",
            "external_id": "12345",
            "city": "Hyderabad",
            "fields": {
                "Zone": "Madhapur",
                "Week": "43",
                "Plan": "Gold"
            },
            "source": "google_sheet",
            "on_conflict": "update"
        },
        {
            "name": "Ravi Teja",
            "phone": "9876500002",
            "external_id": "12346",
            "city": "Hyderabad",
            "fields": {
                "Zone": "Madhapur",
                "Week": "43",
                "Plan": "Gold"
            },
            "source": "google_sheet",
            "on_conflict": "update"
        }
    ],
    "on_conflict": "update",
    "create_missing_fields": True
}
headers = {"Content-Type": "application/json"}

response = requests.post(url, json=payload, headers=headers)

print(response.json())
```

```javascript CRM_bulk_upsert_example
const url = 'https://api.levrage.ai/v1/crm/leads/bulk';
const options = {
  method: 'POST',
  headers: {'Content-Type': 'application/json'},
  body: '{"leads":[{"name":"Amit Kumar","phone":"9876543210","external_id":"12345","city":"Hyderabad","fields":{"Zone":"Madhapur","Week":"43","Plan":"Gold"},"source":"google_sheet","on_conflict":"update"},{"name":"Ravi Teja","phone":"9876500002","external_id":"12346","city":"Hyderabad","fields":{"Zone":"Madhapur","Week":"43","Plan":"Gold"},"source":"google_sheet","on_conflict":"update"}],"on_conflict":"update","create_missing_fields":true}'
};

try {
  const response = await fetch(url, options);
  const data = await response.json();
  console.log(data);
} catch (error) {
  console.error(error);
}
```

```go CRM_bulk_upsert_example
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

	url := "https://api.levrage.ai/v1/crm/leads/bulk"

	payload := strings.NewReader("{\n  \"leads\": [\n    {\n      \"name\": \"Amit Kumar\",\n      \"phone\": \"9876543210\",\n      \"external_id\": \"12345\",\n      \"city\": \"Hyderabad\",\n      \"fields\": {\n        \"Zone\": \"Madhapur\",\n        \"Week\": \"43\",\n        \"Plan\": \"Gold\"\n      },\n      \"source\": \"google_sheet\",\n      \"on_conflict\": \"update\"\n    },\n    {\n      \"name\": \"Ravi Teja\",\n      \"phone\": \"9876500002\",\n      \"external_id\": \"12346\",\n      \"city\": \"Hyderabad\",\n      \"fields\": {\n        \"Zone\": \"Madhapur\",\n        \"Week\": \"43\",\n        \"Plan\": \"Gold\"\n      },\n      \"source\": \"google_sheet\",\n      \"on_conflict\": \"update\"\n    }\n  ],\n  \"on_conflict\": \"update\",\n  \"create_missing_fields\": true\n}")

	req, _ := http.NewRequest("POST", url, payload)

	req.Header.Add("Content-Type", "application/json")

	res, _ := http.DefaultClient.Do(req)

	defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

	fmt.Println(res)
	fmt.Println(string(body))

}
```

```ruby CRM_bulk_upsert_example
require 'uri'
require 'net/http'

url = URI("https://api.levrage.ai/v1/crm/leads/bulk")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["Content-Type"] = 'application/json'
request.body = "{\n  \"leads\": [\n    {\n      \"name\": \"Amit Kumar\",\n      \"phone\": \"9876543210\",\n      \"external_id\": \"12345\",\n      \"city\": \"Hyderabad\",\n      \"fields\": {\n        \"Zone\": \"Madhapur\",\n        \"Week\": \"43\",\n        \"Plan\": \"Gold\"\n      },\n      \"source\": \"google_sheet\",\n      \"on_conflict\": \"update\"\n    },\n    {\n      \"name\": \"Ravi Teja\",\n      \"phone\": \"9876500002\",\n      \"external_id\": \"12346\",\n      \"city\": \"Hyderabad\",\n      \"fields\": {\n        \"Zone\": \"Madhapur\",\n        \"Week\": \"43\",\n        \"Plan\": \"Gold\"\n      },\n      \"source\": \"google_sheet\",\n      \"on_conflict\": \"update\"\n    }\n  ],\n  \"on_conflict\": \"update\",\n  \"create_missing_fields\": true\n}"

response = http.request(request)
puts response.read_body
```

```java CRM_bulk_upsert_example
import com.mashape.unirest.http.HttpResponse;
import com.mashape.unirest.http.Unirest;

HttpResponse<String> response = Unirest.post("https://api.levrage.ai/v1/crm/leads/bulk")
  .header("Content-Type", "application/json")
  .body("{\n  \"leads\": [\n    {\n      \"name\": \"Amit Kumar\",\n      \"phone\": \"9876543210\",\n      \"external_id\": \"12345\",\n      \"city\": \"Hyderabad\",\n      \"fields\": {\n        \"Zone\": \"Madhapur\",\n        \"Week\": \"43\",\n        \"Plan\": \"Gold\"\n      },\n      \"source\": \"google_sheet\",\n      \"on_conflict\": \"update\"\n    },\n    {\n      \"name\": \"Ravi Teja\",\n      \"phone\": \"9876500002\",\n      \"external_id\": \"12346\",\n      \"city\": \"Hyderabad\",\n      \"fields\": {\n        \"Zone\": \"Madhapur\",\n        \"Week\": \"43\",\n        \"Plan\": \"Gold\"\n      },\n      \"source\": \"google_sheet\",\n      \"on_conflict\": \"update\"\n    }\n  ],\n  \"on_conflict\": \"update\",\n  \"create_missing_fields\": true\n}")
  .asString();
```

```php CRM_bulk_upsert_example
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.levrage.ai/v1/crm/leads/bulk', [
  'body' => '{
  "leads": [
    {
      "name": "Amit Kumar",
      "phone": "9876543210",
      "external_id": "12345",
      "city": "Hyderabad",
      "fields": {
        "Zone": "Madhapur",
        "Week": "43",
        "Plan": "Gold"
      },
      "source": "google_sheet",
      "on_conflict": "update"
    },
    {
      "name": "Ravi Teja",
      "phone": "9876500002",
      "external_id": "12346",
      "city": "Hyderabad",
      "fields": {
        "Zone": "Madhapur",
        "Week": "43",
        "Plan": "Gold"
      },
      "source": "google_sheet",
      "on_conflict": "update"
    }
  ],
  "on_conflict": "update",
  "create_missing_fields": true
}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

echo $response->getBody();
```

```csharp CRM_bulk_upsert_example
using RestSharp;

var client = new RestClient("https://api.levrage.ai/v1/crm/leads/bulk");
var request = new RestRequest(Method.POST);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"leads\": [\n    {\n      \"name\": \"Amit Kumar\",\n      \"phone\": \"9876543210\",\n      \"external_id\": \"12345\",\n      \"city\": \"Hyderabad\",\n      \"fields\": {\n        \"Zone\": \"Madhapur\",\n        \"Week\": \"43\",\n        \"Plan\": \"Gold\"\n      },\n      \"source\": \"google_sheet\",\n      \"on_conflict\": \"update\"\n    },\n    {\n      \"name\": \"Ravi Teja\",\n      \"phone\": \"9876500002\",\n      \"external_id\": \"12346\",\n      \"city\": \"Hyderabad\",\n      \"fields\": {\n        \"Zone\": \"Madhapur\",\n        \"Week\": \"43\",\n        \"Plan\": \"Gold\"\n      },\n      \"source\": \"google_sheet\",\n      \"on_conflict\": \"update\"\n    }\n  ],\n  \"on_conflict\": \"update\",\n  \"create_missing_fields\": true\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift CRM_bulk_upsert_example
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [
  "leads": [
    [
      "name": "Amit Kumar",
      "phone": "9876543210",
      "external_id": "12345",
      "city": "Hyderabad",
      "fields": [
        "Zone": "Madhapur",
        "Week": "43",
        "Plan": "Gold"
      ],
      "source": "google_sheet",
      "on_conflict": "update"
    ],
    [
      "name": "Ravi Teja",
      "phone": "9876500002",
      "external_id": "12346",
      "city": "Hyderabad",
      "fields": [
        "Zone": "Madhapur",
        "Week": "43",
        "Plan": "Gold"
      ],
      "source": "google_sheet",
      "on_conflict": "update"
    ]
  ],
  "on_conflict": "update",
  "create_missing_fields": true
] as [String : Any]

let postData = JSONSerialization.data(withJSONObject: parameters, options: [])

let request = NSMutableURLRequest(url: NSURL(string: "https://api.levrage.ai/v1/crm/leads/bulk")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers
request.httpBody = postData as Data

let session = URLSession.shared
let dataTask = session.dataTask(with: request as URLRequest, completionHandler: { (data, response, error) -> Void in
  if (error != nil) {
    print(error as Any)
  } else {
    let httpResponse = response as? HTTPURLResponse
    print(httpResponse)
  }
})

dataTask.resume()
```