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

# Create a campaign from CSV or XLSX

POST https://api.rasen.ai/v1/campaigns/upload
Content-Type: multipart/form-data

Create a campaign from CSV or XLSX.

Reference: https://docs.rasen.ai/enterprise/api-reference/campaigns/upload-campaign

## Authentication

- `Authorization` header (bearer token, required) — An organisation-owned key whose secret starts ra_org_. The Owner or an Admin of an organisation that Rasen has invited makes it in the app; no API operation makes, changes, rotates or revokes a key. On a workspace operation send the workspace ID in the Rasen-Workspace header; without it the answer is 400 invalid_request with details.field Rasen-Workspace. A workspace outside the organisation or outside the key's workspace list is 404 not_found. An organisation that is not invited gets 403 organisation_api_not_enabled.

## Request

### Headers

- `Idempotency-Key` (string, required) — Stable key per logical intent, 1–255 printable characters. Persist it before sending. Retry the same key/body after an uncertain result for 24 hours. A changed body conflicts. Beyond retention, reconcile the resource before retrying; this is not permanent deduplication. Current authorization is rechecked on replay. Evaluation order: authenticate and check current authorization; look up intent; replay its stored receipt before checking the current revision; only a new intent evaluates If-Match and executes. Fingerprint includes method, path, body and original If-Match. A changed request returns idempotency_key_reused. The server stores only a keyed (HMAC) fingerprint, and no error or response ever returns a fingerprint or hash of a request. In-flight intent returns 409 idempotency_in_progress with Retry-After; retry the same intent after reconciliation. Receipts describe that attempt, not current resource state. A replay returns the original status code and body, with the response header Idempotent-Replayed: true.
- `Rasen-Workspace` (string, required) — The ID of the workspace that this operation acts in. It must be a workspace of the key's organisation and in the key's workspace list. A missing, empty or malformed value is 400 invalid_request with details.field Rasen-Workspace; a workspace outside the organisation or the key's workspace list is the hidden 404 not_found.

### Body (multipart/form-data)

This endpoint expects a multipart form containing a file.

- `recipients` (file, required)
- `agent_id` (string, required)
- `name` (string, required)
- `from_phone_number_id` (string, optional)
- `max_attempts_per_recipient` (integer, optional)
- `max_concurrent_calls` (integer, optional)
- `ringing_timeout_seconds` (integer, optional)
- `retry_backoff_ms` (integer, optional)
- `dialing_time_zone` (string, optional)
- `window_start_at` (datetime, optional)
- `window_end_at` (datetime, optional)
- `daily_opens_minute` (integer, optional)
- `daily_closes_minute` (integer, optional)
- `recipient_edits` (string, optional)

## Response

### 201

Create a campaign from CSV or XLSX.

- `id` (string, required)
- `revision` (string, required)
- `agent_id` (string, required)
- `name` (string, required)
- `state` (string, required)
- `recipient_count` (integer, required)
- `max_attempts_per_recipient` (integer, required)
- `retry_backoff_ms` (integer, required)
- `max_concurrent_calls` (integer, required)
- `dialing_time_zone` (string, required)
- `created_at` (datetime, required)
- `updated_at` (datetime, required)
- `ringing_timeout_seconds` (integer, optional, nullable)
- `from_phone_number_id` (string, optional, nullable)
- `window_start_at` (datetime, optional, nullable)
- `window_end_at` (datetime, optional, nullable)
- `daily_opens_minute` (integer, optional, nullable)
- `daily_closes_minute` (integer, optional, nullable)
- `quota_checked_at` (datetime, optional, nullable)
- `failure_reason` (string, optional, nullable)
- `started_at` (datetime, optional, nullable)
- `ended_at` (datetime, optional, nullable)
- `uploaded_recipient_count` (integer, optional, nullable)
- `duplicates_removed` (integer, optional, nullable)
- `import_report` (map from string to any, optional, nullable)

## Errors

### 400 Bad Request Error

Invalid input or cursor. Correct the request.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 401 Unauthorized Error

Invalid, expired or revoked API key. Creator departure or membership changes do not invalidate a workspace key.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 403 Forbidden Error

Operation not allowed by current credential or workspace access.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 404 Not Found Error

Resource absent or not visible in this workspace.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 409 Conflict Error

Conflict. Not retryable: read the current state, fix the request and send a new request. The one exception is idempotency_in_progress, which carries Retry-After: wait, then resend the identical request with the same Idempotency-Key. The operation lists its codes in x-error-codes; branch on error.code and, for conflict, error.details.reason.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 413 Content Too Large Error

Body or upload exceeds its allowed limit.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 422 Unprocessable Entity Error

The request is well formed but refused, for example a destination that is not a permitted public address.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 428 Precondition Error

Required If-Match revision is absent.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 429 Too Many Requests Error

Rate limited. Respect Retry-After and retry the same intent where permitted.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 500 Internal Server Error

