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

# Create batch

POST https://v1.getraya.app/api/batch
Content-Type: application/json

Creates a new batch with contacts. Each contact must have contact\_name and contact\_phone. Additional fields are stored in agent\_args and can be used during calls. Customer ID is automatically determined from the API key. To add contacts to an existing batch, use POST /api/batch/\{id}/contacts.

Reference: https://docs.getraya.app/api-reference/batches/create-batch

## Authentication

- `X-API-Key` header (required) — API key for authentication. Example: raya_ABCD1234567890abcdef

## Request

### Body (application/json)

This endpoint expects a CreateBatchRequest.

- `agent_id` (string, required) — The UUID of the agent to use for this batch
- `batch_name` (string, required) — Name for the batch
- `contacts` (list of CreateBatchRequestContactsItems, required) — Array of contact objects. Each contact must have contact_name and contact_phone. Additional fields are allowed.

## Response

### 200

Batch created successfully

- `status` (enum, optional) — Status of the batch creation
  - Allowed values: `success`, `error`
- `message` (string, optional) — Human-readable message about the result
- `totalRows` (integer, optional) — Total number of contacts in the request
- `validRows` (integer, optional) — Number of valid contacts that were processed
- `invalidRows` (integer, optional) — Number of invalid contacts that were rejected
- `batchId` (integer, optional) — ID of the created or updated batch
- `contactsInserted` (integer, optional) — Number of contacts successfully added to the batch
- `data` (list of map from string to any, optional) — Array of valid contact data that was processed
- `errors` (list of BatchResponseErrorsItems, optional) — Array of validation errors (only present if status is error)

## Errors

### 400 Bad Request Error

Validation error or batch creation failed

- `status` (enum, optional) — Status of the batch creation
  - Allowed values: `success`, `error`
- `message` (string, optional) — Human-readable message about the result
- `totalRows` (integer, optional) — Total number of contacts in the request
- `validRows` (integer, optional) — Number of valid contacts that were processed
- `invalidRows` (integer, optional) — Number of invalid contacts that were rejected
- `batchId` (integer, optional) — ID of the created or updated batch
- `contactsInserted` (integer, optional) — Number of contacts successfully added to the batch
- `data` (list of map from string to any, optional) — Array of valid contact data that was processed
- `errors` (list of BatchResponseErrorsItems, optional) — Array of validation errors (only present if status is error)

### 401 Unauthorized Error

Unauthorized - Invalid or missing API key

- `error` (string, optional)
- `message` (string, optional)

### 404 Not Found Error

Agent not found or does not belong to customer

- `error` (string, optional)
- `message` (string, optional)

## Types

### CreateBatchRequestContactsItems

- `contact_name` (string, required) — Contact name (required, must contain only alphabets, spaces, and periods)
- `contact_phone` (string, required) — Contact phone number (required, 10 digits for India, or any numeric value if country_code is provided)
- `country_code` (string, optional) — Country code (optional, 1-4 digits)

### BatchResponseErrorsItems

- `row` (integer, optional) — Row number (1-based) where the error occurred
- `field` (string, optional) — Field name that has the error
- `value` (string, optional) — Value that caused the error
- `message` (string, optional) — Error message

## Examples

**Request**

```json
{
  "agent_id": "123e4567-e89b-12d3-a456-426614174000",
  "batch_name": "Customer Follow-up Batch",
  "contacts": [
    {
      "contact_name": "John Doe",
      "contact_phone": "1234567890",
      "country_code": "91",
      "company": "Acme Corp",
      "email": "john@example.com"
    },
    {
      "contact_name": "Jane Smith",
      "contact_phone": "9876543210",
      "country_code": "91"
    }
  ]
}
```

**Response**

```json
{
  "status": "success",
  "message": "Successfully created batch \"Customer Follow-up Batch\" with 2 contacts.",
  "totalRows": 2,
  "validRows": 2,
  "invalidRows": 0,
  "batchId": 123,
  "contactsInserted": 2,
  "data": [
    {
      "company": "Acme Corp",
      "contact_name": "John Doe",
      "contact_phone": "1234567890",
      "country_code": "91",
      "email": "john@example.com"
    },
    {
      "contact_name": "Jane Smith",
      "contact_phone": "9876543210",
      "country_code": "91"
    }
  ]
}
```

**SDK Code**

