# Cancel subscription

POST `https://app.iteras.dk/api/customers/cancelsubscription/`

The API key must allow "Change subscriber data".

Stops a subscription now or at a later time. Anything invoiced for the time after the stop is credited.

Stopping a subscription requires computing what's been delivered and what's owed. There is usually an amount up until the given stop time which should still be paid, and an amount afterwards which may have already been invoiced.

If the stop is in the future, there's the question of when the stop is executed. Generally, Iteras tries to execute the stop as soon as possible, computing and setting a future end date on the relevant period.

## Parameters

- `id` (string, required): ID of the customer the subscription belongs to.
- `subscription_id` (string, required): ID of the subscription to stop.
- `stop_at` (string): When the subscription stops, as `YYYY-MM-DDTHH:MM:SS`, the first moment without it. The default is now.
- `exclude_from_webhooks` (bool, Defaults to `false`): Set to `true` to keep every event the request causes from being sent to webhooks, invoice and payment events included, e.g. `"exclude_from_webhooks": true`. The events are still added to the history.

## Examples

```http
POST /api/customers/cancelsubscription/ HTTP/1.1
Content-Type: application/json
```

```json
{
  "id": "12345",
  "subscription_id": "32142532",
  "stop_at": "2026-12-22T13:56:59"
}
```

## Return value

On success the endpoint returns the ID of the cancelled subscription:

```json
{ "subscription_id": "32142532" }
```

## Errors

Invalid requests due to programming error, e.g. invalid JSON, returns 400.

A well-formed operation where a supplied value is invalid is not executed and returns an HTTP 422 error. The response is a JSON object with the errors keyed by the field they concern, e.g. an invalid `stop_at`:

```json
{
  "stop_at": ["Cannot be a date in the past"]
}
```

Errors that are not specific to a field are returned with the empty string as key, e.g. an unknown subscription:

```json
{
  "": ["Subscription does not exist."]
}
```