## Validate Promotions

### cURL

```
curl --request POST \
  --url https://prod01-apigw.yourcompany.fabric.zone/api-price/promo/validate \
  --header 'Content-Type: application/json' \
  --header 'x-site-context: <x-site-context>' \
  --data '
{
  "items": [\
    {\
      "itemId": 1000000119,\
      "group": [\
        "5e2cfb9b45570b000863c4b5"\
      ],\
      "quantity": 3,\
      "price": {\
        "base": 1000,\
        "sale": 0,\
        "currency": "USD"\
      },\
      "lineItemId": 1,\
      "sku": "SKU0001"\
    }\
  ],\
  "isLoggedIn": false,\
  "userId": "5e2cfb9b45570b000864c4b5",\
  "promoCodes": [\
    "300DOFF"\
  ]\
}
'
```

```python
import requests

url = "https://prod01-apigw.yourcompany.fabric.zone/api-price/promo/validate"

payload = {
    "items": [\
        {\
            "itemId": 1000000119,\
            "group": ["5e2cfb9b45570b000863c4b5"],\
            "quantity": 3,\
            "price": {\
                "base": 1000,\
                "sale": 0,\
                "currency": "USD"\
            },\
            "lineItemId": 1,\
            "sku": "SKU0001"\
        }\
    ],
    "isLoggedIn": False,
    "userId": "5e2cfb9b45570b000864c4b5",
    "promoCodes": ["300DOFF"]
}
headers = {
    "x-site-context": "<x-site-context>",
    "Content-Type": "application/json"
}

response = requests.post(url, json=payload, headers=headers)

print(response.text)
```

```javascript
const options = {
  method: 'POST',
  headers: {'x-site-context': '<x-site-context>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    items: [\
      {\
        itemId: 1000000119,\
        group: ['5e2cfb9b45570b000863c4b5'],\
        quantity: 3,\
        price: {base: 1000, sale: 0, currency: 'USD'},\
        lineItemId: 1,\
        sku: 'SKU0001'\
      }\
    ],
    isLoggedIn: false,
    userId: '5e2cfb9b45570b000864c4b5',
    promoCodes: ['300DOFF']
  })
};

fetch('https://prod01-apigw.yourcompany.fabric.zone/api-price/promo/validate', options)
  .then(res => res.json())
  .then(res => console.log(res))
  .catch(err => console.error(err));
```

```php
<?php

$curl = curl_init();

curl_setopt_array($curl, [\
  CURLOPT_URL => "https://prod01-apigw.yourcompany.fabric.zone/api-price/promo/validate",\
  CURLOPT_RETURNTRANSFER => true,\
  CURLOPT_ENCODING => "",\
  CURLOPT_MAXREDIRS => 10,\
  CURLOPT_TIMEOUT => 30,\
  CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,\
  CURLOPT_CUSTOMREQUEST => "POST",\
  CURLOPT_POSTFIELDS => json_encode([\
    'items' => [\
        [\
                'itemId' => 1000000119,\
                'group' => [\
                                '5e2cfb9b45570b000863c4b5'\
                ],\
                'quantity' => 3,\
                'price' => [\
                                'base' => 1000,\
                                'sale' => 0,\
                                'currency' => 'USD'\
                ],\
                'lineItemId' => 1,\
                'sku' => 'SKU0001'\
        ]\
    ],\
    'isLoggedIn' => false,\
    'userId' => '5e2cfb9b45570b000864c4b5',\
    'promoCodes' => [\
        '300DOFF'\
    ]\
  ]),\
  CURLOPT_HTTPHEADER => [\
    "Content-Type: application/json",\
    "x-site-context: <x-site-context>"\
  ],\
]);

$response = curl_exec($curl);
$err = curl_error($curl);

curl_close($curl);

if ($err) {
  echo "cURL Error #:" . $err;
} else {
  echo $response;
}
?>
```

```go
package main

import (
	"fmt"
	"strings"
	"net/http"
	"io"
)

func main() {

url := "https://prod01-apigw.yourcompany.fabric.zone/api-price/promo/validate"

payload := strings.NewReader("{\n  \"items\": [\n    {\n      \"itemId\": 1000000119,\n      \"group\": [\n        \"5e2cfb9b45570b000863c4b5\"]\n      },\n      \"quantity\": 3,\n      \"price\": {\n        \"base\": 1000,\n        \"sale\": 0,\n        \"currency\": \"USD\"\n      },\n      \"lineItemId\": 1,\n      \"sku\": \"SKU0001\"\n    }\n  ],\n  \"isLoggedIn\": false,\n  \"userId\": \"5e2cfb9b45570b000864c4b5\",\n  \"promoCodes\": [\n    \"300DOFF\"\n  ]}")

req, _ := http.NewRequest("POST", url, payload)

req.Header.Add("x-site-context", "<x-site-context>")
	req.Header.Add("Content-Type", "application/json")

res, _ := http.DefaultClient.Do(req)

defer res.Body.Close()
	body, _ := io.ReadAll(res.Body)

fmt.Println(string(body))
}
```

### Sample Response

```json
{
  "isSuccess": true,
  "items": [\
    {\
      "lineItemId": 1,\
      "sku": "SKU0001",\
      "itemId": 1000000119,\
      "group": [\
        "5e2cfb9b45570b000863c4b5"\
      ],\
      "quantity": 3,\
      "price": {\
        "sale": 1000,\
        "cost": 0,\
        "currency": "USD",\
        "base": 5000,\
        "kind": "Promotion",\
        "discount": 0\
      },\
      "discount": [\
        {\
          "_id": "5f9be340dde1cd0008f96035",\
          "unit": "AMOUNT_OFF",\
          "value": 300,\
          "ON": {\
            "kind": "SKU",\
            "value": null\
          },\
          "id": "5f9be340dde1cd0008f96035",\
          "promoId": "5f9be340dde1cd0008f96034",\
          "promoCode": "300DOFF",\
          "promoTitle": "SKU 300 D off all skus",\
          "type": "COUPON"\
        }\
      ],\
      "discountQuantity": 3,\
      "discountAmount": 5070\
    }\
  ],\
  "appliedDiscounts": [\
    {\
      "promoId": "5faaac2dd49ffe00071e4f8d",\
      "promoTitle": "inclsion promo 99 P off ",\
      "type": "PROMOTION-SKU"\
    }\
  ],\
  "discounts": [\
    {\
      "_id": "5faaac2dd49ffe00071e4f8e",\
      "unit": "%OFF",\
      "value": 99,\
      "ON": {\
        "kind": "SKU",\
        "value": null\
      },\
      "id": "5faaac2dd49ffe00071e4f8e",\
      "type": "PROMOTION-SKU",\
      "promoId": "5faaac2dd49ffe00071e4f8d",\
      "promoTitle": "inclsion promo 99 P off."\
    }\
  ]
}
```

### Error Responses

```json
{
  "code": 400,
  "message": "SKU cannot be empty"
}
```

```json
{
  "code": 500,
  "message": "An internal error occurred. If the issue persists please contact support@fabric.inc."
}
```