```python Batches_createBatch_example
import requests

url = "https://v1.getraya.app/api/batch"

payload = {
    "agent_id": "123e4567-e89b-12d3-a456-426614174000",
    "batch_name": "Customer Follow-up Batch",
    "contacts": [
        {
            "contact_name": "John Doe",
            "contact_phone": "1234567890",
            "country_code": "91",
            "company": "Acme Corp",
            "email": "john@example.com"
        },
        {
            "contact_name": "Jane Smith",
            "contact_phone": "9876543210",
            "country_code": "91"
        }
    ]
}
headers = {
    "X-API-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript Batches_createBatch_example
const url = 'https://v1.getraya.app/api/batch';
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"agent_id":"123e4567-e89b-12d3-a456-426614174000","batch_name":"Customer Follow-up Batch","contacts":[{"contact_name":"John Doe","contact_phone":"1234567890","country_code":"91","company":"Acme Corp","email":"john@example.com"},{"contact_name":"Jane Smith","contact_phone":"9876543210","country_code":"91"}]}'
};

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

```go Batches_createBatch_example
package main

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

func main() {

	url := "https://v1.getraya.app/api/batch"

	payload := strings.NewReader("{\n  \"agent_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n  \"batch_name\": \"Customer Follow-up Batch\",\n  \"contacts\": [\n    {\n      \"contact_name\": \"John Doe\",\n      \"contact_phone\": \"1234567890\",\n      \"country_code\": \"91\",\n      \"company\": \"Acme Corp\",\n      \"email\": \"john@example.com\"\n    },\n    {\n      \"contact_name\": \"Jane Smith\",\n      \"contact_phone\": \"9876543210\",\n      \"country_code\": \"91\"\n    }\n  ]\n}")

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

	req.Header.Add("X-API-Key", "<apiKey>")
	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 Batches_createBatch_example
require 'uri'
require 'net/http'

url = URI("https://v1.getraya.app/api/batch")

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

request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"agent_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n  \"batch_name\": \"Customer Follow-up Batch\",\n  \"contacts\": [\n    {\n      \"contact_name\": \"John Doe\",\n      \"contact_phone\": \"1234567890\",\n      \"country_code\": \"91\",\n      \"company\": \"Acme Corp\",\n      \"email\": \"john@example.com\"\n    },\n    {\n      \"contact_name\": \"Jane Smith\",\n      \"contact_phone\": \"9876543210\",\n      \"country_code\": \"91\"\n    }\n  ]\n}"

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

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

HttpResponse<String> response = Unirest.post("https://v1.getraya.app/api/batch")
  .header("X-API-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"agent_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n  \"batch_name\": \"Customer Follow-up Batch\",\n  \"contacts\": [\n    {\n      \"contact_name\": \"John Doe\",\n      \"contact_phone\": \"1234567890\",\n      \"country_code\": \"91\",\n      \"company\": \"Acme Corp\",\n      \"email\": \"john@example.com\"\n    },\n    {\n      \"contact_name\": \"Jane Smith\",\n      \"contact_phone\": \"9876543210\",\n      \"country_code\": \"91\"\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1.getraya.app/api/batch', [
  'body' => '{
  "agent_id": "123e4567-e89b-12d3-a456-426614174000",
  "batch_name": "Customer Follow-up Batch",
  "contacts": [
    {
      "contact_name": "John Doe",
      "contact_phone": "1234567890",
      "country_code": "91",
      "company": "Acme Corp",
      "email": "john@example.com"
    },
    {
      "contact_name": "Jane Smith",
      "contact_phone": "9876543210",
      "country_code": "91"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-Key' => '<apiKey>',
  ],
]);

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

```csharp Batches_createBatch_example
using RestSharp;

var client = new RestClient("https://v1.getraya.app/api/batch");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"agent_id\": \"123e4567-e89b-12d3-a456-426614174000\",\n  \"batch_name\": \"Customer Follow-up Batch\",\n  \"contacts\": [\n    {\n      \"contact_name\": \"John Doe\",\n      \"contact_phone\": \"1234567890\",\n      \"country_code\": \"91\",\n      \"company\": \"Acme Corp\",\n      \"email\": \"john@example.com\"\n    },\n    {\n      \"contact_name\": \"Jane Smith\",\n      \"contact_phone\": \"9876543210\",\n      \"country_code\": \"91\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift Batches_createBatch_example
import Foundation

let headers = [
  "X-API-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "agent_id": "123e4567-e89b-12d3-a456-426614174000",
  "batch_name": "Customer Follow-up Batch",
  "contacts": [
    [
      "contact_name": "John Doe",
      "contact_phone": "1234567890",
      "country_code": "91",
      "company": "Acme Corp",
      "email": "john@example.com"
    ],
    [
      "contact_name": "Jane Smith",
      "contact_phone": "9876543210",
      "country_code": "91"
    ]
  ]
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://v1.getraya.app/api/batch")! 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()
```