Internal error. The effect may have happened. Retry the same request with the same Idempotency-Key; read the resource before creating a new intent. For an operation that takes an Idempotency-Key, a client retry with the same key is safe: the server replays the stored outcome if the first attempt took effect; if the first attempt had no effect, the retry performs the operation once. Never retry with a new key.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

### 503 Service Unavailable Error

Service unavailable. Respect Retry-After where present. For an operation that takes an Idempotency-Key, a client retry with the same key is safe: the server replays the stored outcome if the first attempt took effect; if the first attempt had no effect, the retry performs the operation once. Never retry with a new key.

- `error` (ErrorResponseError, required) — Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

## Types

### ErrorResponseError

Only code and message are required. Rasen sends details, request_id and retry on every error, but clients must parse an error that lacks them, so a typed error is never lost to a parsing failure.

- `code` (string, required) — Stable code. Branch on code (and details.reason for conflict), never on message. Each code has one HTTP status; see components.x-error-catalog.
- `message` (string, required) — Safe description; no provider payload or submitted secrets.
- `details` (map from string to any, optional) — Safe code-specific details. The public fields for each code are listed in components.x-error-catalog. Details never contain a request fingerprint, a hash of a request, secret material or another tenant's data. forbidden may include required_capabilities (a list).
- `request_id` (string, optional) — Same value as the X-Request-Id header. Quote it to support.
- `retry` (string, optional) — Retry class of this code: no (fix the request or state first), yes (retry the same request and the same Idempotency-Key), retry_after (wait for Retry-After, then retry the same request). Open response vocabulary. Preserve unknown values; never assume they mean success.

## Examples

**Request**

```json
{
  "recipients": "<file: string>",
  "agent_id": "string",
  "name": "string"
}
```

**Response**

```json
{
  "id": "string",
  "revision": "string",
  "agent_id": "string",
  "name": "string",
  "state": "string",
  "recipient_count": 1,
  "max_attempts_per_recipient": 1,
  "retry_backoff_ms": 1,
  "max_concurrent_calls": 1,
  "dialing_time_zone": "string",
  "created_at": "2024-01-15T09:30:00Z",
  "updated_at": "2024-01-15T09:30:00Z",
  "ringing_timeout_seconds": 1,
  "from_phone_number_id": "string",
  "window_start_at": "2024-01-15T09:30:00Z",
  "window_end_at": "2024-01-15T09:30:00Z",
  "daily_opens_minute": 1,
  "daily_closes_minute": 1,
  "quota_checked_at": "2024-01-15T09:30:00Z",
  "failure_reason": "string",
  "started_at": "2024-01-15T09:30:00Z",
  "ended_at": "2024-01-15T09:30:00Z",
  "uploaded_recipient_count": 1,
  "duplicates_removed": 1,
  "import_report": {}
}
```

**SDK Code**

```python
import requests

url = "https://api.rasen.ai/v1/campaigns/upload"

files = { "recipients": "open('string', 'rb')" }
payload = {
    "agent_id": "string",
    "name": "string",
    "from_phone_number_id": ,
    "max_attempts_per_recipient": ,
    "max_concurrent_calls": ,
    "ringing_timeout_seconds": ,
    "retry_backoff_ms": ,
    "dialing_time_zone": ,
    "window_start_at": ,
    "window_end_at": ,
    "daily_opens_minute": ,
    "daily_closes_minute": ,
    "recipient_edits": 
}
headers = {
    "Idempotency-Key": "intent-appointment-001",
    "Rasen-Workspace": "ws_01j00000000000000000000000",
    "Authorization": "Bearer <token>"
}

response = requests.post(url, data=payload, files=files, headers=headers)

print(response.json())
```

```javascript
const url = 'https://api.rasen.ai/v1/campaigns/upload';
const form = new FormData();
form.append('recipients', 'string');
form.append('agent_id', 'string');
form.append('name', 'string');
form.append('from_phone_number_id', '');
form.append('max_attempts_per_recipient', '');
form.append('max_concurrent_calls', '');
form.append('ringing_timeout_seconds', '');
form.append('retry_backoff_ms', '');
form.append('dialing_time_zone', '');
form.append('window_start_at', '');
form.append('window_end_at', '');
form.append('daily_opens_minute', '');
form.append('daily_closes_minute', '');
form.append('recipient_edits', '');

const options = {
  method: 'POST',
  headers: {
    'Idempotency-Key': 'intent-appointment-001',
    'Rasen-Workspace': 'ws_01j00000000000000000000000',
    Authorization: 'Bearer <token>'
  }
};

options.body = form;

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

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

url = URI("https://api.rasen.ai/v1/campaigns/upload")

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

request = Net::HTTP::Post.new(url)
request["Idempotency-Key"] = 'intent-appointment-001'
request["Rasen-Workspace"] = 'ws_01j00000000000000000000000'
request["Authorization"] = 'Bearer <token>'
request.body = "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"recipients\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"agent_id\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"from_phone_number_id\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"max_attempts_per_recipient\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"max_concurrent_calls\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ringing_timeout_seconds\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"retry_backoff_ms\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dialing_time_zone\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"window_start_at\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"window_end_at\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"daily_opens_minute\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"daily_closes_minute\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"recipient_edits\"\r\n\r\n\r\n-----011000010111000001101001--\r\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.rasen.ai/v1/campaigns/upload")
  .header("Idempotency-Key", "intent-appointment-001")
  .header("Rasen-Workspace", "ws_01j00000000000000000000000")
  .header("Authorization", "Bearer <token>")
  .body("-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"recipients\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"agent_id\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"from_phone_number_id\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"max_attempts_per_recipient\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"max_concurrent_calls\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ringing_timeout_seconds\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"retry_backoff_ms\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dialing_time_zone\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"window_start_at\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"window_end_at\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"daily_opens_minute\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"daily_closes_minute\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"recipient_edits\"\r\n\r\n\r\n-----011000010111000001101001--\r\n")
  .asString();
```

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

