# Cancel a subscription

Operation ID: `cancelSubscription`

Group: Accounting › Subscriptions

[Open in the interactive reference](https://docs.api.lensing.ai/lensing/v1/endpoints/cancelSubscription)

`POST /accounting/subscriptions/{id}/cancel`

Retry-safe: A write that accepts Idempotency-Key: repeating a request with the same key replays the stored answer instead of executing twice.

Cancels a subscription. Every line of the subscription ends on cancellationDate, and the subscription ends in a canceled state.

For a termed subscription, every planned invoice dated on or after cancellationDate is created at once, with cancellationDate as the invoice date. Pay-as-you-go invoices are the exception. For an evergreen subscription, the planned invoices after cancellationDate are removed, and a final prorated invoice up to cancellationDate is planned. That invoice is created at once only when invoiceImmediately is true.

To cancel only some lines, or to combine a cancellation with other changes, use POST accounting/subscriptions/:id/modify.

## Parameters

| Name | In | Type | Required | Description |
| --- | --- | --- | --- | --- |
| `Api-Version` | header | string · v1 | yes | The API version this request targets, named by its public identifier. Required on every request; omitting it, or naming a version this company does not have, is answered with 400. This document describes version `v1`. |
| `Idempotency-Key` | header | string | no | An opaque caller-chosen string (1-255 characters) that makes this request safe to retry. Repeating the same key with an identical request body replays the original response instead of re-executing - but only once that original request succeeded; a failed attempt re-executes on retry. Repeating the key with a different body is answered with 422. A key still in flight is answered with 409 - as is a key whose original request was interrupted before it finished, for a few minutes afterwards, until that attempt is presumed dead. A completed response stays replayable for 24 hours. The key is scoped to the caller, not to the action: reusing it for a different action is answered with 409 or 422 rather than treated independently. On read actions this header is ignored. On write actions that cannot offer the guarantee it is answered with `400 IDEMPOTENCY_NOT_SUPPORTED` rather than silently ignored. |
| `id` | path | string | yes | Id of the subscription to cancel (a UUID); bound from the :id path segment. |

## Request body

Required, `application/json`: cancelSubscriptionInput.

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `cancellationDate` | date | yes | Date the service ends (ISO 8601, YYYY-MM-DD). For evergreen subscriptions this must fall on a billing-period boundary and on/after the end of the last invoiced period. |
| `submissionDate` | date | no | Date the customer requested the cancellation (ISO 8601, YYYY-MM-DD). Recorded on the cancellation for audit. |
| `reasonCode` | any | no | Reason for the cancellation. Defaults to noReasonGiven. One of: `"noReasonGiven"`, `"budgetary"`, `"movingToCompetitors"`, `"lowCustomerSatisfaction"`, `"bankruptcy"`, `"acquisitionMerger"`. |
| `note` | string | no | Free-text note recorded on the cancellation |
| `invoiceImmediately` | boolean | no | Evergreen subscriptions only: immediately invoice the final prorated period up to the cancellation date. Defaults to false. |
| `externalOrderId` | string | no | Upstream order reference, recorded on the cancellation note for audit. Cancellation is naturally idempotent: a repeat call returns ALREADY_CANCELLED. |

```json
{
  "cancellationDate": "2026-01-15",
  "submissionDate": "2026-01-15",
  "reasonCode": "noReasonGiven",
  "note": "<note>",
  "invoiceImmediately": true,
  "externalOrderId": "3fa85f64-5717-4562-b3fc-2c963f66afa6"
}
```

## Response

`200` Success

Under `data` (cancelSubscriptionOutput):

| Field | Type | Required | Description |
| --- | --- | --- | --- |
| `subscriptionId` | string | yes | Id of the canceled subscription (a UUID); echoes the :id path segment. |
| `status` | string | yes | Status of the subscription after the call. Always 'cancelled'. |
| `cancellationDate` | date | yes | Effective date the service ends (ISO 8601, YYYY-MM-DD); echoes the validated cancellationDate. |

```json
{
  "data": {
    "subscriptionId": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "status": "<status>",
    "cancellationDate": "2026-01-15"
  },
  "diagnostics": [
    {
      "code": "<code>",
      "message": "<message>",
      "severity": "error",
      "path": [
        "<path>"
      ],
      "details": "<details>"
    }
  ]
}
```

## Response headers

- `Idempotency-Replayed` — Present and `true` only when this response replays a previously stored one for the same Idempotency-Key, rather than reflecting a live execution. Absent on a live response - never sent as `false`.

## Errors

| Code | Status |
| --- | --- |
| `SUBSCRIPTION_NOT_FOUND` | 400 |
| `ALREADY_CANCELLED` | 400 |
| `CANCELLATION_DATE_WITHIN_BILLING_PERIOD` | 400 |
| `CANCELLATION_DATE_BEFORE_INVOICED_PERIOD` | 400 |
| `CANCELLATION_DATE_OUTSIDE_SERVICE_PERIOD` | 400 |
| `IDEMPOTENCY_KEY_CONFLICT` | 409 |
| `IDEMPOTENCY_PAYLOAD_MISMATCH` | 422 |

## Statuses

- `400` — Invalid request or business failure. Codes: SUBSCRIPTION_NOT_FOUND, ALREADY_CANCELLED, CANCELLATION_DATE_WITHIN_BILLING_PERIOD, CANCELLATION_DATE_BEFORE_INVOICED_PERIOD, CANCELLATION_DATE_OUTSIDE_SERVICE_PERIOD
- `401` — The request carries no valid access token.
- `403` — Not authorized
- `404` — Not found
- `409` — The Idempotency-Key is still being processed by another request.
- `422` — The Idempotency-Key was already used with a different request payload.
- `429` — Too many requests from this client address. The response has no body and no `Retry-After` header.
- `500` — Internal server error
