# Create a company address

URL: https://docs.sparklayer.io/developers/api/customers/create-a-company-address
Operation: `POST /api/v2/companies/{lookupBy}/{identifier}/addresses` (operationId `createCompanyAddress`)
OpenAPI spec: https://docs.sparklayer.io/openapi/customers.yaml

`POST /api/v2/companies/{lookupBy}/{identifier}/addresses`

**Base URLs:** `https://app.sparklayer.io` (Live), `https://test.app.sparklayer.io` (Test)

**Authentication:** send `Authorization: Bearer <access_token>` and `Site-Id: <site id>` with every request. Get the token from [Get an access token](https://docs.sparklayer.io/developers/api/core/get-an-access-token.md); see [Authentication](https://docs.sparklayer.io/developers/authentication.md).

### Example request

```bash
curl -X POST "https://app.sparklayer.io/api/v2/companies/platform/7843024560291/addresses" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "section_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
  "external_id": "<external_id>",
  "label": "<label>",
  "first_name": "<first_name>",
  "last_name": "<last_name>",
  "company": "<company>",
  "address_line1": "<address_line1>",
  "address_line2": "<address_line2>",
  "city": "<city>",
  "region_code": "<region_code>",
  "postal_code": "<postal_code>",
  "country_code": "<country_code>",
  "phone": "<phone>",
  "available_to_descendants": false
}'
```

Set `SPARKLAYER_TOKEN` to an access token and `SPARKLAYER_SITE_ID` to your Site ID. For the test environment, use `https://test.app.sparklayer.io`.

### Path parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `lookupBy` | "sparklayer" \| "platform" \| "integration" | Yes | What `identifier` is: `sparklayer` (the customer's SparkLayer ID), `platform` (their ID on your eCommerce platform) or `email` (their email address). Example: `platform` |
| `identifier` | string | Yes | The customer's ID or email address, of the kind set by `lookupBy`. SparkLayer IDs are UUIDs; legacy `cu_` IDs work too, except for shopping lists and favourites. Email lookups are exact and case-sensitive: URL-encode the address, with `+` as `%2B`. Example: `7843024560291` |

### Header parameters

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `Site-Id` | string | Yes | Your SparkLayer Site ID, from Settings > API in the SparkLayer Dashboard. Length: min 1. Example: `jones-climbing` |

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

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `section_id` | string (uuid) | | Owning section; omit to use the Company root |
| `external_id` | string \| null | | The platform's ID for an address a sync owns; null for one made in SparkLayer. An update replaces it, so send it back to keep it. Length: max 128. |
| `label` | string | Yes | Length: min 1, max 128. |
| `first_name` | string | | Length: max 50. |
| `last_name` | string | | Length: max 50. |
| `company` | string \| null | | Length: max 255. |
| `address_line1` | string | Yes | Length: min 1, max 255. |
| `address_line2` | string \| null | | Length: max 255. |
| `city` | string | Yes | Length: min 1, max 128. |
| `region_code` | string \| null | | Length: max 10. |
| `postal_code` | string \| null | | Required when the country's address format has a postal code, unless the address is synced. Null is stored as an empty string. Length: max 20. |
| `country_code` | string | Yes | Length: min 2, max 3. |
| `phone` | string \| null | | Length: max 20. |
| `available_to_descendants` | boolean | | Whether descendant sections may use this address. Default: `false`. |

```json
{
  "section_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
  "external_id": "<external_id>",
  "label": "<label>",
  "first_name": "<first_name>",
  "last_name": "<last_name>",
  "company": "<company>",
  "address_line1": "<address_line1>",
  "address_line2": "<address_line2>",
  "city": "<city>",
  "region_code": "<region_code>",
  "postal_code": "<postal_code>",
  "country_code": "<country_code>",
  "phone": "<phone>",
  "available_to_descendants": false
}
```

### Responses

#### 201: Created

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `section_id` | string (uuid) | Yes | |
| `external_id` | string \| null | | The platform's ID for an address a sync owns; null for one made in SparkLayer. An update replaces it, so send it back to keep it. Length: max 128. |
| `label` | string | Yes | Length: min 1, max 128. |
| `first_name` | string | | Length: max 50. |
| `last_name` | string | | Length: max 50. |
| `company` | string \| null | | Length: max 255. |
| `address_line1` | string | Yes | Length: min 1, max 255. |
| `address_line2` | string \| null | | Length: max 255. |
| `city` | string | Yes | Length: min 1, max 128. |
| `region_code` | string \| null | | Length: max 10. |
| `postal_code` | string \| null | | Required when the country's address format has a postal code, unless the address is synced. Null is stored as an empty string. Length: max 20. |
| `country_code` | string | Yes | Length: min 2, max 3. |
| `phone` | string \| null | | Length: max 20. |
| `available_to_descendants` | boolean | | Whether descendant sections may use this address. Default: `false`. |
| `id` | string (uuid) | Yes | |
| `company_id` | string (uuid) | Yes | |

```json
{
  "section_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
  "external_id": "<external_id>",
  "label": "<label>",
  "first_name": "<first_name>",
  "last_name": "<last_name>",
  "company": "<company>",
  "address_line1": "<address_line1>",
  "address_line2": "<address_line2>",
  "city": "<city>",
  "region_code": "<region_code>",
  "postal_code": "<postal_code>",
  "country_code": "<country_code>",
  "phone": "<phone>",
  "available_to_descendants": false,
  "id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
  "company_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b"
}
```

#### 409: Conflict - the site syncs its companies from its eCommerce platform, so an API key can't change its companies, sections, company addresses or company roles

`application/problem+json`: the standard error body (below).

#### Other statuses: An error. The body describes the problem: see [Errors](https://docs.sparklayer.io/developers/errors.md).

`application/problem+json`: the standard error body (below).

### Error body

Error responses with a body use this RFC 7807 problem details object. See [Errors](https://docs.sparklayer.io/developers/errors.md) for every status code and which errors to retry.

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `detail` | string | | Human-readable summary of the error |
| `status` | integer | | HTTP Status code returned from API |
| `title` | string | | Machine-readable error code |
| `type` | string | | |
| `errors` | object[] | | |
| `errors[].code` | string | | A machine-readable error message |
| `errors[].property` | string | | The offending property, with the full path |
| `errors[].field` | string | | The offending property, stripped of the path |
| `errors[].message` | string | | A human-readable summary of the error |

```json
{
  "detail": "Data Validation Failed",
  "status": 400,
  "title": "invalid-api-request-contents",
  "type": "https://hub.sparklayer.io/tech-docs",
  "errors": [
    {
      "code": "unique-constraint-violation",
      "property": "purchase_identifiers.sparklayer",
      "field": "sparklayer",
      "message": "Each stock level must have a unique stock location and sku combination"
    }
  ]
}
```
