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

# Migrating from v1 to v2

> Endpoint, request and response differences between /api/v1/crm and /api/v2.

v1 keeps working. Migrate one resource at a time. Both versions use the same API token, so you only change URLs and the way you read responses. See [Versioning and compatibility](https://docs.oktivo.com/api-reference/versioning.md) for scope.

## What changes for every call

| Topic | v1 | v2 |
| - | - | - |
| Base path | `/api/v1/crm` | `/api/v2` |
| Success body | Varies: `data`, `endpoint`, `endpoints`, `logs`, plus the additive `requestId`, `timestamp` and `meta` | `{ success, requestId, timestamp, data, meta? }` |
| Pagination | `pagination` object, `page` and `pageSize` | `meta`. Cursor for calls and events, `page` and `limit` elsewhere. See [Pagination](https://docs.oktivo.com/api-reference/pagination.md) |
| Error body | `{ success, message, code, requestId, errorInfo: { code, message, details? }, errors? }` | `{ success, requestId, error: { code, message, details? } }` |
| Validation error | `400` | `422` |
| Unknown request fields | Mostly ignored | Dropped |
| Ids | `contactUID`, `campaignUID`, `webhookId`, `deliveryId`, `queueId` | One field named `id` per resource |
| Request key style | camelCase | camelCase. snake\_case keys and the legacy names below are still accepted |
| Webhook update | `PUT` | `PATCH` |
| Webhook endpoint delete | `200` with `{ success, message }` | `204` with no body |
| Dates in filters | `YYYY-MM-DD`, IST | ISO 8601 with a UTC offset |

Check `data` for success and `error.code` for failure. In v2 a response with `success: true` always has `data`.

## Endpoint mapping

| v1 | v2 |
| - | - |
| `POST /api/v1/crm/calls` | `POST /api/v2/calls` |
| `POST /api/v1/crm/calls/bulk` | `POST /api/v2/calls/bulk` |
| `GET /api/v1/crm/calls` | `GET /api/v2/calls` |
| `GET /api/v1/crm/calls/{contactUID}` | `GET /api/v2/calls/{id}` |
| `DELETE /api/v1/crm/calls/{contactUID}` | `DELETE /api/v2/calls/{id}` |
| `GET /api/v1/crm/calls/queue` | `GET /api/v2/queue` |
| `GET /api/v1/crm/calls/queue/summary` | `GET /api/v2/queue/summary` |
| `GET /api/v1/crm/calls/queue/{id}` | `GET /api/v2/queue/{id}` |
| `DELETE /api/v1/crm/calls/queue/{id}` | `DELETE /api/v2/queue/{id}` |
| `GET /api/v1/crm/events` | `GET /api/v2/events` |
| `GET /api/v1/crm/events/types` | `GET /api/v2/events/types` |
| `GET /api/v1/crm/events/{eventId}` | `GET /api/v2/events/{id}` |
| `GET, POST /api/v1/crm/webhooks/endpoints` | `GET, POST /api/v2/webhooks/endpoints` |
| `GET, DELETE /api/v1/crm/webhooks/endpoints/{webhookId}` | `GET, DELETE /api/v2/webhooks/endpoints/{id}` |
| `PUT /api/v1/crm/webhooks/endpoints/{webhookId}` | `PATCH /api/v2/webhooks/endpoints/{id}` |
| `POST /api/v1/crm/webhooks/endpoints/{webhookId}/regenerate-secret` | `POST /api/v2/webhooks/endpoints/{id}/regenerate-secret` |
| `POST /api/v1/crm/webhooks/endpoints/test-delivery` | `POST /api/v2/webhooks/endpoints/test-delivery` |
| `GET /api/v1/crm/webhooks/delivery-logs` | `GET /api/v2/webhooks/delivery-logs` |
| `GET /api/v1/crm/webhooks/delivery-logs/{deliveryId}` | `GET /api/v2/webhooks/delivery-logs/{id}` |
| `GET /api/v1/crm/agents` | `GET /api/v2/agents` |
| `POST /api/v1/crm/leads` | `POST /api/v2/leads` |
| `POST /api/v1/crm/tickets` | `POST /api/v2/tickets` |

Not in v2, keep using v1: `/tokens`, `/analysis-schemas`, `/retry-analysis`, `/track`, `/shopify/confirmation-calls`.

## Field mapping

### Create call (`POST /calls`)

Request: the fields are the same (`phone`, `name`, `agentId`, `dynamicVariables`, `retryConfig`, `deferIfUnavailable`, `scheduledAt`). v2 also accepts `phoneNumber` for `phone` and `agent` for `agentId`.

| v1 response | v2 response (`data`) |
| - | - |
| `contactUID` | `id` |
| `campaignUID` | `campaignId` |
| (none) | `status`: `placed` (`201`) |
| `deferredCallId` (`202`) | `queueId` |
| `contactUID` (`202`) | `id` |
| `status`, `reason`, `notBefore` (`202`) | same names, plus `scheduledFor` and `expiresAt` |

A call placed now returns `201`. A scheduled or deferred call returns `202`, as in v1.

### Call (list and get)

| v1 | v2 |
| - | - |
| `contactUID` | `id` |
| `campaignUID` | `campaignId` |
| `callDirection` | `direction` |
| `callDuration` | `durationSeconds` |
| `billingDuration` | `billedSeconds` |
| `createdAt`, `updatedAt` | `createdAt`, `updatedAt` |
| `startedAt`, `answeredAt`, `endedAt` | same names |
| `status`, `callStatus`, `disconnectReason`, `attempts`, `lastError`, `source`, `hasRecording`, `hasTranscription`, `hasAnalysis` | same names |
| `dynamicVariables`, `retryConfig` (get) | same names (get only) |

List filters: `campaignUID` is now `campaignId`, `contactUID` is now `callId`, `agentID` is now `agentId`, `page` and `pageSize` are now `cursor` and `limit`. The old names are still accepted as aliases. A call that only exists in the queue is returned by `GET /calls/{id}` with the same shape.

### Bulk calls (`POST /calls/bulk`)

The request is `{ calls: [...], deferIfUnavailable?, scheduledAt? }`. Item-level `deferIfUnavailable` and `scheduledAt` override the request-level values. The response is always `200`; look at each item:

```json theme={null}
{
  "success": true,
  "data": {
    "summary": { "total": 2, "succeeded": 1, "failed": 1 },
    "results": [
      { "index": 0, "status": "success", "data": { "id": "...", "campaignId": "...", "status": "placed" } },
      { "index": 1, "status": "failed", "error": { "code": "INSUFFICIENT_CREDITS", "message": "Skipped: insufficient credits" } }
    ]
  }
}
```

### Call queue

| v1 | v2 |
| - | - |
| `queueId` | `id` |
| `contactUID` | `callId` |
| `campaignUID` | `campaignId` |
| `state`, `type`, `reason`, `phone`, `name`, `agentId`, `agentName`, `kind`, `scheduledFor`, `notBefore`, `expiresAt`, `attempts`, `outcome`, `lastError`, `createdAt`, `updatedAt` | same names |
| `pagination` | `meta: { page, limit, total }` |

`sortBy=scheduledFor` is accepted and treated as `notBefore`.

### Events

An event has `id`, `type`, `version`, `timestamp`, `source` and `data` in both versions. The `data` object is the same payload your webhooks receive. `GET /events/{id}` in v2 also returns a `deliveries` array.

| v1 filter | v2 filter |
| - | - |
| `contactUID` | `callId` |
| `deferredCallId` | `queueId` |
| `campaignUID` | `campaignId` |
| `type` | `type` (an unknown type returns `422 INVALID_EVENT_TYPE`; v1 returned no results) |

### Webhook endpoints

| v1 | v2 |
| - | - |
| `endpoint.webhookId` | `id` |
| `endpoint` / `endpoints` wrapper | `data` object or array |
| `secret` next to `endpoint` | `data.secret`, on create only |
| `PUT` | `PATCH` |
| `url`, `description`, `eventTypes`, `agentIds`, `payloadMode`, `deliveryProfile`, `isActive`, `createdAt` | same names |
| (not in list) | `name`, `method`, `headers`, `bodyType`, `bodyTemplate`, `auth`, `conditions`, `timeoutMs`, `retryOnFailure`, `maxRetries`, `consecutiveFailures`, `disabledReason`, `updatedAt` |

The secret is returned once, when you create the endpoint or regenerate the secret. Regenerate returns `{ id, secret }` in `data` (v1: `webhookId` and `secret` next to `success`). Credentials inside `auth` are never returned; v2 shows `{ type, headerName, sendIn, hasCredentials }`.

Test delivery returns `delivered` (boolean), `status`, `body`, `latencyMs`, `error` and `samplePayload` in `data`. v1 returned `success`, `result` and `samplePayload`, with `success` set to the delivery outcome.

### Webhook delivery logs

| v1 | v2 |
| - | - |
| `logs` | `data` |
| `deliveryId` | `id` |
| `webhookId`, `eventId`, `eventType`, `url`, `status`, `attempt`, `responseStatus`, `latencyMs`, `error`, `createdAt` | same names |
| `pagination` | `meta: { page, limit, total }` |
| `limit` default 20 | `limit` default 25 |

The detail endpoint adds `requestHeaders`, `requestBody` and `responseBody`.

### Agents

v1 returns the stored field names and the full list without paging. v2 returns camelCase names with `meta: { page, limit, total }`.

| v1 | v2 |
| - | - |
| `agent_id` | `id` |
| `AgentName` | `name` |
| `preset_id` | `presetId` |
| `tts_voice` | `ttsVoice` |
| `tts_language` | `ttsLanguage` |
| `stt_language` | `sttLanguage` |
| `first_message` | `firstMessage` |
| `auto_hangup_time` | `autoHangupTime` |
| `templateVariables`, `createdAt` | same names |

### Leads

* `contactName` and `fullName` are accepted for `name`. `opportunityAmount` is accepted for `opportunityValue`, `leadTemperature` for `temperature`, and `industryData` or `fields` for `customFields`.
* v2 accepts a fixed set of fields: `name`, `phone`, `email`, `status`, `temperature`, `opportunityValue`, `customFields`, `source`, `visitorId`. Unknown top-level keys are dropped. In v1 they were stored as custom fields; in v2 put them under `customFields`.
* v2 does not create an opportunity automatically and does not record the caller's IP address or user agent.
* Response: `201` with the created lead, or `200` with `meta.merged: true` when the lead was merged into an existing one. The DTO has `id`, `callId`, `name`, `phone`, `email`, `status`, `temperature`, `opportunityValue`, `source`, `customFields`, `createdAt`, `updatedAt`.

### Tickets

* `body` is accepted for `description`.
* Request fields: `subject`, `description`, `phone`, `email`, `name`, `externalId`.
* Response: `{ id, status, channel, leadId }`. `201` for a new ticket, `200` with `meta: { created: false, duplicate: true }` for a duplicate.

### Errors

| v1 | v2 |
| - | - |
| `errorInfo.message` (or the legacy `message`) | `error.message` |
| `errorInfo.code` (or the legacy `code`) | `error.code` |
| `errorInfo.details` (or the legacy `errors`) | `error.details` |
| `errors[].field` | `error.details[].path` (with `in`: `body`, `query` or `params`) |
| `400` validation | `422` validation |
| `error` string (webhook management) | `error.message` |

`errorInfo` is the v1 spelling of the v2 `error` object, so moving a client from v1 to v2 only changes the property name and the validation detail shape. Codes are listed in [Errors](https://docs.oktivo.com/api-reference/errors.md#error-code-table).

## Behaviour differences to check

* Cancelling a call is one atomic update in v2. It returns `409 CALL_NOT_CANCELLABLE` when the call is already being dialed or finished.
* Webhook endpoint deletion is a soft delete, as in v1: the endpoint stops receiving events and no longer appears in lists.
* v2 additionally supports `Idempotency-Key` on `POST /webhooks/endpoints`. See [Idempotency](https://docs.oktivo.com/api-reference/idempotency.md).
* v2 body limits: 100 KB, and 1 MB for `POST /calls/bulk`. v1 allows 1 MB, and 10 MB for bulk calls, leads and tracking. Requests above the limit return `413`.
* v2 sets a `Retry-After` header on `429` and some `503` responses.

## Suggested order

1. Add `X-Request-ID` and log it. Add `Idempotency-Key` to your `POST` requests on v1 first; this needs no other change.
2. Move read endpoints (calls, queue, events) and switch to cursor pagination.
3. Move writes and webhook management.
4. Switch your error handling to `error.code`.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.