> This is a page from the ElevenLabs documentation. For a complete page index, fetch https://elevenlabs.io/docs/llms.txt. For the full documentation in a single file, fetch https://elevenlabs.io/docs/llms-full.txt.

# 替换外呼活动配置

PUT https://api.elevenlabs.io/v1/convai/outbound-campaigns/config
Content-Type: application/json

创建或替换工作区的外呼活动配置。将上次读取的 `version` 作为 `expected_version` 发送，或省略它以创建首个配置。自读取后已变更的配置不会被替换。活动会保留启动时使用的策略。

Reference: https://elevenlabs.io/docs/api-reference/campaigns/config/update

## Servers

- `https://api.elevenlabs.io` (Production, default)
- `https://api.us.elevenlabs.io` (Production US)
- `https://api.eu.residency.elevenlabs.io` (Production EU)
- `https://api.in.residency.elevenlabs.io` (Production India)
- `https://api.sg.residency.elevenlabs.io` (Production Singapore)

## Request

### Body (application/json)

This endpoint expects a ReplaceWorkspaceConfigRequest.

- `config` (CampaignConfig-Input, required)
- `expected_version` (integer, optional, nullable) — 要替换的配置的 `version`。仅在创建首个配置时省略。

## Response

### 200

成功响应

- `version` (integer, required) — 每次替换都会递增；将其作为 `expected_version` 发送。
- `config` (CampaignConfig-Output, required)

## Errors

### 422 Unprocessable Entity Error

验证错误。

- `detail` (list of ValidationError, optional)

## Types

### CampaignConfig-Input

- `policy` (PolicyConfig-Input, optional) — 除非活动自行设置，否则采用的策略。
- `agent_policies` (map from string to AgentPolicyOverride-Input, optional) — 以智能体 ID 为键的 `policy` 覆盖设置。
- `whatsapp_voice_policy` (AgentPolicyOverride-Input, optional, nullable) — WhatsApp 语音活动的覆盖设置，优先级介于工作区策略和智能体覆盖设置之间。省略的部分遵循 WhatsApp 语音的内置默认值。

### CampaignConfig-Output

- `policy` (PolicyConfig-Output, optional) — 除非活动自行设置，否则采用的策略。
- `agent_policies` (map from string to AgentPolicyOverride-Output, optional) — 以智能体 ID 为键的 `policy` 覆盖设置。
- `whatsapp_voice_policy` (AgentPolicyOverride-Output, optional, nullable) — WhatsApp 语音活动的覆盖设置，优先级介于工作区策略和智能体覆盖设置之间。省略的部分遵循 WhatsApp 语音的内置默认值。

### ValidationError

- `loc` (list of ValidationErrorLocItems, required)
- `msg` (string, required)
- `type` (string, required)

### PolicyConfig-Input

- `timezone` (string, optional, default: UTC) — 读取呼叫时段所用的 IANA 时区。
- `retry` (RetryPolicy, optional)
- `calling_periods` (list of CallingPeriod, optional) — 每周可发起呼叫的时间窗口。
- `data_collection` (DataCollectionConfig, optional) — 引导后续呼叫的智能体数据收集项。每项默认使用其用途对应的内置项目；`null` 会将其关闭。
- `followup_context` (FollowupContextPolicy, optional) — 后续呼叫会获取哪些 `campaign__` 动态变量。

### AgentPolicyOverride-Input

此处设置的每个部分都会替换策略中对应的整个部分。

- `timezone` (string, optional, nullable)
- `retry` (RetryPolicy, optional, nullable)
- `calling_periods` (list of CallingPeriod, optional, nullable)
- `data_collection` (DataCollectionConfig, optional, nullable) — 引导后续呼叫的智能体数据收集项。每项默认使用其用途对应的内置项目；`null` 会将其关闭。
- `followup_context` (FollowupContextPolicy, optional, nullable) — 后续呼叫会获取哪些 `campaign__` 动态变量。

### PolicyConfig-Output

