# Calculate prices for SKUs

URL: https://docs.sparklayer.io/developers/api/pricing/calculate-pricing
Operation: `POST /api/v1/calculate-pricing` (operationId `calculateVariantPricing`)
OpenAPI spec: https://docs.sparklayer.io/openapi/pricing.yaml

Works out the price of each SKU in `skus` from the price lists in `price_list_slugs`, checked in the order given. The first list that has prices for the SKU wins, whether those prices are stored on the list or derived from one of its rules (with currency conversion and the percentage adjustment applied). Prices are always net and are returned as `{number, currency}` objects. Returns an empty array if none of the price lists exist.

`POST /api/v1/calculate-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/calculate-pricing" \
  -H "Authorization: Bearer $SPARKLAYER_TOKEN" \
  -H "Site-Id: $SPARKLAYER_SITE_ID" \
  -H "Content-Type: application/json" \
  -d '{
  "skus": [
    "TEST01"
  ],
  "price_list_slugs": [
    "a-price-list"
  ]
}'
```

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 |
| --- | --- | --- | --- |
| `skus` | string[] | | The SKUs to price. |
| `price_list_slugs` | string[] | | The price lists to check, in order: the first list with prices for a SKU is used. |

```json
{
  "skus": [
    "TEST01"
  ],
  "price_list_slugs": [
    "a-price-list"
  ]
}
```

### Responses

#### 200: The calculated prices of each SKU.

An array. Each item:

| Name | Type | Required | Description |
| --- | --- | --- | --- |
| `[].sku` | string | | SKU |
| `[].display_tax_rate` | number (float) \| null | | Tax rate used only to display a tax-inclusive price, expressed as a whole percentage (10 means 10%). Stored prices remain net and the eCommerce platform remains authoritative for the tax actually charged at checkout. On an update the field has three states: omit it to leave any stored rate unchanged (so a price-only sync never disturbs it), send null to clear it, or send a value to set it. Min 0, max 100. |
| `[].tax_inclusive_display` | boolean | | Whether the winning price list is configured to display prices inclusive of display_tax_rate. Presentation only - the prices returned above are always net. |
| `[].pricing` | object[] | | |
| `[].pricing[].quantity` | integer | | |
| `[].pricing[].price` | object | | |
| `[].pricing[].price.number` | string | | |
| `[].pricing[].price.currency` | string | | |
| `[].pricing[].unit_of_measure` | string \| null | | |

```json
[
  {
    "sku": "TEST01",
    "display_tax_rate": 10,
    "tax_inclusive_display": false,
    "pricing": [
      {
        "quantity": 1,
        "price": {
          "number": "<number>",
          "currency": "<currency>"
        },
        "unit_of_measure": "pallet"
      }
    ]
  }
]
```

#### 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 | | |

```json
{
  "detail": "Data Validation Failed",
  "status": 400,
  "title": "invalid-api-request-contents",
  "type": "https://docs.sparklayer.io/tech-docs"
}
```
