> 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.

# Add contacts

POST https://v1.getraya.app/api/batch/{id}/contacts
Content-Type: application/json

Adds contacts to an existing batch. Each contact must have contact_name and contact_phone. Additional fields are stored in agent_args. Customer ID is automatically determined from the API key.

Reference: https://docs.getraya.app/api-reference/batches/add-contacts

## Authentication

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

## Request

### Path parameters

- `id` (integer, required) — The batch ID

### Body (application/json)

This endpoint expects an AddContactsRequest.

- `contacts` (list of AddContactsRequestContactsItems, required) — Array of contact objects. Each contact must have contact_name and contact_phone. Additional fields are allowed.

## Response

### 200

Contacts added 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 update 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)

### 404 Not Found Error

Batch not found or unauthorized

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

## Types

### AddContactsRequestContactsItems

- `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
{
  "contacts": [
    {
      "contact_name": "John Doe",
      "contact_phone": "1234567890",
      "country_code": "91",
      "email": "john@example.com"
    }
  ]
}
```

**Response**

```json
{
  "status": "success",
  "message": "string",
  "totalRows": 1,
  "validRows": 1,
  "invalidRows": 1,
  "batchId": 1,
  "contactsInserted": 1,
  "data": [
    {}
  ],
  "errors": [
    {
      "row": 1,
      "field": "string",
      "value": "string",
      "message": "string"
    }
  ]
}
```

**SDK Code**

```python
import requests

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

payload = { "contacts": [
        {
            "contact_name": "John Doe",
            "contact_phone": "1234567890",
            "country_code": "91",
            "email": "john@example.com"
        }
    ] }
headers = {
    "X-API-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://v1.getraya.app/api/batch/1/contacts';
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"contacts":[{"contact_name":"John Doe","contact_phone":"1234567890","country_code":"91","email":"john@example.com"}]}'
};

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

```go
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"contacts\": [\n    {\n      \"contact_name\": \"John Doe\",\n      \"contact_phone\": \"1234567890\",\n      \"country_code\": \"91\",\n      \"email\": \"john@example.com\"\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
require 'uri'
require 'net/http'

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

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  \"contacts\": [\n    {\n      \"contact_name\": \"John Doe\",\n      \"contact_phone\": \"1234567890\",\n      \"country_code\": \"91\",\n      \"email\": \"john@example.com\"\n    }\n  ]\n}"

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

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

HttpResponse<String> response = Unirest.post("https://v1.getraya.app/api/batch/1/contacts")
  .header("X-API-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"contacts\": [\n    {\n      \"contact_name\": \"John Doe\",\n      \"contact_phone\": \"1234567890\",\n      \"country_code\": \"91\",\n      \"email\": \"john@example.com\"\n    }\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1.getraya.app/api/batch/1/contacts', [
  'body' => '{
  "contacts": [
    {
      "contact_name": "John Doe",
      "contact_phone": "1234567890",
      "country_code": "91",
      "email": "john@example.com"
    }
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-Key' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://v1.getraya.app/api/batch/1/contacts");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"contacts\": [\n    {\n      \"contact_name\": \"John Doe\",\n      \"contact_phone\": \"1234567890\",\n      \"country_code\": \"91\",\n      \"email\": \"john@example.com\"\n    }\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-API-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["contacts": [
    [
      "contact_name": "John Doe",
      "contact_phone": "1234567890",
      "country_code": "91",
      "email": "john@example.com"
    ]
  ]] as [String : Any]

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

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