- `timezone` (string, optional, default: UTC) — 读取呼叫时段所用的 IANA 时区。
- `retry` (RetryPolicy, optional)
- `calling_periods` (list of CallingPeriod, optional) — 每周可发起呼叫的时间窗口。
- `data_collection` (DataCollectionConfig, optional) — 引导后续呼叫的智能体数据收集项。每项默认使用其用途对应的内置项目；`null` 会将其关闭。
- `followup_context` (FollowupContextPolicy, optional) — 后续呼叫会获取哪些 `campaign__` 动态变量。

### AgentPolicyOverride-Output

此处设置的每个部分都会替换策略中对应的整个部分。

- `timezone` (string, optional, nullable)
- `retry` (RetryPolicy, optional, nullable)
- `calling_periods` (list of CallingPeriod, optional, nullable)
- `data_collection` (DataCollectionConfig, optional, nullable) — 引导后续呼叫的智能体数据收集项。每项默认使用其用途对应的内置项目；`null` 会将其关闭。
- `followup_context` (FollowupContextPolicy, optional, nullable) — 后续呼叫会获取哪些 `campaign__` 动态变量。

### ValidationErrorLocItems

- string
- integer

### RetryPolicy

- `retry_delay_seconds` (integer, optional, default: 600) — 短暂重试前的等待时间。
- `max_short_retries` (integer, optional, default: 1) — 呼叫失败后，一个呼叫时段允许的重试次数。用完后，下次重试会等待下一个时段，并重新开始计算。
- `max_total_calls` (integer, optional, default: 6) — 每位潜在客户最多接收的呼叫次数，包括首次呼叫。
- `max_callbacks` (integer, optional, default: 2) — 同一号码最多可执行的回拨次数。
- `max_redirects` (integer, optional, default: 2) — 潜在客户按请求改拨其他号码的最大次数。
- `interval_placement` (enum, optional, default: start) — 延后的呼叫在后续呼叫时间窗口中的安排位置：在其 `start` 时开始、在 `random` 时间开始，或在该窗口中上次呼叫失败位置之后 `rotate` `rotate_step_seconds`。
  - Allowed values: `start`, `random`, `rotate`
- `rotate_step_seconds` (integer, optional, default: 900) — `rotate` 排序中每次呼叫移动的距离。仅由 `rotate` 使用。
- `max_consecutive_failures_per_number` (integer, optional, nullable) — 在潜在客户转而呼叫列表中的下一个号码前，向同一号码连续失败的最大呼叫次数；若没有下一个号码，则结束。呼叫被接听或重定向到新号码时，计数会重置。未设置时仅使用 `max_total_calls`。

### CallingPeriod

- `weekdays` (list of integer, required) — 时间段适用的日期，从 `0`（星期一）到 `6`（星期日）。
- `intervals` (list of CallingIntervalPolicy, required) — 这些日期每天的时间窗口。任何一天的时间窗口均不得重叠。

### DataCollectionConfig

引导后续呼叫的智能体数据收集项。每项默认使用其用途对应的内置项目；`null` 会将其关闭。

- `callback_time` (string, optional, nullable, default: __system_data_collection_callback_time) — 存放联系人请求回拨时间的项目。
- `redirect_phone_number` (string, optional, nullable, default: __system_data_collection_redirect_phone_number) — 存放联系人请求改拨号码的项目。
- `stop` (string, optional, nullable, default: __system_data_collection_do_not_call) — 当联系人请求不再被呼叫时为 true 的项目。
- `mappings` (map from string to string, optional) — 将数据收集结果复制到动态变量，以供后续呼叫使用：每个键为数据收集项 ID，值为变量名称。

### FollowupContextPolicy

后续呼叫会获取哪些 `campaign__` 动态变量。

- `call_type` (boolean, optional, default: true) — 将呼叫类型作为 `campaign__call_type` 传递。
- `previous_conversation_id` (boolean, optional, default: true) — 将上次对话的 ID 作为 `campaign__previous_conversation_id` 传递。
- `previous_summary` (boolean, optional, default: true) — 将上次对话的摘要作为 `campaign__previous_summary` 传递。
- `previous_transcript` (boolean, optional, default: true) — 将上次对话的转录文本作为 `campaign__previous_transcript` 传递。

