# Update customer

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

The API key must allow "Change subscriber data".

Changes the attributes of a customer; those not given are left unchanged.

## Parameters

- `id` (string, required): ID of the customer to update.
- `data` (object): The attributes to change, e.g. `{"name": "Customer Name", "email": "john@example.com", "country": "NO"}`. Valid attributes are the built-in ones and the customer fields set up inside Iteras for the account. Fields not mentioned are not touched, and `null` deletes the value of a field.
- `create` (bool, Defaults to `false`): If set to `true`, the customer is created if not found. Otherwise an unknown customer ID results in an error.
- `use_external_lookup` (bool, Defaults to `true`): Set to `false` or 0 if you do not want e-invoice recipients, VAT organization IDs and similar to be validated via external services.
- `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 change these built-in customer fields in `data`:

- `name`, `company`, `address` and `country`
- `email`
- `billing_name`, `billing_company`, `billing_address`, `billing_country` and `billing_email`
- `password` - you can't retrieve it in clear text afterwards as it goes through a hash
- `created`

Note that a few of these fields have a different name in the [retrieval API](/api/docs/server/retrievingcustomers.md) for backwards compatibility.

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

[Log in](/login/?next=/api/docs/server/updatecustomer.md), or send your API key as a bearer token, to see the custom customer 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`.

A date and time field (type `datetime`) can be set up to follow other fields, so it is set to the time one of them changes. If the same update changes the date and time field itself, that value is kept.

## Examples

An example where we fill in name, address country and two custom fields and clear the obsolete field:

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

```json
{
  "id": "12345",
  "data": {
    "name": "New Name",
    "address": "Some Street 12\n8000 Aarhus",
    "country": "DK",
    ":Custom field": "Example text",
    ":Custom date field": "2026-10-23",
    ":Obsolete field": null
  }
}
```

With `create` set, an unknown customer ID creates the customer instead of returning an error:

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

```json
{
  "id": "12345",
  "create": true,
  "data": {
    "name": "Customer Name",
    "email": "foo@example.com",
    "country": "DK"
  }
}
```

## Return value

On success the endpoint returns the ID of the updated customer:

```json
{ "id": "12345" }
```

## 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. a custom customer field:

```json
{
  ":Custom date field": ["Enter a valid date."]
}
```

Errors that are not specific to a field are returned with the empty string as key:

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