curl --request POST \
--url https://api.fabric.inc/v3/coupons \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
--data @- <<EOF
{
"name": "Christmas 2022 coupons",
"startAt": "2022-08-24T14:15:22.000Z",
"endAt": "2019-08-25T14:15:22.000Z",
"type": "PRODUCT",
"couponCodes": [
"XMAS2022"
],
"details": [
{
"discounts": [
{
"unit": "PERCENTAGE_OFF",
"amount": 15,
"type": "SKU",
"values": "null",
"maximumQuantity": 2,
"includeOperator": "OR",
"excludeOperator": "AND",
"discountId": "1",
"isAutoAdd": false,
"sets": [
"A"
]
}
],
"targetProducts": [
{
"type": "SKU",
"values": "*",
"operator": "IN",
"discountId": "1"
}
],
"conditions": [
{
"operator": "AND",
"conditions": [
{
"type": "SKU",
"values": "*",
"operator": "IN"
}
],
"id": "6380e7ecb419a30009865fad",
"includeOperator": "OR",
"excludeOperator": "AND",
"set": "A"
}
]
}
],
"buyOperator": "OR",
"isExclusive": true,
"limits": [
{
"type": "SITE_WIDE",
"quantity": 30
}
],
"termsAndConditions": [
{
"name": "Terms Applied",
"description": "Items can't be exchanged"
}
],
"promotionMessages": [
{
"title": "Buy 2 get 1 free",
"message": "Offer valid at participating stores through September 5, 2023.",
"pages": [
"PDP",
"Cart"
],
"locales": [
"en-CA",
"fr-CA"
]
}
],
"proximityMessages": {
"threshold": 1,
"localizedMessages": [
{
"locales": [
"en-CA"
],
"message": "Buy some more to get the discount!"
}
]
},
"shipmentMethodIds": [
"1000001"
],
"eligiblePriceLists": [
10000056
],
"additionalAttributes": [
{
"name": "eventName",
"values": "Store sale"
}
],
"note": "Independence day sale!",
"level": 3,
"stackingType": "STACKABLE",
"isStackable": false,
"isAlwaysApplied": false,
"singleMultiUse": "MULTI_USE"
}
EOFimport requests
url = "https://api.fabric.inc/v3/coupons"
payload = {
"name": "Christmas 2022 coupons",
"startAt": "2022-08-24T14:15:22.000Z",
"endAt": "2019-08-25T14:15:22.000Z",
"type": "PRODUCT",
"couponCodes": ["XMAS2022"],
"details": [
{
"discounts": [
{
"unit": "PERCENTAGE_OFF",
"amount": 15,
"type": "SKU",
"values": "null",
"maximumQuantity": 2,
"includeOperator": "OR",
"excludeOperator": "AND",
"discountId": "1",
"isAutoAdd": False,
"sets": ["A"]
}
],
"targetProducts": [
{
"type": "SKU",
"values": "*",
"operator": "IN",
"discountId": "1"
}
],
"conditions": [
{
"operator": "AND",
"conditions": [
{
"type": "SKU",
"values": "*",
"operator": "IN"
}
],
"id": "6380e7ecb419a30009865fad",
"includeOperator": "OR",
"excludeOperator": "AND",
"set": "A"
}
]
}
],
"buyOperator": "OR",
"isExclusive": True,
"limits": [
{
"type": "SITE_WIDE",
"quantity": 30
}
],
"termsAndConditions": [
{
"name": "Terms Applied",
"description": "Items can't be exchanged"
}
],
"promotionMessages": [
{
"title": "Buy 2 get 1 free",
"message": "Offer valid at participating stores through September 5, 2023.",
"pages": ["PDP", "Cart"],
"locales": ["en-CA", "fr-CA"]
}
],
"proximityMessages": {
"threshold": 1,
"localizedMessages": [
{
"locales": ["en-CA"],
"message": "Buy some more to get the discount!"
}
]
},
"shipmentMethodIds": ["1000001"],
"eligiblePriceLists": [10000056],
"additionalAttributes": [
{
"name": "eventName",
"values": "Store sale"
}
],
"note": "Independence day sale!",
"level": 3,
"stackingType": "STACKABLE",
"isStackable": False,
"isAlwaysApplied": False,
"singleMultiUse": "MULTI_USE"
}
headers = {
"x-fabric-tenant-id": "<x-fabric-tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-fabric-tenant-id': '<x-fabric-tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Christmas 2022 coupons',
startAt: '2022-08-24T14:15:22.000Z',
endAt: '2019-08-25T14:15:22.000Z',
type: 'PRODUCT',
couponCodes: ['XMAS2022'],
details: [
{
discounts: [
{
unit: 'PERCENTAGE_OFF',
amount: 15,
type: 'SKU',
values: 'null',
maximumQuantity: 2,
includeOperator: 'OR',
excludeOperator: 'AND',
discountId: '1',
isAutoAdd: false,
sets: ['A']
}
],
targetProducts: [{type: 'SKU', values: '*', operator: 'IN', discountId: '1'}],
conditions: [
{
operator: 'AND',
conditions: [{type: 'SKU', values: '*', operator: 'IN'}],
id: '6380e7ecb419a30009865fad',
includeOperator: 'OR',
excludeOperator: 'AND',
set: 'A'
}
]
}
],
buyOperator: 'OR',
isExclusive: true,
limits: [{type: 'SITE_WIDE', quantity: 30}],
termsAndConditions: [{name: 'Terms Applied', description: 'Items can\'t be exchanged'}],
promotionMessages: [
{
title: 'Buy 2 get 1 free',
message: 'Offer valid at participating stores through September 5, 2023.',
pages: ['PDP', 'Cart'],
locales: ['en-CA', 'fr-CA']
}
],
proximityMessages: {
threshold: 1,
localizedMessages: [{locales: ['en-CA'], message: 'Buy some more to get the discount!'}]
},
shipmentMethodIds: ['1000001'],
eligiblePriceLists: [10000056],
additionalAttributes: [{name: 'eventName', values: 'Store sale'}],
note: 'Independence day sale!',
level: 3,
stackingType: 'STACKABLE',
isStackable: false,
isAlwaysApplied: false,
singleMultiUse: 'MULTI_USE'
})
};
fetch('https://api.fabric.inc/v3/coupons', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.fabric.inc/v3/coupons",
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([
'name' => 'Christmas 2022 coupons',
'startAt' => '2022-08-24T14:15:22.000Z',
'endAt' => '2019-08-25T14:15:22.000Z',
'type' => 'PRODUCT',
'couponCodes' => [
'XMAS2022'
],
'details' => [
[
'discounts' => [
[
'unit' => 'PERCENTAGE_OFF',
'amount' => 15,
'type' => 'SKU',
'values' => 'null',
'maximumQuantity' => 2,
'includeOperator' => 'OR',
'excludeOperator' => 'AND',
'discountId' => '1',
'isAutoAdd' => false,
'sets' => [
'A'
]
]
],
'targetProducts' => [
[
'type' => 'SKU',
'values' => '*',
'operator' => 'IN',
'discountId' => '1'
]
],
'conditions' => [
[
'operator' => 'AND',
'conditions' => [
[
'type' => 'SKU',
'values' => '*',
'operator' => 'IN'
]
],
'id' => '6380e7ecb419a30009865fad',
'includeOperator' => 'OR',
'excludeOperator' => 'AND',
'set' => 'A'
]
]
]
],
'buyOperator' => 'OR',
'isExclusive' => true,
'limits' => [
[
'type' => 'SITE_WIDE',
'quantity' => 30
]
],
'termsAndConditions' => [
[
'name' => 'Terms Applied',
'description' => 'Items can\'t be exchanged'
]
],
'promotionMessages' => [
[
'title' => 'Buy 2 get 1 free',
'message' => 'Offer valid at participating stores through September 5, 2023.',
'pages' => [
'PDP',
'Cart'
],
'locales' => [
'en-CA',
'fr-CA'
]
]
],
'proximityMessages' => [
'threshold' => 1,
'localizedMessages' => [
[
'locales' => [
'en-CA'
],
'message' => 'Buy some more to get the discount!'
]
]
],
'shipmentMethodIds' => [
'1000001'
],
'eligiblePriceLists' => [
10000056
],
'additionalAttributes' => [
[
'name' => 'eventName',
'values' => 'Store sale'
]
],
'note' => 'Independence day sale!',
'level' => 3,
'stackingType' => 'STACKABLE',
'isStackable' => false,
'isAlwaysApplied' => false,
'singleMultiUse' => 'MULTI_USE'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"x-fabric-tenant-id: <x-fabric-tenant-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.fabric.inc/v3/coupons"
payload := strings.NewReader("{\n \"name\": \"Christmas 2022 coupons\",\n \"startAt\": \"2022-08-24T14:15:22.000Z\",\n \"endAt\": \"2019-08-25T14:15:22.000Z\",\n \"type\": \"PRODUCT\",\n \"couponCodes\": [\n \"XMAS2022\"\n ],\n \"details\": [\n {\n \"discounts\": [\n {\n \"unit\": \"PERCENTAGE_OFF\",\n \"amount\": 15,\n \"type\": \"SKU\",\n \"values\": \"null\",\n \"maximumQuantity\": 2,\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"discountId\": \"1\",\n \"isAutoAdd\": false,\n \"sets\": [\n \"A\"\n ]\n }\n ],\n \"targetProducts\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\",\n \"discountId\": \"1\"\n }\n ],\n \"conditions\": [\n {\n \"operator\": \"AND\",\n \"conditions\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\"\n }\n ],\n \"id\": \"6380e7ecb419a30009865fad\",\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"set\": \"A\"\n }\n ]\n }\n ],\n \"buyOperator\": \"OR\",\n \"isExclusive\": true,\n \"limits\": [\n {\n \"type\": \"SITE_WIDE\",\n \"quantity\": 30\n }\n ],\n \"termsAndConditions\": [\n {\n \"name\": \"Terms Applied\",\n \"description\": \"Items can't be exchanged\"\n }\n ],\n \"promotionMessages\": [\n {\n \"title\": \"Buy 2 get 1 free\",\n \"message\": \"Offer valid at participating stores through September 5, 2023.\",\n \"pages\": [\n \"PDP\",\n \"Cart\"\n ],\n \"locales\": [\n \"en-CA\",\n \"fr-CA\"\n ]\n }\n ],\n \"proximityMessages\": {\n \"threshold\": 1,\n \"localizedMessages\": [\n {\n \"locales\": [\n \"en-CA\"\n ],\n \"message\": \"Buy some more to get the discount!\"\n }\n ]\n },\n \"shipmentMethodIds\": [\n \"1000001\"\n ],\n \"eligiblePriceLists\": [\n 10000056\n ],\n \"additionalAttributes\": [\n {\n \"name\": \"eventName\",\n \"values\": \"Store sale\"\n }\n ],\n \"note\": \"Independence day sale!\",\n \"level\": 3,\n \"stackingType\": \"STACKABLE\",\n \"isStackable\": false,\n \"isAlwaysApplied\": false,\n \"singleMultiUse\": \"MULTI_USE\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-fabric-tenant-id", "<x-fabric-tenant-id>")
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))
}HttpResponse<String> response = Unirest.post("https://api.fabric.inc/v3/coupons")
.header("x-fabric-tenant-id", "<x-fabric-tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Christmas 2022 coupons\",\n \"startAt\": \"2022-08-24T14:15:22.000Z\",\n \"endAt\": \"2019-08-25T14:15:22.000Z\",\n \"type\": \"PRODUCT\",\n \"couponCodes\": [\n \"XMAS2022\"\n ],\n \"details\": [\n {\n \"discounts\": [\n {\n \"unit\": \"PERCENTAGE_OFF\",\n \"amount\": 15,\n \"type\": \"SKU\",\n \"values\": \"null\",\n \"maximumQuantity\": 2,\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"discountId\": \"1\",\n \"isAutoAdd\": false,\n \"sets\": [\n \"A\"\n ]\n }\n ],\n \"targetProducts\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\",\n \"discountId\": \"1\"\n }\n ],\n \"conditions\": [\n {\n \"operator\": \"AND\",\n \"conditions\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\"\n }\n ],\n \"id\": \"6380e7ecb419a30009865fad\",\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"set\": \"A\"\n }\n ]\n }\n ],\n \"buyOperator\": \"OR\",\n \"isExclusive\": true,\n \"limits\": [\n {\n \"type\": \"SITE_WIDE\",\n \"quantity\": 30\n }\n ],\n \"termsAndConditions\": [\n {\n \"name\": \"Terms Applied\",\n \"description\": \"Items can't be exchanged\"\n }\n ],\n \"promotionMessages\": [\n {\n \"title\": \"Buy 2 get 1 free\",\n \"message\": \"Offer valid at participating stores through September 5, 2023.\",\n \"pages\": [\n \"PDP\",\n \"Cart\"\n ],\n \"locales\": [\n \"en-CA\",\n \"fr-CA\"\n ]\n }\n ],\n \"proximityMessages\": {\n \"threshold\": 1,\n \"localizedMessages\": [\n {\n \"locales\": [\n \"en-CA\"\n ],\n \"message\": \"Buy some more to get the discount!\"\n }\n ]\n },\n \"shipmentMethodIds\": [\n \"1000001\"\n ],\n \"eligiblePriceLists\": [\n 10000056\n ],\n \"additionalAttributes\": [\n {\n \"name\": \"eventName\",\n \"values\": \"Store sale\"\n }\n ],\n \"note\": \"Independence day sale!\",\n \"level\": 3,\n \"stackingType\": \"STACKABLE\",\n \"isStackable\": false,\n \"isAlwaysApplied\": false,\n \"singleMultiUse\": \"MULTI_USE\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fabric.inc/v3/coupons")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-fabric-tenant-id"] = '<x-fabric-tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Christmas 2022 coupons\",\n \"startAt\": \"2022-08-24T14:15:22.000Z\",\n \"endAt\": \"2019-08-25T14:15:22.000Z\",\n \"type\": \"PRODUCT\",\n \"couponCodes\": [\n \"XMAS2022\"\n ],\n \"details\": [\n {\n \"discounts\": [\n {\n \"unit\": \"PERCENTAGE_OFF\",\n \"amount\": 15,\n \"type\": \"SKU\",\n \"values\": \"null\",\n \"maximumQuantity\": 2,\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"discountId\": \"1\",\n \"isAutoAdd\": false,\n \"sets\": [\n \"A\"\n ]\n }\n ],\n \"targetProducts\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\",\n \"discountId\": \"1\"\n }\n ],\n \"conditions\": [\n {\n \"operator\": \"AND\",\n \"conditions\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\"\n }\n ],\n \"id\": \"6380e7ecb419a30009865fad\",\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"set\": \"A\"\n }\n ]\n }\n ],\n \"buyOperator\": \"OR\",\n \"isExclusive\": true,\n \"limits\": [\n {\n \"type\": \"SITE_WIDE\",\n \"quantity\": 30\n }\n ],\n \"termsAndConditions\": [\n {\n \"name\": \"Terms Applied\",\n \"description\": \"Items can't be exchanged\"\n }\n ],\n \"promotionMessages\": [\n {\n \"title\": \"Buy 2 get 1 free\",\n \"message\": \"Offer valid at participating stores through September 5, 2023.\",\n \"pages\": [\n \"PDP\",\n \"Cart\"\n ],\n \"locales\": [\n \"en-CA\",\n \"fr-CA\"\n ]\n }\n ],\n \"proximityMessages\": {\n \"threshold\": 1,\n \"localizedMessages\": [\n {\n \"locales\": [\n \"en-CA\"\n ],\n \"message\": \"Buy some more to get the discount!\"\n }\n ]\n },\n \"shipmentMethodIds\": [\n \"1000001\"\n ],\n \"eligiblePriceLists\": [\n 10000056\n ],\n \"additionalAttributes\": [\n {\n \"name\": \"eventName\",\n \"values\": \"Store sale\"\n }\n ],\n \"note\": \"Independence day sale!\",\n \"level\": 3,\n \"stackingType\": \"STACKABLE\",\n \"isStackable\": false,\n \"isAlwaysApplied\": false,\n \"singleMultiUse\": \"MULTI_USE\"\n}"
response = http.request(request)
puts response.read_body{
"id": "6380e7ecb419a30009865fad",
"name": "Christmas 2022 coupons",
"status": "SCHEDULED",
"startAt": "2022-08-24T14:15:22.000Z",
"endAt": "2019-08-25T14:15:22.000Z",
"type": "PRODUCT",
"createdAt": "2019-08-20T14:15:22.000Z",
"updatedAt": "2019-08-20T14:15:22.000Z",
"couponCodesCount": 100,
"level": 3,
"stackingType": "STACKABLE",
"isStackable": false,
"isAlwaysApplied": false,
"singleMultiUse": "MULTI_USE",
"couponCodes": [
"SUMMER1000001"
],
"promotionMessages": [
{
"title": "Buy 2 get 1 free",
"message": "Offer valid at participating stores through September 5, 2023.",
"pages": [
"PDP",
"Cart"
],
"locales": [
"en-CA",
"fr-CA"
]
}
],
"additionalAttributes": [
{
"name": "type",
"values": "Birthday",
"attributeId": 100000
}
]
}{
"type": "PROMO_TITLE_EXISTS",
"message": "Promotion name already exists"
}{
"type": "UNAUTHORIZED",
"message": "Invalid credentials"
}{
"type": "INTERNAL_SERVER_ERROR",
"message": "Internal server error"
}Create coupon
Create a coupon with the requested conditions.
curl --request POST \
--url https://api.fabric.inc/v3/coupons \
--header 'Authorization: Bearer <token>' \
--header 'Content-Type: application/json' \
--header 'x-fabric-tenant-id: <x-fabric-tenant-id>' \
--data @- <<EOF
{
"name": "Christmas 2022 coupons",
"startAt": "2022-08-24T14:15:22.000Z",
"endAt": "2019-08-25T14:15:22.000Z",
"type": "PRODUCT",
"couponCodes": [
"XMAS2022"
],
"details": [
{
"discounts": [
{
"unit": "PERCENTAGE_OFF",
"amount": 15,
"type": "SKU",
"values": "null",
"maximumQuantity": 2,
"includeOperator": "OR",
"excludeOperator": "AND",
"discountId": "1",
"isAutoAdd": false,
"sets": [
"A"
]
}
],
"targetProducts": [
{
"type": "SKU",
"values": "*",
"operator": "IN",
"discountId": "1"
}
],
"conditions": [
{
"operator": "AND",
"conditions": [
{
"type": "SKU",
"values": "*",
"operator": "IN"
}
],
"id": "6380e7ecb419a30009865fad",
"includeOperator": "OR",
"excludeOperator": "AND",
"set": "A"
}
]
}
],
"buyOperator": "OR",
"isExclusive": true,
"limits": [
{
"type": "SITE_WIDE",
"quantity": 30
}
],
"termsAndConditions": [
{
"name": "Terms Applied",
"description": "Items can't be exchanged"
}
],
"promotionMessages": [
{
"title": "Buy 2 get 1 free",
"message": "Offer valid at participating stores through September 5, 2023.",
"pages": [
"PDP",
"Cart"
],
"locales": [
"en-CA",
"fr-CA"
]
}
],
"proximityMessages": {
"threshold": 1,
"localizedMessages": [
{
"locales": [
"en-CA"
],
"message": "Buy some more to get the discount!"
}
]
},
"shipmentMethodIds": [
"1000001"
],
"eligiblePriceLists": [
10000056
],
"additionalAttributes": [
{
"name": "eventName",
"values": "Store sale"
}
],
"note": "Independence day sale!",
"level": 3,
"stackingType": "STACKABLE",
"isStackable": false,
"isAlwaysApplied": false,
"singleMultiUse": "MULTI_USE"
}
EOFimport requests
url = "https://api.fabric.inc/v3/coupons"
payload = {
"name": "Christmas 2022 coupons",
"startAt": "2022-08-24T14:15:22.000Z",
"endAt": "2019-08-25T14:15:22.000Z",
"type": "PRODUCT",
"couponCodes": ["XMAS2022"],
"details": [
{
"discounts": [
{
"unit": "PERCENTAGE_OFF",
"amount": 15,
"type": "SKU",
"values": "null",
"maximumQuantity": 2,
"includeOperator": "OR",
"excludeOperator": "AND",
"discountId": "1",
"isAutoAdd": False,
"sets": ["A"]
}
],
"targetProducts": [
{
"type": "SKU",
"values": "*",
"operator": "IN",
"discountId": "1"
}
],
"conditions": [
{
"operator": "AND",
"conditions": [
{
"type": "SKU",
"values": "*",
"operator": "IN"
}
],
"id": "6380e7ecb419a30009865fad",
"includeOperator": "OR",
"excludeOperator": "AND",
"set": "A"
}
]
}
],
"buyOperator": "OR",
"isExclusive": True,
"limits": [
{
"type": "SITE_WIDE",
"quantity": 30
}
],
"termsAndConditions": [
{
"name": "Terms Applied",
"description": "Items can't be exchanged"
}
],
"promotionMessages": [
{
"title": "Buy 2 get 1 free",
"message": "Offer valid at participating stores through September 5, 2023.",
"pages": ["PDP", "Cart"],
"locales": ["en-CA", "fr-CA"]
}
],
"proximityMessages": {
"threshold": 1,
"localizedMessages": [
{
"locales": ["en-CA"],
"message": "Buy some more to get the discount!"
}
]
},
"shipmentMethodIds": ["1000001"],
"eligiblePriceLists": [10000056],
"additionalAttributes": [
{
"name": "eventName",
"values": "Store sale"
}
],
"note": "Independence day sale!",
"level": 3,
"stackingType": "STACKABLE",
"isStackable": False,
"isAlwaysApplied": False,
"singleMultiUse": "MULTI_USE"
}
headers = {
"x-fabric-tenant-id": "<x-fabric-tenant-id>",
"Authorization": "Bearer <token>",
"Content-Type": "application/json"
}
response = requests.post(url, json=payload, headers=headers)
print(response.text)const options = {
method: 'POST',
headers: {
'x-fabric-tenant-id': '<x-fabric-tenant-id>',
Authorization: 'Bearer <token>',
'Content-Type': 'application/json'
},
body: JSON.stringify({
name: 'Christmas 2022 coupons',
startAt: '2022-08-24T14:15:22.000Z',
endAt: '2019-08-25T14:15:22.000Z',
type: 'PRODUCT',
couponCodes: ['XMAS2022'],
details: [
{
discounts: [
{
unit: 'PERCENTAGE_OFF',
amount: 15,
type: 'SKU',
values: 'null',
maximumQuantity: 2,
includeOperator: 'OR',
excludeOperator: 'AND',
discountId: '1',
isAutoAdd: false,
sets: ['A']
}
],
targetProducts: [{type: 'SKU', values: '*', operator: 'IN', discountId: '1'}],
conditions: [
{
operator: 'AND',
conditions: [{type: 'SKU', values: '*', operator: 'IN'}],
id: '6380e7ecb419a30009865fad',
includeOperator: 'OR',
excludeOperator: 'AND',
set: 'A'
}
]
}
],
buyOperator: 'OR',
isExclusive: true,
limits: [{type: 'SITE_WIDE', quantity: 30}],
termsAndConditions: [{name: 'Terms Applied', description: 'Items can\'t be exchanged'}],
promotionMessages: [
{
title: 'Buy 2 get 1 free',
message: 'Offer valid at participating stores through September 5, 2023.',
pages: ['PDP', 'Cart'],
locales: ['en-CA', 'fr-CA']
}
],
proximityMessages: {
threshold: 1,
localizedMessages: [{locales: ['en-CA'], message: 'Buy some more to get the discount!'}]
},
shipmentMethodIds: ['1000001'],
eligiblePriceLists: [10000056],
additionalAttributes: [{name: 'eventName', values: 'Store sale'}],
note: 'Independence day sale!',
level: 3,
stackingType: 'STACKABLE',
isStackable: false,
isAlwaysApplied: false,
singleMultiUse: 'MULTI_USE'
})
};
fetch('https://api.fabric.inc/v3/coupons', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));<?php
$curl = curl_init();
curl_setopt_array($curl, [
CURLOPT_URL => "https://api.fabric.inc/v3/coupons",
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([
'name' => 'Christmas 2022 coupons',
'startAt' => '2022-08-24T14:15:22.000Z',
'endAt' => '2019-08-25T14:15:22.000Z',
'type' => 'PRODUCT',
'couponCodes' => [
'XMAS2022'
],
'details' => [
[
'discounts' => [
[
'unit' => 'PERCENTAGE_OFF',
'amount' => 15,
'type' => 'SKU',
'values' => 'null',
'maximumQuantity' => 2,
'includeOperator' => 'OR',
'excludeOperator' => 'AND',
'discountId' => '1',
'isAutoAdd' => false,
'sets' => [
'A'
]
]
],
'targetProducts' => [
[
'type' => 'SKU',
'values' => '*',
'operator' => 'IN',
'discountId' => '1'
]
],
'conditions' => [
[
'operator' => 'AND',
'conditions' => [
[
'type' => 'SKU',
'values' => '*',
'operator' => 'IN'
]
],
'id' => '6380e7ecb419a30009865fad',
'includeOperator' => 'OR',
'excludeOperator' => 'AND',
'set' => 'A'
]
]
]
],
'buyOperator' => 'OR',
'isExclusive' => true,
'limits' => [
[
'type' => 'SITE_WIDE',
'quantity' => 30
]
],
'termsAndConditions' => [
[
'name' => 'Terms Applied',
'description' => 'Items can\'t be exchanged'
]
],
'promotionMessages' => [
[
'title' => 'Buy 2 get 1 free',
'message' => 'Offer valid at participating stores through September 5, 2023.',
'pages' => [
'PDP',
'Cart'
],
'locales' => [
'en-CA',
'fr-CA'
]
]
],
'proximityMessages' => [
'threshold' => 1,
'localizedMessages' => [
[
'locales' => [
'en-CA'
],
'message' => 'Buy some more to get the discount!'
]
]
],
'shipmentMethodIds' => [
'1000001'
],
'eligiblePriceLists' => [
10000056
],
'additionalAttributes' => [
[
'name' => 'eventName',
'values' => 'Store sale'
]
],
'note' => 'Independence day sale!',
'level' => 3,
'stackingType' => 'STACKABLE',
'isStackable' => false,
'isAlwaysApplied' => false,
'singleMultiUse' => 'MULTI_USE'
]),
CURLOPT_HTTPHEADER => [
"Authorization: Bearer <token>",
"Content-Type: application/json",
"x-fabric-tenant-id: <x-fabric-tenant-id>"
],
]);
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
} else {
echo $response;
}package main
import (
"fmt"
"strings"
"net/http"
"io"
)
func main() {
url := "https://api.fabric.inc/v3/coupons"
payload := strings.NewReader("{\n \"name\": \"Christmas 2022 coupons\",\n \"startAt\": \"2022-08-24T14:15:22.000Z\",\n \"endAt\": \"2019-08-25T14:15:22.000Z\",\n \"type\": \"PRODUCT\",\n \"couponCodes\": [\n \"XMAS2022\"\n ],\n \"details\": [\n {\n \"discounts\": [\n {\n \"unit\": \"PERCENTAGE_OFF\",\n \"amount\": 15,\n \"type\": \"SKU\",\n \"values\": \"null\",\n \"maximumQuantity\": 2,\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"discountId\": \"1\",\n \"isAutoAdd\": false,\n \"sets\": [\n \"A\"\n ]\n }\n ],\n \"targetProducts\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\",\n \"discountId\": \"1\"\n }\n ],\n \"conditions\": [\n {\n \"operator\": \"AND\",\n \"conditions\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\"\n }\n ],\n \"id\": \"6380e7ecb419a30009865fad\",\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"set\": \"A\"\n }\n ]\n }\n ],\n \"buyOperator\": \"OR\",\n \"isExclusive\": true,\n \"limits\": [\n {\n \"type\": \"SITE_WIDE\",\n \"quantity\": 30\n }\n ],\n \"termsAndConditions\": [\n {\n \"name\": \"Terms Applied\",\n \"description\": \"Items can't be exchanged\"\n }\n ],\n \"promotionMessages\": [\n {\n \"title\": \"Buy 2 get 1 free\",\n \"message\": \"Offer valid at participating stores through September 5, 2023.\",\n \"pages\": [\n \"PDP\",\n \"Cart\"\n ],\n \"locales\": [\n \"en-CA\",\n \"fr-CA\"\n ]\n }\n ],\n \"proximityMessages\": {\n \"threshold\": 1,\n \"localizedMessages\": [\n {\n \"locales\": [\n \"en-CA\"\n ],\n \"message\": \"Buy some more to get the discount!\"\n }\n ]\n },\n \"shipmentMethodIds\": [\n \"1000001\"\n ],\n \"eligiblePriceLists\": [\n 10000056\n ],\n \"additionalAttributes\": [\n {\n \"name\": \"eventName\",\n \"values\": \"Store sale\"\n }\n ],\n \"note\": \"Independence day sale!\",\n \"level\": 3,\n \"stackingType\": \"STACKABLE\",\n \"isStackable\": false,\n \"isAlwaysApplied\": false,\n \"singleMultiUse\": \"MULTI_USE\"\n}")
req, _ := http.NewRequest("POST", url, payload)
req.Header.Add("x-fabric-tenant-id", "<x-fabric-tenant-id>")
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))
}HttpResponse<String> response = Unirest.post("https://api.fabric.inc/v3/coupons")
.header("x-fabric-tenant-id", "<x-fabric-tenant-id>")
.header("Authorization", "Bearer <token>")
.header("Content-Type", "application/json")
.body("{\n \"name\": \"Christmas 2022 coupons\",\n \"startAt\": \"2022-08-24T14:15:22.000Z\",\n \"endAt\": \"2019-08-25T14:15:22.000Z\",\n \"type\": \"PRODUCT\",\n \"couponCodes\": [\n \"XMAS2022\"\n ],\n \"details\": [\n {\n \"discounts\": [\n {\n \"unit\": \"PERCENTAGE_OFF\",\n \"amount\": 15,\n \"type\": \"SKU\",\n \"values\": \"null\",\n \"maximumQuantity\": 2,\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"discountId\": \"1\",\n \"isAutoAdd\": false,\n \"sets\": [\n \"A\"\n ]\n }\n ],\n \"targetProducts\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\",\n \"discountId\": \"1\"\n }\n ],\n \"conditions\": [\n {\n \"operator\": \"AND\",\n \"conditions\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\"\n }\n ],\n \"id\": \"6380e7ecb419a30009865fad\",\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"set\": \"A\"\n }\n ]\n }\n ],\n \"buyOperator\": \"OR\",\n \"isExclusive\": true,\n \"limits\": [\n {\n \"type\": \"SITE_WIDE\",\n \"quantity\": 30\n }\n ],\n \"termsAndConditions\": [\n {\n \"name\": \"Terms Applied\",\n \"description\": \"Items can't be exchanged\"\n }\n ],\n \"promotionMessages\": [\n {\n \"title\": \"Buy 2 get 1 free\",\n \"message\": \"Offer valid at participating stores through September 5, 2023.\",\n \"pages\": [\n \"PDP\",\n \"Cart\"\n ],\n \"locales\": [\n \"en-CA\",\n \"fr-CA\"\n ]\n }\n ],\n \"proximityMessages\": {\n \"threshold\": 1,\n \"localizedMessages\": [\n {\n \"locales\": [\n \"en-CA\"\n ],\n \"message\": \"Buy some more to get the discount!\"\n }\n ]\n },\n \"shipmentMethodIds\": [\n \"1000001\"\n ],\n \"eligiblePriceLists\": [\n 10000056\n ],\n \"additionalAttributes\": [\n {\n \"name\": \"eventName\",\n \"values\": \"Store sale\"\n }\n ],\n \"note\": \"Independence day sale!\",\n \"level\": 3,\n \"stackingType\": \"STACKABLE\",\n \"isStackable\": false,\n \"isAlwaysApplied\": false,\n \"singleMultiUse\": \"MULTI_USE\"\n}")
.asString();require 'uri'
require 'net/http'
url = URI("https://api.fabric.inc/v3/coupons")
http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true
request = Net::HTTP::Post.new(url)
request["x-fabric-tenant-id"] = '<x-fabric-tenant-id>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n \"name\": \"Christmas 2022 coupons\",\n \"startAt\": \"2022-08-24T14:15:22.000Z\",\n \"endAt\": \"2019-08-25T14:15:22.000Z\",\n \"type\": \"PRODUCT\",\n \"couponCodes\": [\n \"XMAS2022\"\n ],\n \"details\": [\n {\n \"discounts\": [\n {\n \"unit\": \"PERCENTAGE_OFF\",\n \"amount\": 15,\n \"type\": \"SKU\",\n \"values\": \"null\",\n \"maximumQuantity\": 2,\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"discountId\": \"1\",\n \"isAutoAdd\": false,\n \"sets\": [\n \"A\"\n ]\n }\n ],\n \"targetProducts\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\",\n \"discountId\": \"1\"\n }\n ],\n \"conditions\": [\n {\n \"operator\": \"AND\",\n \"conditions\": [\n {\n \"type\": \"SKU\",\n \"values\": \"*\",\n \"operator\": \"IN\"\n }\n ],\n \"id\": \"6380e7ecb419a30009865fad\",\n \"includeOperator\": \"OR\",\n \"excludeOperator\": \"AND\",\n \"set\": \"A\"\n }\n ]\n }\n ],\n \"buyOperator\": \"OR\",\n \"isExclusive\": true,\n \"limits\": [\n {\n \"type\": \"SITE_WIDE\",\n \"quantity\": 30\n }\n ],\n \"termsAndConditions\": [\n {\n \"name\": \"Terms Applied\",\n \"description\": \"Items can't be exchanged\"\n }\n ],\n \"promotionMessages\": [\n {\n \"title\": \"Buy 2 get 1 free\",\n \"message\": \"Offer valid at participating stores through September 5, 2023.\",\n \"pages\": [\n \"PDP\",\n \"Cart\"\n ],\n \"locales\": [\n \"en-CA\",\n \"fr-CA\"\n ]\n }\n ],\n \"proximityMessages\": {\n \"threshold\": 1,\n \"localizedMessages\": [\n {\n \"locales\": [\n \"en-CA\"\n ],\n \"message\": \"Buy some more to get the discount!\"\n }\n ]\n },\n \"shipmentMethodIds\": [\n \"1000001\"\n ],\n \"eligiblePriceLists\": [\n 10000056\n ],\n \"additionalAttributes\": [\n {\n \"name\": \"eventName\",\n \"values\": \"Store sale\"\n }\n ],\n \"note\": \"Independence day sale!\",\n \"level\": 3,\n \"stackingType\": \"STACKABLE\",\n \"isStackable\": false,\n \"isAlwaysApplied\": false,\n \"singleMultiUse\": \"MULTI_USE\"\n}"
response = http.request(request)
puts response.read_body{
"id": "6380e7ecb419a30009865fad",
"name": "Christmas 2022 coupons",
"status": "SCHEDULED",
"startAt": "2022-08-24T14:15:22.000Z",
"endAt": "2019-08-25T14:15:22.000Z",
"type": "PRODUCT",
"createdAt": "2019-08-20T14:15:22.000Z",
"updatedAt": "2019-08-20T14:15:22.000Z",
"couponCodesCount": 100,
"level": 3,
"stackingType": "STACKABLE",
"isStackable": false,
"isAlwaysApplied": false,
"singleMultiUse": "MULTI_USE",
"couponCodes": [
"SUMMER1000001"
],
"promotionMessages": [
{
"title": "Buy 2 get 1 free",
"message": "Offer valid at participating stores through September 5, 2023.",
"pages": [
"PDP",
"Cart"
],
"locales": [
"en-CA",
"fr-CA"
]
}
],
"additionalAttributes": [
{
"name": "type",
"values": "Birthday",
"attributeId": 100000
}
]
}{
"type": "PROMO_TITLE_EXISTS",
"message": "Promotion name already exists"
}{
"type": "UNAUTHORIZED",
"message": "Invalid credentials"
}{
"type": "INTERNAL_SERVER_ERROR",
"message": "Internal server error"
}Authorizations
Headers
A header used by fabric to identify the tenant making the request. You must include tenant id in the authentication header for an API request to access any of fabric’s endpoints. You can retrieve the tenant id , which is also called account id, from Copilot. This header is required.
24A unique identifier obtained from Copilot for the System app in the fabric ecosystem, essential for OpenID Connect authentication flows.
Body
Coupon record detail
The type of coupon promotion you want to create. The following are the coupon promotion types you can create:
PRODUCT: A SKU coupon promotion. Applies a discount to SKUs based on the value specified in thediscountobject of the request body.CART: A cart coupon promotion. Applies a discount to the minimum order amount of the cart based on theORDER_VALUEspecified in theconditionobject of the request body.QUANTITY: A quantity coupon promotion. Provides discounts on items based on the quantity requirement set in the promotion.SHIPPING: A shipping coupon promotion. Provides discounts on the shipping cost.BUYGET: A BuyGet coupon promotion. Specifies the Buy conditions and corresponding Get discounts.SPEND_GET: A SpendGet coupon promotion. Specifies the total order value required to qualify for discounts and the applicable discounts based on the order value.
PRODUCT, CART, QUANTITY, SHIPPING, BUYGET, SPEND_GET "PRODUCT"
Defines the rules for how a promotion can be combined with other promotions. This field determines whether a specific promotion can be applied in conjunction with other active promotions during a transaction or if it must be used exclusively. If configured, stackingType will have precedence over the isStackable and isAlwaysApplied Possible values: - STACKABLE: This promotion can be combined with other stackable promotions, allowing multiple
discounts to be applied together. The order in which stackable promotions are applied
is determined by the level field, with promotions having a higher priority (lower numeric value)
being applied before those with a lower priority.
EXCLUSIVE: This promotion can't be combined with any other promotions. Thelevelfield is used to determine which exclusive promotion will be evaluated and applied first. Once an exclusive promotion is applied, no other promotions can be used in the same transaction.TYPE_EXCLUSIVE: This promotion can't be combined with other promotions of the same type. Thelevelfield is used to determine which promotion within the same type will be evaluated and applied first.UNIVERSAL: This promotion can be combined with any other promotions without restrictions. Universal promotions will be evaluated last.
STACKABLE, EXCLUSIVE, TYPE_EXCLUSIVE, UNIVERSAL "STACKABLE"
Response
Created
The coupon details.
A 24-character system-generated coupon ID, generated using the create coupon endpoint.
"6380e7ecb419a30009865fad"
The type of coupon promotion you want to create. The following are the coupon promotion types you can create:
PRODUCT: A SKU coupon promotion. Applies a discount to SKUs based on the value specified in thediscountobject of the request body.CART: A cart coupon promotion. Applies a discount to the minimum order amount of the cart based on theORDER_VALUEspecified in theconditionobject of the request body.QUANTITY: A quantity coupon promotion. Provides discounts on items based on the quantity requirement set in the promotion.SHIPPING: A shipping coupon promotion. Provides discounts on the shipping cost.BUYGET: A BuyGet coupon promotion. Specifies the Buy conditions and corresponding Get discounts.SPEND_GET: A SpendGet coupon promotion. Specifies the total order value required to qualify for discounts and the applicable discounts based on the order value.
PRODUCT, CART, QUANTITY, SHIPPING, BUYGET, SPEND_GET "PRODUCT"
Defines the rules for how a promotion can be combined with other promotions. This field determines whether a specific promotion can be applied in conjunction with other active promotions during a transaction or if it must be used exclusively. If configured, stackingType will have precedence over the isStackable and isAlwaysApplied Possible values: - STACKABLE: This promotion can be combined with other stackable promotions, allowing multiple
discounts to be applied together. The order in which stackable promotions are applied
is determined by the level field, with promotions having a higher priority (lower numeric value)
being applied before those with a lower priority.
EXCLUSIVE: This promotion can't be combined with any other promotions. Thelevelfield is used to determine which exclusive promotion will be evaluated and applied first. Once an exclusive promotion is applied, no other promotions can be used in the same transaction.TYPE_EXCLUSIVE: This promotion can't be combined with other promotions of the same type. Thelevelfield is used to determine which promotion within the same type will be evaluated and applied first.UNIVERSAL: This promotion can be combined with any other promotions without restrictions. Universal promotions will be evaluated last.
STACKABLE, EXCLUSIVE, TYPE_EXCLUSIVE, UNIVERSAL "STACKABLE"
Was this page helpful?
