# Create a shopping list

URL: https://docs.sparklayer.io/developers/api/customers/create-a-shopping-list
Operation: `POST /api/v2/customers/{lookupBy}/{identifier}/shopping-lists` (operationId `createCustomerShoppingList`)
OpenAPI spec: https://docs.sparklayer.io/openapi/customers.yaml

Creates a shopping list for the customer and returns it with `201`. Quantities are whole numbers up to 1,000. To share the list with a company location, set `company.section_id`: it can't be changed afterwards.

`POST /api/v2/customers/{lookupBy}/{identifier}/shopping-lists`

**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/customers/platform/7843024560291/shopping-lists" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "Weekly list",
  "contents": [
    {
      "sku": "TEST",
      "quantity": 9
    }
  ],
  "company": {
    "id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
    "section_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
    "section_name": "<section_name>"
  }
}'
```

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" \| "email" | 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`) (optional)

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `name` | string | Yes | Length: max 256. |
| `contents` | object[] | Yes | |
| `contents[].sku` | string | | Length: max 256. |
| `contents[].quantity` | number | | Max 1000. |
| `company` | object \| null | | Company sections are opt-in; omit this, or send null, for merchants that do not use them. Otherwise `section_id` is required. Set when the list is created and not changed afterwards. |
| `company.id` | string (uuid) \| null | | |
| `company.section_id` | string (uuid) | Yes | |
| `company.section_name` | string \| null | | Length: max 128. |

```json
{
  "name": "Weekly list",
  "contents": [
    {
      "sku": "TEST",
      "quantity": 9
    }
  ],
  "company": {
    "id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
    "section_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
    "section_name": "<section_name>"
  }
}
```

### Responses

#### 201: Successful response, shopping list created

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `id` | string (uuid) | | |
| `created_at` | string | | Created Date |
| `updated_at` | string | | Updated Date |
| `name` | string | Yes | Length: max 256. |
| `contents` | object[] | Yes | |
| `contents[].sku` | string | | Length: max 256. |
| `contents[].quantity` | number | | Max 1000. |
| `company` | object \| null | | Company sections are opt-in; omit this, or send null, for merchants that do not use them. Otherwise `section_id` is required. Set when the list is created and not changed afterwards. |
| `company.id` | string (uuid) \| null | | |
| `company.section_id` | string (uuid) | Yes | |
| `company.section_name` | string \| null | | Length: max 128. |

```json
{
  "id": "6502579c-90b9-4fc1-8e78-083cb84702d8",
  "created_at": "2003-05-20T08:20:00Z",
  "updated_at": "2003-05-21T08:20:00Z",
  "name": "Weekly list",
  "contents": [
    {
      "sku": "TEST",
      "quantity": 9
    }
  ],
  "company": {
    "id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
    "section_id": "3f2b8c1e-5d4a-4e6f-9b7c-1a2d3e4f5a6b",
    "section_name": "<section_name>"
  }
}
```

#### 400: The request is invalid.

`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"
    }
  ]
}
```
