> This page is for Voice AI Platform.

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

# Create Batch

POST https://api.hams.ai/outbound-batch/batches
Content-Type: application/json

Reference: https://docs.hams.ai/platform/reference/outbound-batch/create-batch-outbound-batch-batches-post

## Authentication

- `X-Secret-Key` header (required) — A secret API key (`sk_...`) for server-to-server calls. The entity is derived from the key.

## Request

### Body (application/json)

This endpoint expects a CreateBatchIn.

- `extension_id` (string, required)
- `leads` (list of LeadIn, required)
- `name` (string, required)
- `scheduled_date` (datetime, required)
- `fetch_limit` (integer, optional, default: 20)
- `is_draft` (boolean, optional, default: false) — Create the batch as a DRAFT (not dialed) until it is published via POST /batches/\{id}/publish.
- `max_attempts_per_lead` (integer, optional, default: 3)
- `webhook` (BatchWebhookIn, optional, nullable)

## Response

### 201

Successful Response

- `any`

## Errors

### 422 Unprocessable Entity Error

Validation Error

- `detail` (list of ValidationError, optional)

## Types

### LeadIn

- `number` (string, required)
- `dynamic_variables` (map from string to string, optional)

### BatchWebhookIn

- `url` (string, required) — URL to receive webhook requests
- `events` (list of enum, optional, default: ["outbound_lead_status_changed"]) — Events to subscribe to (batch scope currently dispatches only outbound_lead_status_changed)
  - Allowed values: `call_started`, `call_ended`, `call_analyzed`, `call_rated`, `chat_started`, `chat_ended`, `chat_analyzed`, `outbound_lead_status_changed`
- `headers` (map from string to string, optional, nullable) — Custom headers to include in webhook requests
- `max_retries` (integer, optional, default: 3) — Maximum retry attempts on failure
- `method` (enum, optional, default: POST) — HTTP method for webhook requests
  - Allowed values: `POST`, `PUT`, `PATCH`
- `signing_secret` (string, optional, nullable) — HMAC-SHA256 signing secret for payload verification
- `timeout_seconds` (integer, optional, default: 10) — Request timeout in seconds

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)
- `ctx` (ValidationErrorCtx, optional)
- `input` (any, optional)

### ValidationErrorLocItems

- string
- integer

### ValidationErrorCtx

## Examples

**Request**

```json
{
  "extension_id": "string",
  "leads": [
    {
      "number": "string"
    }
  ],
  "name": "string",
  "scheduled_date": "2024-01-15T09:30:00Z"
}
```

**SDK Code**

```python
import requests

url = "https://api.hams.ai/outbound-batch/batches"

payload = {
    "extension_id": "string",
    "leads": [{ "number": "string" }],
    "name": "string",
    "scheduled_date": "2024-01-15T09:30:00Z"
}
headers = {
    "X-Secret-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript
const url = 'https://api.hams.ai/outbound-batch/batches';
const options = {
  method: 'POST',
  headers: {'X-Secret-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"extension_id":"string","leads":[{"number":"string"}],"name":"string","scheduled_date":"2024-01-15T09:30:00Z"}'
};

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://api.hams.ai/outbound-batch/batches"

	payload := strings.NewReader("{\n  \"extension_id\": \"string\",\n  \"leads\": [\n    {\n      \"number\": \"string\"\n    }\n  ],\n  \"name\": \"string\",\n  \"scheduled_date\": \"2024-01-15T09:30:00Z\"\n}")

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

	req.Header.Add("X-Secret-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://api.hams.ai/outbound-batch/batches")

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

request = Net::HTTP::Post.new(url)
request["X-Secret-Key"] = '<apiKey>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"extension_id\": \"string\",\n  \"leads\": [\n    {\n      \"number\": \"string\"\n    }\n  ],\n  \"name\": \"string\",\n  \"scheduled_date\": \"2024-01-15T09:30:00Z\"\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://api.hams.ai/outbound-batch/batches")
  .header("X-Secret-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"extension_id\": \"string\",\n  \"leads\": [\n    {\n      \"number\": \"string\"\n    }\n  ],\n  \"name\": \"string\",\n  \"scheduled_date\": \"2024-01-15T09:30:00Z\"\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.hams.ai/outbound-batch/batches', [
  'body' => '{
  "extension_id": "string",
  "leads": [
    {
      "number": "string"
    }
  ],
  "name": "string",
  "scheduled_date": "2024-01-15T09:30:00Z"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-Secret-Key' => '<apiKey>',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.hams.ai/outbound-batch/batches");
var request = new RestRequest(Method.POST);
request.AddHeader("X-Secret-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"extension_id\": \"string\",\n  \"leads\": [\n    {\n      \"number\": \"string\"\n    }\n  ],\n  \"name\": \"string\",\n  \"scheduled_date\": \"2024-01-15T09:30:00Z\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "X-Secret-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "extension_id": "string",
  "leads": [["number": "string"]],
  "name": "string",
  "scheduled_date": "2024-01-15T09:30:00Z"
] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.hams.ai/outbound-batch/batches")! 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()
```