# Get customer-specific pricing

URL: https://docs.sparklayer.io/developers/api/core/get-customer-specific-pricing
Operation: `POST /api/v1/fetch-customer-pricing` (operationId `getCustomerPricing`)
OpenAPI spec: https://docs.sparklayer.io/openapi/core.yaml

Returns the net unit price, line total and quantity price breaks a customer would get for each SKU, based on their price lists and any customer discount percentage. If some SKUs can't be priced the response is `207`, and those line items have an `error` message instead of prices. Returns `400` if the customer can't be found or has no price lists, or if `customer_lookup_by` is `sparklayer` and `customer_id` isn't a UUID.

`POST /api/v1/fetch-customer-pricing`

**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/v1/fetch-customer-pricing" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "customer_id": "123e4567-e89b-12d3-a456-426614174000",
  "customer_lookup_by": "sparklayer",
  "line_items": [
    {
      "sku": "WIDGET-RED-M",
      "quantity": 10
    },
    {
      "sku": "WIDGET-BLUE-L",
      "quantity": 25
    }
  ]
}'
```

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`.

### Header parameters

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

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

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `customer_id` | string | Yes | The customer identifier, of the kind set by `customer_lookup_by`. |
| `customer_lookup_by` | "sparklayer" \| "platform" \| "email" | Yes | What `customer_id` is: `sparklayer` (the customer's SparkLayer ID, a UUID), `platform` (the ID from your eCommerce platform) or `email`. |
| `line_items` | object[] | Yes | Items: min 1. |
| `line_items[].sku` | string | Yes | SKU. Length: min 1, max 128. |
| `line_items[].quantity` | integer | Yes | Min 1. |

```json
{
  "customer_id": "123e4567-e89b-12d3-a456-426614174000",
  "customer_lookup_by": "sparklayer",
  "line_items": [
    {
      "sku": "WIDGET-RED-M",
      "quantity": 10
    },
    {
      "sku": "WIDGET-BLUE-L",
      "quantity": 25
    }
  ]
}
```

### Responses

#### 200: Successful response — all line items resolved pricing

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `line_items` | object[] | | |
| `line_items[].sku` | string | | |
| `line_items[].quantity` | integer | | |
| `line_items[].error` | string \| null | | Populated when pricing could not be determined for this SKU; null on success |
| `line_items[].currency_code` | string \| null | | |
| `line_items[].unit_price` | object \| null | | |
| `line_items[].unit_price.net` | string | | |
| `line_items[].line_total` | object \| null | | |
| `line_items[].line_total.net` | string | | |
| `line_items[].quantity_price_breaks` | object[] \| null | | |
| `line_items[].quantity_price_breaks[].min_quantity` | integer | | |
| `line_items[].quantity_price_breaks[].price` | object | | |
| `line_items[].quantity_price_breaks[].price.net` | string | | |
| `line_items[].quantity_price_breaks[].unit_of_measure` | string \| null | | |

```json
{
  "line_items": [
    {
      "sku": "WIDGET-RED-M",
      "quantity": 10,
      "error": null,
      "currency_code": "USD",
      "unit_price": {
        "net": "8.500000"
      },
      "line_total": {
        "net": "85.000000"
      },
      "quantity_price_breaks": [
        {
          "min_quantity": 1,
          "price": {
            "net": "10.000000"
          },
          "unit_of_measure": "box"
        },
        {
          "min_quantity": 10,
          "price": {
            "net": "8.500000"
          },
          "unit_of_measure": "box"
        }
      ]
    }
  ]
}
```

#### 207: Partial success — one or more line items could not be priced

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `line_items` | object[] | | |
| `line_items[].sku` | string | | |
| `line_items[].quantity` | integer | | |
| `line_items[].error` | string \| null | | Populated when pricing could not be determined for this SKU; null on success |
| `line_items[].currency_code` | string \| null | | |
| `line_items[].unit_price` | object \| null | | |
| `line_items[].unit_price.net` | string | | |
| `line_items[].line_total` | object \| null | | |
| `line_items[].line_total.net` | string | | |
| `line_items[].quantity_price_breaks` | object[] \| null | | |
| `line_items[].quantity_price_breaks[].min_quantity` | integer | | |
| `line_items[].quantity_price_breaks[].price` | object | | |
| `line_items[].quantity_price_breaks[].price.net` | string | | |
| `line_items[].quantity_price_breaks[].unit_of_measure` | string \| null | | |

```json
{
  "line_items": [
    {
      "sku": "WIDGET-RED-M",
      "quantity": 10,
      "error": null,
      "currency_code": "USD",
      "unit_price": {
        "net": "8.500000"
      },
      "line_total": {
        "net": "85.000000"
      },
      "quantity_price_breaks": [
        {
          "min_quantity": 1,
          "price": {
            "net": "10.000000"
          },
          "unit_of_measure": "box"
        }
      ]
    },
    {
      "sku": "WIDGET-BLUE-L",
      "quantity": 25,
      "error": "Pricing not found for SKU 'WIDGET-BLUE-L'",
      "currency_code": null,
      "unit_price": null,
      "line_total": null,
      "quantity_price_breaks": null
    }
  ]
}
```

#### 400: Validation error

`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 \| null | | |
| `errors` | object[] \| null | | A list of errors related to the call |
| `errors[].code` | string | | Machine-readable error code |
| `errors[].property` | string | | The property the error relates to |
| `errors[].message` | string | | Human readable summary of the error |

```json
{
  "detail": "Data Validation Failed",
  "status": 400,
  "title": "invalid-api-request-contents",
  "type": "https://docs.sparklayer.io/api/errors#invalid-api-request-contents",
  "errors": [
    {
      "code": "resource-not-found",
      "property": "stock_location_id",
      "message": "stock_location_id not found"
    }
  ]
}
```
