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

# Cancel contacts

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

Stops calls to some contacts of a batch while the rest of the batch keeps running. Use it when a contact has already answered you another way (for example on WhatsApp) and no longer needs the call.

Name the contacts either by `phones` (the numbers you added them with) or by `contact_ids` (from Get batch contacts), up to 500 per request. Phones follow the same rules as adding contacts: a 10-digit number for India, or any number with `country_code` (one country code per request).

A contact still waiting for its call (status `Pending`, or `Unanswered` and waiting for a retry) is cancelled, and so is any callback booked for it. Its status becomes `Cancelled` and the batch never calls it again. It stays in the batch and in its contact list.

Each phone or ID gets one result:
- `cancelled`: it will not be called.
- `in_call`: it is being called right now. That call is not cut. If you still want no further calls, send the request again after the call ends.
- `already_done`: there is no call left to stop (the contact is `Completed`, `Failed`, `Invalid` or already `Cancelled`).
- `not_found`: the batch has no contact with this phone or ID.

If a phone is in the batch more than once, every contact with that phone is cancelled, and the result is `in_call` if any of them is on a call. `counts` adds up the results.

A cancel can't be undone through the API. To call a cancelled contact again, add it to the batch again.

Reference: https://docs.getraya.app/api-reference/batches/cancel-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 a CancelBatchContactsRequest.

- `phones` (list of string, optional) — Phone numbers as you added them: 10 digits for India, or any digits with `country_code`.
- `country_code` (string, optional) — Country code for every phone in `phones` (1 to 4 digits, no "+"). Leave it out for Indian 10-digit numbers.
- `contact_ids` (list of integer, optional) — Contact IDs from Get batch contacts.

## Response

### 200

One result per phone or contact ID, plus counts

- `batch_id` (integer, optional)
- `results` (list of CancelBatchContactsResponseResultsItems, optional) — One entry per phone or contact ID sent, in the order sent (repeated values are listed once).
- `counts` (CancelBatchContactsResponseCounts, optional)

## Errors

### 400 Bad Request Error

Invalid request: neither or both of phones and contact_ids, more than 500 entries, or a phone that breaks the rules

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

### 404 Not Found Error

Batch not found

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

## Types

### CancelBatchContactsResponseResultsItems

- `result` (enum, required)
  - Allowed values: `cancelled`, `in_call`, `already_done`, `not_found`
- `phone` (string, optional) — Present when you sent phones.
- `contact_ids` (list of integer, optional) — Present when you sent phones: the batch contacts with this phone (empty when not_found).
- `contact_id` (integer, optional) — Present when you sent contact_ids.

### CancelBatchContactsResponseCounts

- `cancelled` (integer, optional)
- `in_call` (integer, optional)
- `already_done` (integer, optional)
- `not_found` (integer, optional)

## Examples

### Batches_cancelContacts_example

**Response**

```json
{
  "batch_id": 1234,
  "results": [
    {
      "result": "cancelled",
      "phone": "9876543210",
      "contact_ids": [
        184213
      ]
    },
    {
      "result": "in_call",
      "phone": "9123456780",
      "contact_ids": [
        184214
      ]
    }
  ],
  "counts": {
    "cancelled": 1,
    "in_call": 1,
    "already_done": 0,
    "not_found": 0
  }
}
```

**SDK Code**

```python Batches_cancelContacts_example
import requests

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

headers = {"X-API-Key": "<apiKey>"}

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

print(response.json())
```

```javascript Batches_cancelContacts_example
const url = 'https://v1.getraya.app/api/batch/1/contacts/cancel';
const options = {method: 'POST', headers: {'X-API-Key': '<apiKey>'}};

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

```go Batches_cancelContacts_example
package main

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

func main() {

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

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

	req.Header.Add("X-API-Key", "<apiKey>")

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

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

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

}
```

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

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

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

request = Net::HTTP::Post.new(url)
request["X-API-Key"] = '<apiKey>'

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

```java Batches_cancelContacts_example
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/cancel")
  .header("X-API-Key", "<apiKey>")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1.getraya.app/api/batch/1/contacts/cancel', [
  'headers' => [
    'X-API-Key' => '<apiKey>',
  ],
]);

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

```csharp Batches_cancelContacts_example
using RestSharp;

var client = new RestClient("https://v1.getraya.app/api/batch/1/contacts/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-Key", "<apiKey>");
IRestResponse response = client.Execute(request);
```

```swift Batches_cancelContacts_example
import Foundation

let headers = ["X-API-Key": "<apiKey>"]

let request = NSMutableURLRequest(url: NSURL(string: "https://v1.getraya.app/api/batch/1/contacts/cancel")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "POST"
request.allHTTPHeaderFields = headers

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()
```

### By phone (India)

**Request**

```json
{
  "phones": [
    "9876543210",
    "9123456780"
  ]
}
```

**Response**

```json
{
  "batch_id": 1234,
  "results": [
    {
      "result": "cancelled",
      "phone": "9876543210",
      "contact_ids": [
        184213
      ]
    },
    {
      "result": "in_call",
      "phone": "9123456780",
      "contact_ids": [
        184214
      ]
    }
  ],
  "counts": {
    "cancelled": 1,
    "in_call": 1,
    "already_done": 0,
    "not_found": 0
  }
}
```

**SDK Code**

