# Update subscription

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

The API key must allow "Change subscriber data".

Changes the custom fields or the business policy of a subscription.

## Parameters

- `id` (string, required): ID of the customer the subscription belongs to.
- `subscription_id` (string, required): ID of the subscription to update.
- `data` (object): Any fields to set on the subscription, by field ID. The valid fields are the ones associated with the products that the subscription is subscribed to. Fields not mentioned are not touched, and `null` deletes a field.
- `created` (string): Override the time the subscription was created, as `YYYY-MM-DDTHH:MM:SS`. Mainly useful when correcting imported subscriptions.
- `reinvoice` (bool): Set to `true` if the update changes the pricing of the subscription to make the change take effect immediately. The system then credits the future part of the subscription (if it has been invoiced already) and sets it up to be invoiced.
- `policy` (object): An object containing an `id` or `external_id` of the business policy to attach to the subscription. To remove an attached policy, send `null`.
- `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.

You can set any custom subscription field, using its field id (the field name with a colon prepended, or its external identifier).

[Log in](/login/?next=/api/docs/server/updatesubscription.md), or send your API key as a bearer token, to see the custom subscription fields set up for your account.

A yes/no field (type `bool`) is `true` or `false`, and has no value when it isn't set. Set it with `true` or `false`, and clear it with `null`.

## Examples

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

```json
{
  "id": "12345",
  "subscription_id": "32142532",
  "data": {
    ":Custom subscription field": "Example text",
    ":Obsolete field": null
  },
  "policy": {
    "external_id": "no_pause"
  }
}
```

## Return value

On success the endpoint returns the ID of the updated 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 unknown policy:

```json
{
  "external_id": ["Policy not found"]
}
```

Errors that are not specific to a field are returned with the empty string as key. This covers an unknown subscription or a subscription that belongs to a different customer, and invalid custom subscription fields:

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