### CallingIntervalPolicy

- `start` (string, required) — 本地开始时间，格式为 `HH:MM`。
- `end` (string, required) — 本地结束时间，格式为 `HH:MM`；`24:00` 表示在午夜结束。

## Examples

**Request**

```json
{}
```

**Response**

```json
{
  "version": 1,
  "config": {
    "policy": {
      "timezone": "UTC",
      "retry": {
        "retry_delay_seconds": 600,
        "max_short_retries": 1,
        "max_total_calls": 6,
        "max_callbacks": 2,
        "max_redirects": 2,
        "interval_placement": "start",
        "rotate_step_seconds": 900,
        "max_consecutive_failures_per_number": 1
      },
      "calling_periods": [
        {
          "weekdays": [
            1
          ],
          "intervals": [
            {
              "start": "string",
              "end": "string"
            }
          ]
        }
      ],
      "data_collection": {
        "callback_time": "string",
        "redirect_phone_number": "string",
        "stop": "string",
        "mappings": {}
      },
      "followup_context": {
        "call_type": true,
        "previous_conversation_id": true,
        "previous_summary": true,
        "previous_transcript": true
      }
    },
    "agent_policies": {},
    "whatsapp_voice_policy": {
      "timezone": "string",
      "retry": {
        "retry_delay_seconds": 600,
        "max_short_retries": 1,
        "max_total_calls": 6,
        "max_callbacks": 2,
        "max_redirects": 2,
        "interval_placement": "start",
        "rotate_step_seconds": 900,
        "max_consecutive_failures_per_number": 1
      },
      "calling_periods": [
        {
          "weekdays": [
            1
          ],
          "intervals": [
            {
              "start": "string",
              "end": "string"
            }
          ]
        }
      ],
      "data_collection": {
        "callback_time": "string",
        "redirect_phone_number": "string",
        "stop": "string",
        "mappings": {}
      },
      "followup_context": {
        "call_type": true,
        "previous_conversation_id": true,
        "previous_summary": true,
        "previous_transcript": true
      }
    }
  }
}
```

**SDK Code**

```python
import requests

url = "https://api.elevenlabs.io/v1/convai/outbound-campaigns/config"

payload = {}
headers = {"Content-Type": "application/json"}

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

print(response.json())
```

```javascript
const url = 'https://api.elevenlabs.io/v1/convai/outbound-campaigns/config';
const options = {method: 'PUT', headers: {'Content-Type': 'application/json'}, body: '{}'};

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.elevenlabs.io/v1/convai/outbound-campaigns/config"

	payload := strings.NewReader("{}")

	req, _ := http.NewRequest("PUT", 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
require 'uri'
require 'net/http'

url = URI("https://api.elevenlabs.io/v1/convai/outbound-campaigns/config")

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

request = Net::HTTP::Put.new(url)
request["Content-Type"] = 'application/json'
request.body = "{}"

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.put("https://api.elevenlabs.io/v1/convai/outbound-campaigns/config")
  .header("Content-Type", "application/json")
  .body("{}")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('PUT', 'https://api.elevenlabs.io/v1/convai/outbound-campaigns/config', [
  'body' => '{}',
  'headers' => [
    'Content-Type' => 'application/json',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.elevenlabs.io/v1/convai/outbound-campaigns/config");
var request = new RestRequest(Method.PUT);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", "{}", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = ["Content-Type": "application/json"]
let parameters = [] as [String : Any]

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

let request = NSMutableURLRequest(url: NSURL(string: "https://api.elevenlabs.io/v1/convai/outbound-campaigns/config")! as URL,
                                        cachePolicy: .useProtocolCachePolicy,
                                    timeoutInterval: 10.0)
request.httpMethod = "PUT"
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()
```