> ## Documentation Index
> Fetch the complete documentation index at: https://docs.burki.dev/llms.txt
> Use this file to discover all available pages before exploring further.

# Re-execute Campaign

> Re-execute a completed or failed campaign with new contact selection and scheduling.
Preserves all execution history while allowing a fresh run with customizable parameters.

Re-execute a completed, cancelled, or failed campaign with flexible contact selection and scheduling options.

### Path Parameters

* `campaign_id` (integer, required): The unique identifier of the campaign

### Request Body

| Field               | Type            | Required | Description               |
| ------------------- | --------------- | -------- | ------------------------- |
| `contact_selection` | string or array | Yes      | Which contacts to include |
| `schedule_settings` | object          | No       | Scheduling configuration  |

### Contact Selection Options

| Value           | Description                                             |
| --------------- | ------------------------------------------------------- |
| `"all"`         | Reset and re-contact all contacts                       |
| `"failed_only"` | Only retry failed, no\_answer, busy, voicemail contacts |
| `[1, 2, 3]`     | Array of specific contact IDs to retry                  |

### Schedule Settings

```json theme={null}
{
  "schedule_settings": {
    "schedule_type": "immediate",
    "scheduled_at": "2024-02-15T09:00:00Z",
    "timezone": "America/New_York"
  }
}
```

| Field           | Type   | Description                              |
| --------------- | ------ | ---------------------------------------- |
| `schedule_type` | string | `immediate`, `scheduled`, or `recurring` |
| `scheduled_at`  | string | ISO 8601 datetime for scheduled type     |
| `timezone`      | string | Timezone for scheduling                  |

### Example Requests

**Re-execute all contacts immediately:**

```json theme={null}
{
  "contact_selection": "all",
  "schedule_settings": {
    "schedule_type": "immediate"
  }
}
```

**Retry only failed contacts:**

```json theme={null}
{
  "contact_selection": "failed_only",
  "schedule_settings": {
    "schedule_type": "scheduled",
    "scheduled_at": "2024-02-15T09:00:00",
    "timezone": "America/New_York"
  }
}
```

**Retry specific contacts:**

```json theme={null}
{
  "contact_selection": [101, 102, 103],
  "schedule_settings": {
    "schedule_type": "immediate"
  }
}
```

### Response

```json Response (Immediate) theme={null}
{
  "success": true,
  "message": "Campaign ready for re-execution with 150 contacts",
  "campaign_id": 42,
  "contacts_reset": 150,
  "schedule_type": "immediate",
  "status": "draft"
}
```

```json Response (Scheduled) theme={null}
{
  "success": true,
  "message": "Campaign scheduled for re-execution at 2024-02-15 09:00:00 UTC with 50 contacts",
  "campaign_id": 42,
  "contacts_reset": 50,
  "schedule_type": "once",
  "status": "scheduled",
  "scheduled_time": "2024-02-15T09:00:00Z"
}
```

### Example Code

```bash cURL theme={null}
curl -X POST "https://api.burki.dev/api/v1/campaigns/42/re-execute" \
  -H "Authorization: Bearer YOUR_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "contact_selection": "failed_only",
    "schedule_settings": {
      "schedule_type": "immediate"
    }
  }'
```

```python Python theme={null}
import requests

response = requests.post(
    "https://api.burki.dev/api/v1/campaigns/42/re-execute",
    headers={"Authorization": "Bearer YOUR_API_KEY"},
    json={
        "contact_selection": "failed_only",
        "schedule_settings": {
            "schedule_type": "immediate"
        }
    }
)

result = response.json()
print(f"Reset {result['contacts_reset']} contacts for re-execution")
```

```javascript JavaScript theme={null}
const response = await fetch("https://api.burki.dev/api/v1/campaigns/42/re-execute", {
  method: "POST",
  headers: {
    "Authorization": "Bearer YOUR_API_KEY",
    "Content-Type": "application/json"
  },
  body: JSON.stringify({
    contact_selection: "failed_only",
    schedule_settings: {
      schedule_type: "immediate"
    }
  })
});

const result = await response.json();
console.log(`Reset ${result.contacts_reset} contacts for re-execution`);
```

### Behavior

When re-executing a campaign:

1. **Selected contacts** are reset to `pending` status
2. **Non-selected contacts** are marked as `skipped`
3. **Campaign counters** are reset to 0
4. **Metrics** are cleared for fresh tracking
5. **Execution history** is preserved for audit
6. **Campaign status** becomes `draft` (immediate) or `scheduled`

### Error Responses

| Status Code | Description                                |
| ----------- | ------------------------------------------ |
| 400         | Campaign status doesn't allow re-execution |
| 400         | No contacts match the selection criteria   |
| 400         | Scheduled time is in the past              |
| 404         | Campaign not found                         |

### Valid Starting Statuses

Re-execution is only available for:

* `completed` - All contacts processed
* `cancelled` - Campaign was stopped
* `failed` - Campaign encountered an error


## OpenAPI

````yaml POST /api/v1/campaigns/{campaign_id}/re-execute
openapi: 3.1.0
info:
  title: Burki
  description: A system that uses AI to answer customer Calls.
  version: 0.1.0
servers: []
security: []
paths:
  /api/v1/campaigns/{campaign_id}/re-execute:
    post:
      tags:
        - campaigns
      summary: Re Execute Campaign
      description: >-
        Re-execute a completed or failed campaign with new contact selection and
        scheduling.

        Preserves all execution history while allowing a fresh run with
        customizable parameters.
      operationId: re_execute_campaign_api_v1_campaigns__campaign_id__re_execute_post
      parameters:
        - name: campaign_id
          in: path
          required: true
          schema:
            type: integer
            title: Campaign Id
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              additionalProperties: true
              title: Re Execute Data
      responses:
        '200':
          description: Successful Response
          content:
            application/json:
              schema: {}
        '422':
          description: Validation Error
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/HTTPValidationError'
      security:
        - HTTPBearer: []
components:
  schemas:
    HTTPValidationError:
      properties:
        detail:
          items:
            $ref: '#/components/schemas/ValidationError'
          type: array
          title: Detail
      type: object
      title: HTTPValidationError
    ValidationError:
      properties:
        loc:
          items:
            anyOf:
              - type: string
              - type: integer
          type: array
          title: Location
        msg:
          type: string
          title: Message
        type:
          type: string
          title: Error Type
      type: object
      required:
        - loc
        - msg
        - type
      title: ValidationError
  securitySchemes:
    HTTPBearer:
      type: http
      scheme: bearer

````