```python By phone (India)
import requests

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

payload = { "phones": ["9876543210", "9123456780"] }
headers = {
    "X-API-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript By phone (India)
const url = 'https://v1.getraya.app/api/batch/1/contacts/cancel';
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"phones":["9876543210","9123456780"]}'
};

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

```go By phone (India)
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"phones\": [\n    \"9876543210\",\n    \"9123456780\"\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 By phone (India)
require 'uri'
require 'net/http'

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

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  \"phones\": [\n    \"9876543210\",\n    \"9123456780\"\n  ]\n}"

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

```java By phone (India)
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/cancel")
  .header("X-API-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"phones\": [\n    \"9876543210\",\n    \"9123456780\"\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1.getraya.app/api/batch/1/contacts/cancel', [
  'body' => '{
  "phones": [
    "9876543210",
    "9123456780"
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-Key' => '<apiKey>',
  ],
]);

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

```csharp By phone (India)
using RestSharp;

var client = new RestClient("https://v1.getraya.app/api/batch/1/contacts/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"phones\": [\n    \"9876543210\",\n    \"9123456780\"\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift By phone (India)
import Foundation

let headers = [
  "X-API-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["phones": ["9876543210", "9123456780"]] as [String : Any]

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

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

### By phone with a country code

**Request**

```json
{
  "phones": [
    "4155550123"
  ],
  "country_code": "1"
}
```

**Response**

```json
{
  "batch_id": 1234,
  "results": [
    {
      "result": "cancelled",
      "phone": "9876543210",
      "contact_ids": [
        184213
      ]
    },
    {
      "result": "in_call",
      "phone": "9123456780",
      "contact_ids": [
        184214
      ]
    }
  ],
  "counts": {
    "cancelled": 1,
    "in_call": 1,
    "already_done": 0,
    "not_found": 0
  }
}
```

**SDK Code**

```python By phone with a country code
import requests

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

payload = {
    "phones": ["4155550123"],
    "country_code": "1"
}
headers = {
    "X-API-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript By phone with a country code
const url = 'https://v1.getraya.app/api/batch/1/contacts/cancel';
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"phones":["4155550123"],"country_code":"1"}'
};

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

```go By phone with a country code
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"phones\": [\n    \"4155550123\"\n  ],\n  \"country_code\": \"1\"\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 By phone with a country code
require 'uri'
require 'net/http'

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

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  \"phones\": [\n    \"4155550123\"\n  ],\n  \"country_code\": \"1\"\n}"

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

```java By phone with a country code
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/cancel")
  .header("X-API-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"phones\": [\n    \"4155550123\"\n  ],\n  \"country_code\": \"1\"\n}")
  .asString();
```

```php By phone with a country code
<?php
require_once('vendor/autoload.php');

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1.getraya.app/api/batch/1/contacts/cancel', [
  'body' => '{
  "phones": [
    "4155550123"
  ],
  "country_code": "1"
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-Key' => '<apiKey>',
  ],
]);

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

```csharp By phone with a country code
using RestSharp;

var client = new RestClient("https://v1.getraya.app/api/batch/1/contacts/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"phones\": [\n    \"4155550123\"\n  ],\n  \"country_code\": \"1\"\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift By phone with a country code
import Foundation

let headers = [
  "X-API-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = [
  "phones": ["4155550123"],
  "country_code": "1"
] as [String : Any]

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

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

### By contact ID

**Request**

```json
{
  "contact_ids": [
    184213,
    184214
  ]
}
```

**Response**

```json
{
  "batch_id": 1234,
  "results": [
    {
      "result": "cancelled",
      "phone": "9876543210",
      "contact_ids": [
        184213
      ]
    },
    {
      "result": "in_call",
      "phone": "9123456780",
      "contact_ids": [
        184214
      ]
    }
  ],
  "counts": {
    "cancelled": 1,
    "in_call": 1,
    "already_done": 0,
    "not_found": 0
  }
}
```

**SDK Code**

```python By contact ID
import requests

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

payload = { "contact_ids": [184213, 184214] }
headers = {
    "X-API-Key": "<apiKey>",
    "Content-Type": "application/json"
}

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

print(response.json())
```

```javascript By contact ID
const url = 'https://v1.getraya.app/api/batch/1/contacts/cancel';
const options = {
  method: 'POST',
  headers: {'X-API-Key': '<apiKey>', 'Content-Type': 'application/json'},
  body: '{"contact_ids":[184213,184214]}'
};

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

```go By contact ID
package main

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

func main() {

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

	payload := strings.NewReader("{\n  \"contact_ids\": [\n    184213,\n    184214\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 By contact ID
require 'uri'
require 'net/http'

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

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  \"contact_ids\": [\n    184213,\n    184214\n  ]\n}"

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

```java By contact ID
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/cancel")
  .header("X-API-Key", "<apiKey>")
  .header("Content-Type", "application/json")
  .body("{\n  \"contact_ids\": [\n    184213,\n    184214\n  ]\n}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://v1.getraya.app/api/batch/1/contacts/cancel', [
  'body' => '{
  "contact_ids": [
    184213,
    184214
  ]
}',
  'headers' => [
    'Content-Type' => 'application/json',
    'X-API-Key' => '<apiKey>',
  ],
]);

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

```csharp By contact ID
using RestSharp;

var client = new RestClient("https://v1.getraya.app/api/batch/1/contacts/cancel");
var request = new RestRequest(Method.POST);
request.AddHeader("X-API-Key", "<apiKey>");
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{\n  \"contact_ids\": [\n    184213,\n    184214\n  ]\n}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift By contact ID
import Foundation

let headers = [
  "X-API-Key": "<apiKey>",
  "Content-Type": "application/json"
]
let parameters = ["contact_ids": [184213, 184214]] as [String : Any]

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

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