$client = new \GuzzleHttp\Client();

$response = $client->request('POST', 'https://api.rasen.ai/v1/campaigns/upload', [
  'multipart' => [
    [
        'name' => 'recipients',
        'filename' => 'string',
        'contents' => null
    ],
    [
        'name' => 'agent_id',
        'contents' => 'string'
    ],
    [
        'name' => 'name',
        'contents' => 'string'
    ]
  ]
  'headers' => [
    'Authorization' => 'Bearer <token>',
    'Idempotency-Key' => 'intent-appointment-001',
    'Rasen-Workspace' => 'ws_01j00000000000000000000000',
  ],
]);

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

```csharp
using RestSharp;

var client = new RestClient("https://api.rasen.ai/v1/campaigns/upload");
var request = new RestRequest(Method.POST);
request.AddHeader("Idempotency-Key", "intent-appointment-001");
request.AddHeader("Rasen-Workspace", "ws_01j00000000000000000000000");
request.AddHeader("Authorization", "Bearer <token>");
request.AddParameter("undefined", "-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"recipients\"; filename=\"string\"\r\nContent-Type: application/octet-stream\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"agent_id\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"name\"\r\n\r\nstring\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"from_phone_number_id\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"max_attempts_per_recipient\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"max_concurrent_calls\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"ringing_timeout_seconds\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"retry_backoff_ms\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"dialing_time_zone\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"window_start_at\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"window_end_at\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"daily_opens_minute\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"daily_closes_minute\"\r\n\r\n\r\n-----011000010111000001101001\r\nContent-Disposition: form-data; name=\"recipient_edits\"\r\n\r\n\r\n-----011000010111000001101001--\r\n", ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
```

```swift
import Foundation

let headers = [
  "Idempotency-Key": "intent-appointment-001",
  "Rasen-Workspace": "ws_01j00000000000000000000000",
  "Authorization": "Bearer <token>"
]
let parameters = [
  [
    "name": "recipients",
    "fileName": "string"
  ],
  [
    "name": "agent_id",
    "value": "string"
  ],
  [
    "name": "name",
    "value": "string"
  ],
  [
    "name": "from_phone_number_id",
    "value": 
  ],
  [
    "name": "max_attempts_per_recipient",
    "value": 
  ],
  [
    "name": "max_concurrent_calls",
    "value": 
  ],
  [
    "name": "ringing_timeout_seconds",
    "value": 
  ],
  [
    "name": "retry_backoff_ms",
    "value": 
  ],
  [
    "name": "dialing_time_zone",
    "value": 
  ],
  [
    "name": "window_start_at",
    "value": 
  ],
  [
    "name": "window_end_at",
    "value": 
  ],
  [
    "name": "daily_opens_minute",
    "value": 
  ],
  [
    "name": "daily_closes_minute",
    "value": 
  ],
  [
    "name": "recipient_edits",
    "value": 
  ]
]

let boundary = "---011000010111000001101001"

var body = ""
var error: NSError? = nil
for param in parameters {
  let paramName = param["name"]!
  body += "--\(boundary)\r\n"
  body += "Content-Disposition:form-data; name=\"\(paramName)\""
  if let filename = param["fileName"] {
    let contentType = param["content-type"]!
    let fileContent = String(contentsOfFile: filename, encoding: String.Encoding.utf8)
    if (error != nil) {
      print(error as Any)
    }
    body += "; filename=\"\(filename)\"\r\n"
    body += "Content-Type: \(contentType)\r\n\r\n"
    body += fileContent
  } else if let paramValue = param["value"] {
    body += "\r\n\r\n\(paramValue)"
  }
}

let request = NSMutableURLRequest(url: NSURL(string: "https://api.rasen.ai/v1/campaigns/upload")! 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()
```