# Create or update a customer

URL: https://docs.sparklayer.io/ignite/api/create-update-a-customer
Operation: `PUT /v1/{siteEnv}/{siteId}/customers` (operationId `createUpdateCustomer`)
OpenAPI spec: https://docs.sparklayer.io/openapi/ignite.yaml

Create or update a "customer" on the eCommerce platform.
The email address of the customer should be used as the unique identifier for finding the customer on the target platform.

`PUT /v1/{siteEnv}/{siteId}/customers`

> This is an Ignite endpoint: your integration service implements it and SparkLayer calls it.

### Request SparkLayer sends

```http
PUT /v1/live/bobs-store/customers HTTP/1.1
Host: ignite.example.com
Content-Type: application/json

{
  "email": "bob@sparklayer.io",
  "first_name": "Bob",
  "last_name": "Jones",
  "company_name": "Tom Jones Climbing Ltd",
  "accounting_id": "<accounting_id>",
  "sales_agent_groups": [
    "group-1"
  ],
  "price_lists": [
    "25-off"
  ],
  "customer_discount_percentage": 25,
  "group": "50-off",
  "role": "limited-customer",
  "addresses": [
    {
      "title": "Mr",
      "first_name": "Bob",
      "last_name": "Jones",
      "company": "Tom Jones Climbing Ltd",
      "address_line1": "Example Industrial Estate",
      "address_line2": "North Country",
      "city": "Cityland",
      "region_name": "California",
      "region_code": "CA",
      "postal_code": "12345",
      "country_code": "US",
      "phone": "+44 (0) 123456789",
      "is_default_shipping": true,
      "is_default_billing": true,
      "is_temporary": true
    }
  ],
  "send_invite": true,
  "tax_exempt": true,
  "parent_customer_external_id": "CU1234",
  "additional_tags": [
    "high-priority"
  ],
  "payment_on_account": {
    "credit_limit": 0,
    "balance": 0,
    "currency_code": "<currency_code>",
    "net_terms": "7_days"
  }
}
```

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `siteEnv` | string | Yes | The SparkLayer environment the request is for, such as `live`. Store it, with the site ID, when SparkLayer connects your platform. Example: `live` |
| `siteId` | string | Yes | The SparkLayer site ID the request is for, such as `bobs-store`. Store it, with the environment, when SparkLayer connects your platform. Length: min 1. Example: `bobs-store` |

### Request body (`application/json`) (required)

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `email` | string (email) | Yes | |
| `first_name` | string | Yes | Length: min 1, max 128. |
| `last_name` | string | Yes | Length: min 1, max 128. |
| `company_name` | string \| null | | Length: max 128. |
| `accounting_id` | string \| null | | The identifier for the customer in the merchant's accountancy or ERP. Length: min 1, max 124. |
| `sales_agent_groups` | string[] \| null | | |
| `price_lists` | string[] \| null | | |
| `customer_discount_percentage` | number (float) \| null | | |
| `group` | string \| null | | Length: max 128. |
| `role` | string \| null | | |
| `addresses` | object[] \| null | | List of customer addresses |
| `addresses[].title` | string \| null | | Length: max 30. |
| `addresses[].first_name` | string \| null | | Length: max 50. |
| `addresses[].last_name` | string \| null | | Length: max 50. |
| `addresses[].company` | string \| null | | Length: max 128. |
| `addresses[].address_line1` | string | | Length: max 255. |
| `addresses[].address_line2` | string \| null | | Length: max 255. |
| `addresses[].city` | string | | Length: max 128. |
| `addresses[].region_name` | string \| null | | Length: max 128. |
| `addresses[].region_code` | string \| null | | Length: max 10. |
| `addresses[].postal_code` | string \| null | | Length: max 20. |
| `addresses[].country_code` | string | | Two letter country code as defined by ISO 3166-2. Length: max 2. |
| `addresses[].phone` | string | | Length: max 20. |
| `addresses[].is_default_shipping` | boolean | | |
| `addresses[].is_default_billing` | boolean | | |
| `addresses[].is_temporary` | boolean | | Whether the address is temporary for the duration of a cart. This value is only relevant to platforms that create the order address automatically on order creation (or conversion from draft to normal order as in the case of our Shopify integration). In such cases we will want the integration to ensure this address does not get created in SparkLayer when the platform notifes the integration of a new customer address. |
| `send_invite` | boolean \| null | | |
| `tax_exempt` | boolean | | Whether the customer is tax exempt or not. This is only relevant to platforms that support tax exemption. |
| `parent_customer_external_id` | string \| null | | Parent Customer ID of the Customer |
| `additional_tags` | string[] \| null | | Additional tags to appear on the customer in Shopify. Automatically prefixed with spark- |
| `payment_on_account` | object \| null | | |
| `payment_on_account.credit_limit` | number (float) \| null | | Max 999999999.999. |
| `payment_on_account.balance` | number (float) \| null | | Max 999999999.999. |
| `payment_on_account.currency_code` | string \| null | | If set allows overriding the currency for the customer, otherwise the base currency of the store is to be used. Pattern: `^[A-Za-z]{3}$`. |
| `payment_on_account.net_terms` | "7_days" \| "15_days" \| "30_days" \| "45_days" \| "60_days" \| "90_days" \| null | | |

```json
{
  "email": "bob@sparklayer.io",
  "first_name": "Bob",
  "last_name": "Jones",
  "company_name": "Tom Jones Climbing Ltd",
  "accounting_id": "<accounting_id>",
  "sales_agent_groups": [
    "group-1"
  ],
  "price_lists": [
    "25-off"
  ],
  "customer_discount_percentage": 25,
  "group": "50-off",
  "role": "limited-customer",
  "addresses": [
    {
      "title": "Mr",
      "first_name": "Bob",
      "last_name": "Jones",
      "company": "Tom Jones Climbing Ltd",
      "address_line1": "Example Industrial Estate",
      "address_line2": "North Country",
      "city": "Cityland",
      "region_name": "California",
      "region_code": "CA",
      "postal_code": "12345",
      "country_code": "US",
      "phone": "+44 (0) 123456789",
      "is_default_shipping": true,
      "is_default_billing": true,
      "is_temporary": true
    }
  ],
  "send_invite": true,
  "tax_exempt": true,
  "parent_customer_external_id": "CU1234",
  "additional_tags": [
    "high-priority"
  ],
  "payment_on_account": {
    "credit_limit": 0,
    "balance": 0,
    "currency_code": "<currency_code>",
    "net_terms": "7_days"
  }
}
```

### Responses your service returns

#### 201: Successful operation

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `customer_external_id` | string | | Platform ID of Customer |

```json
{
  "customer_external_id": "CU1234"
}
```

#### 401: Auth Failure

#### 500: System Exception
