Get Discounts - Fabric

Get Discounts

cURL

curl --request POST \
  --url https://vanilla-dev02-loyalty.fabric.zone/api/v1/discounts \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --data '
{
  "profileId": "67460e74-02e3-11e8-b443-00163e990bdb",
  "entityReference": "Company_Club",
  "transactionTimestamp": "2020-02-08 09:30:26",
  "taxAmount": 1,
  "grossAmount": 6,
  "netAmount": 5,
  "transactionItems": [
    {
      "grossAmount": 6,
      "netAmount": 5,
      "categories": [
        "Proteins",
        "Adults"
      ],
      "itemPrice": 5,
      "itemQuantity": 1,
      "SKU": "123456",
      "taxAmount": 1,
      "itemName": "Whey"
    }
  ]
}
'

Python

import requests

url = "https://vanilla-dev02-loyalty.fabric.zone/api/v1/discounts"

payload = {
    "profileId": "67460e74-02e3-11e8-b443-00163e990bdb",
    "entityReference": "Company_Club",
    "transactionTimestamp": "2020-02-08 09:30:26",
    "taxAmount": 1,
    "grossAmount": 6,
    "netAmount": 5,
    "transactionItems": [
        {
            "grossAmount": 6,
            "netAmount": 5,
            "categories": ["Proteins", "Adults"],
            "itemPrice": 5,
            "itemQuantity": 1,
            "SKU": "123456",
            "taxAmount": 1,
            "itemName": "Whey"
        }
    ]
}
headers = {
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)

JavaScript

const options = {
  method: 'POST',
  headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
  body: JSON.stringify({
    profileId: '67460e74-02e3-11e8-b443-00163e990bdb',
    entityReference: 'Company_Club',
    transactionTimestamp: '2020-02-08 09:30:26',
    taxAmount: 1,
    grossAmount: 6,
    netAmount: 5,
    transactionItems: [
      {
        grossAmount: 6,
        netAmount: 5,
        categories: ['Proteins', 'Adults'],
        itemPrice: 5,
        itemQuantity: 1,
        SKU: '123456',
        taxAmount: 1,
        itemName: 'Whey'
      }
    ]
  })
};

fetch('https://vanilla-dev02-loyalty.fabric.zone/api/v1/discounts', 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://vanilla-dev02-loyalty.fabric.zone/api/v1/discounts",
  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([
    'profileId' => '67460e74-02e3-11e8-b443-00163e990bdb',
    'entityReference' => 'Company_Club',
    'transactionTimestamp' => '2020-02-08 09:30:26',
    'taxAmount' => 1,
    'grossAmount' => 6,
    'netAmount' => 5,
    'transactionItems' => [
        [
                'grossAmount' => 6,
                'netAmount' => 5,
                'categories' => [
                                'Proteins',
                                'Adults'
                ],
                'itemPrice' => 5,
                'itemQuantity' => 1,
                'SKU' => '123456',
                'taxAmount' => 1,
                'itemName' => 'Whey'
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "Content-Type: application/json"
  ],
]);

$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://vanilla-dev02-loyalty.fabric.zone/api/v1/discounts"

payload := strings.NewReader("{\n  \"profileId\": \"67460e74-02e3-11e8-b443-00163e990bdb\",\n  \"entityReference\": \"Company_Club\",\n  \"transactionTimestamp\": \"2020-02-08 09:30:26\",\n  \"taxAmount\": 1,\n  \"grossAmount\": 6,\n  \"netAmount\": 5,\n  \"transactionItems\": [\n    {\n      \"grossAmount\": 6,\n      \"netAmount\": 5,\n      \"categories\": [\n        \"Proteins\",\n        \"Adults\"\n      ],\n      \"itemPrice\": 5,\n      \"itemQuantity\": 1,\n      \"SKU\": \"123456\",\n      \"taxAmount\": 1,\n      \"itemName\": \"Whey\"\n    }\n  ]\n}")

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

req.Header.Add("Authorization", "Bearer <token>")
    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))
}

Response

200

{
  "status": 200,
  "message": "Created",
  "errors": {},
  "data": [
    {
      "grossAmount": 6,
      "taxAmount": 1,
      "netAmount": 4,
      "discounts": [
        {
          "value": 1,
          "type": "tier",
          "description": "20.0% discount from tier rule.",
          "id": 23,
          "ruleName": "tier-discount-rule",
          "discountPercentage": 20,
          "discountAmount": 1
        }
      ],
      "transactionItems": [
        {
          "SKU": "123456",
          "discounts": []
        }
      ],
      "miscellaneous": []
    }
  ]
}

400

{
  "message": "Error message string",
  "errors": {
    "ExceptionString": ["Invalid Field"]
  },
  "data": null,
  "status": 400
}

401

{
  "detail": "Authentication Failed"
}