Create coupon - Fabric

Create coupon

cURL

curl --request POST \
  --url https://live.copilot.fabric.inc/api-offers/coupon/create \
  --header 'Authorization: Bearer <token>' \
  --header 'Content-Type: application/json' \
  --header 'x-site-context: <x-site-context>' \
  --data '
{
  "title": "CREATE COUPON",
  "promo": [
    {
      "discount": [
        {
          "unit": "%OFF",
          "value": 10,
          "ON": {
            "kind": "SKU",
            "value": "*",
            "quantity": 2,
            "includeOperator": "OR",
            "excludeOperator": "AND"
          },
          "discountId": 1,
          "autoAdd": false,
          "set": []
        }
      ],
      "targetProducts": [
        {
          "kind": "SKU",
          "value": "*",
          "operator": "IN",
          "discountId": 1
        }
      ],
      "condition": [
        {
          "conditions": [
            {
              "key": "SKU",
              "value": "*",
              "operator": "IN"
            }
          ],
          "includeOperator": "OR",
          "excludeOperator": "AND",
          "set": "A"
        }
      ]
    }
  ],
  "startDate": "2019-08-24T14:15:22Z",
  "endDate": "2019-08-25T14:15:22Z",
  "isExclusive": true,
  "type": "PRODUCT",
  "promoCodes": [
    [
      "SUMMER100",
      "SUMMER20"
    ]
  ],
  "buyOperator": "OR",
  "stackingType": "STACKABLE",
  "level": 1,
  "termsAndConditions": [
    {
      "title": "Terms Applied",
      "description": "Items cannot be exchanged"
    }
  ],
  "promotionMessages": [
    {
      "title": "Buy 1 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": [
            "<string>"
          ],
          "message": "<string>"
        }
      ]
    }
  ],
  "shipmentMethodIds": [
    "1000001"
  ],
  "eligiblePriceList": [
    10000056
  ],
  "note": "Independence day sale!",
  "limits": [
    {
      "kind": "ORDER",
      "value": 2
    }
  ],
  "additionalAttributes": [
    {
      "key": "type",
      "value": "Birthday",
      "attributeId": 100000
    }
  ]
}
' 

Python

import requests

url = "https://live.copilot.fabric.inc/api-offers/coupon/create"

payload = {
    "title": "CREATE COUPON",
    "promo": [
        {
            "discount": [
                {
                    "unit": "%OFF",
                    "value": 10,
                    "ON": {
                        "kind": "SKU",
                        "value": "*",
                        "quantity": 2,
                        "includeOperator": "OR",
                        "excludeOperator": "AND"
                    },
                    "discountId": 1,
                    "autoAdd": False,
                    "set": []
                }
            ],
            "targetProducts": [
                {
                    "kind": "SKU",
                    "value": "*",
                    "operator": "IN",
                    "discountId": 1
                }
            ],
            "condition": [
                {
                    "conditions": [
                        {
                            "key": "SKU",
                            "value": "*",
                            "operator": "IN"
                        }
                    ],
                    "includeOperator": "OR",
                    "excludeOperator": "AND",
                    "set": "A"
                }
            ]
        }
    ],
    "startDate": "2019-08-24T14:15:22Z",
    "endDate": "2019-08-25T14:15:22Z",
    "isExclusive": True,
    "type": "PRODUCT",
    "promoCodes": [["SUMMER100", "SUMMER20"]],
    "buyOperator": "OR",
    "stackingType": "STACKABLE",
    "level": 1,
    "termsAndConditions": [
        {
            "title": "Terms Applied",
            "description": "Items cannot be exchanged"
        }
    ],
    "promotionMessages": [
        {
            "title": "Buy 1 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": ["<string>"],
                    "message": "<string>"
                }
            ]
        }
    ],
    "shipmentMethodIds": ["1000001"],
    "eligiblePriceList": [10000056],
    "note": "Independence day sale!",
    "limits": [
        {
            "kind": "ORDER",
            "value": 2
        }
    ],
    "additionalAttributes": [
        {
            "key": "type",
            "value": "Birthday",
            "attributeId": 100000
        }
    ]
}
headers = {
    "x-site-context": "<x-site-context>",
    "Authorization": "Bearer <token>",
    "Content-Type": "application/json"
}

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

print(response.text)

Node.js

const options = {
  method: 'POST',
  headers: {
    'x-site-context': '<x-site-context>',
    Authorization: 'Bearer <token>',
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    title: 'CREATE COUPON',
    promo: [
      {
        discount: [
          {
            unit: '%OFF',
            value: 10,
            ON: {
              kind: 'SKU',
              value: '*',
              quantity: 2,
              includeOperator: 'OR',
              excludeOperator: 'AND'
            },
            discountId: 1,
            autoAdd: false,
            set: []
          }
        ],
        targetProducts: [{kind: 'SKU', value: '*', operator: 'IN', discountId: 1}],
        condition: [
          {
            conditions: [{key: 'SKU', value: '*', operator: 'IN'}],
            includeOperator: 'OR',
            excludeOperator: 'AND',
            set: 'A'
          }
        ]
      }
    ],
    startDate: '2019-08-24T14:15:22Z',
    endDate: '2019-08-25T14:15:22Z',
    isExclusive: true,
    type: 'PRODUCT',
    promoCodes: [['SUMMER100', 'SUMMER20']],
    buyOperator: 'OR',
    stackingType: 'STACKABLE',
    level: 1,
    termsAndConditions: [{title: 'Terms Applied', description: 'Items cannot be exchanged'}],
    promotionMessages: [{title: 'Buy 1 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: ['<string>'], message: '<string>'}]}],
    shipmentMethodIds: ['1000001'],
    eligiblePriceList: [10000056],
    note: 'Independence day sale!',
    limits: [{kind: 'ORDER', value: 2}],
    additionalAttributes: [{key: 'type', value: 'Birthday', attributeId: 100000}]
  })
};

fetch('https://live.copilot.fabric.inc/api-offers/coupon/create', 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://live.copilot.fabric.inc/api-offers/coupon/create",
  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([
    'title' => 'CREATE COUPON',
    'promo' => [
        [
                'discount' => [
                                [
                                                                'unit' => '%OFF',
                                                                'value' => 10,
                                                                'ON' => [
                                                                                                                                'kind' => 'SKU',
                                                                                                                                'value' => '*',
                                                                                                                                'quantity' => 2,
                                                                                                                                'includeOperator' => 'OR',
                                                                                                                                'excludeOperator' => 'AND'
                                                                ],
                                                                'discountId' => 1,
                                                                'autoAdd' => false,
                                                                'set' => []
                                ]
                ],
                'targetProducts' => [
                                [
                                                                'kind' => 'SKU',
                                                                'value' => '*',
                                                                'operator' => 'IN',
                                                                'discountId' => 1
                                ]
                ],
                'condition' => [
                                [
                                                                'conditions' => [
                                                                                                                                [
                                                                                                                                                                                                                                                                'key' => 'SKU',
                                                                                                                                                                                                                                                                'value' => '*',
                                                                                                                                                                                                                                                                'operator' => 'IN'
                                                                                                                                ]
                                                                ],
                                                                'includeOperator' => 'OR',
                                                                'excludeOperator' => 'AND',
                                                                'set' => 'A'
                                ]
                ]
        ]
    ],
    'startDate' => '2019-08-24T14:15:22Z',
    'endDate' => '2019-08-25T14:15:22Z',
    'isExclusive' => true,
    'type' => 'PRODUCT',
    'promoCodes' => [
        [
                'SUMMER100',
                'SUMMER20'
        ]
    ],
    'buyOperator' => 'OR',
    'stackingType' => 'STACKABLE',
    'level' => 1,
    'termsAndConditions' => [
        [
                'title' => 'Terms Applied',
                'description' => 'Items cannot be exchanged'
        ]
    ],
    'promotionMessages' => [
        [
                'title' => 'Buy 1 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' => [
                                                                                                                                '<string>'
                                                                ],
                                                                'message' => '<string>'
                                ]
                ]
        ]
    ],
    'shipmentMethodIds' => [
        '1000001'
    ],
    'eligiblePriceList' => [
        10000056
    ],
    'note' => 'Independence day sale!',
    'limits' => [
        [
                'kind' => 'ORDER',
                'value' => 2
        ]
    ],
    'additionalAttributes' => [
        [
                'key' => 'type',
                'value' => 'Birthday',
                'attributeId' => 100000
        ]
    ]
  ]),
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer <token>",
    "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://live.copilot.fabric.inc/api-offers/coupon/create"

payload := strings.NewReader("{\n  \"title\": \"CREATE COUPON\",\n  \"promo\": [\n    {\n      \"discount\": [\n        {\n          \"unit\": \"%OFF\",\n          \"value\": 10,\n          \"ON\": {\n            \"kind\": \"SKU\",\n            \"value\": \"*\",\n            \"quantity\": 2,\n            \"includeOperator\": \"OR\",\n            \"excludeOperator\": \"AND\"\n          },\n          \"discountId\": 1,\n          \"autoAdd\": false,\n          \"set\": []\n        }\n      ],\n      \"targetProducts\": [\n        {\n          \"kind\": \"SKU\",\n          \"value\": \"*\",\n          \"operator\": \"IN\",\n          \"discountId\": 1\n        }\n      ],\n      \"condition\": [\n        {\n          \"conditions\": [\n            {\n              \"key\": \"SKU\",\n              \"value\": \"*\",\n              \"operator\": \"IN\"\n            }\n          ],\n          \"includeOperator\": \"OR\",\n          \"excludeOperator\": \"AND\",\n          \"set\": \"A\"\n        }\n      ]\n    }\n  ],\n  \"startDate\": \"2019-08-24T14:15:22Z\",\n  \"endDate\": \"2019-08-25T14:15:22Z\",\n  \"isExclusive\": true,\n  \"type\": \"PRODUCT\",\n  \"promoCodes\": [[\"SUMMER100\", \"SUMMER20\"]],\n  \"buyOperator\": \"OR\",\n  \"stackingType\": \"STACKABLE\",\n  \"level\": 1,\n  \"termsAndConditions\": [{\n    \"title\": \"Terms Applied\",\n    \"description\": \"Items cannot be exchanged\"\n  }],\n  \"promotionMessages\": [{\n    \"title\": \"Buy 1 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  \"proximityMessages\": [{\n    \"threshold\": 1,\n    \"localizedMessages\": [{\n      \"locales\": [\"<string>\"],\n      \"message\": \"<string>\"\n    }]\n  }],\n  \"shipmentMethodIds\": [\"1000001\"],\n  \"eligiblePriceList\": [10000056],\n  \"note\": \"Independence day sale!\",\n  \"limits\": [{\n    \"kind\": \"ORDER\",\n    \"value\": 2\n  }],\n  \"additionalAttributes\": [{\n    \"key\": \"type\",\n    \"value\": \"Birthday\",\n    \"attributeId\": 100000\n  }]\n}")

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

req.Header.Add("x-site-context", "<x-site-context>")
    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))
}

Java

HttpResponse<String> response = Unirest.post("https://live.copilot.fabric.inc/api-offers/coupon/create")
  .header("x-site-context", "<x-site-context>")
  .header("Authorization", "Bearer <token>")
  .header("Content-Type", "application/json")
  .body("{\n  \"title\": \"CREATE COUPON\",\n  \"promo\": [\n    {\n      \"discount\": [\n        {\n          \"unit\": \"%OFF\",\n          \"value\": 10,\n          \"ON\": {\n            \"kind\": \"SKU\",\n            \"value\": \"*\",\n            \"quantity\": 2,\n            \"includeOperator\": \"OR\",\n            \"excludeOperator\": \"AND\"\n          },\n          \"discountId\": 1,\n          \"autoAdd\": false,\n          \"set\": []\n        }\n      ],\n      \"targetProducts\": [\n        {\n          \"kind\": \"SKU\",\n          \"value\": \"*\",\n          \"operator\": \"IN\",\n          \"discountId\": 1\n        }\n      ],\n      \"condition\": [\n        {\n          \"conditions\": [\n            {\n              \"key\": \"SKU\",\n              \"value\": \"*\",\n              \"operator\": \"IN\"\n            }\n          ],\n          \"includeOperator\": \"OR\",\n          \"excludeOperator\": \"AND\",\n          \"set\": \"A\"\n        }\n      ]\n    }\n  ],\n  \"startDate\": \"2019-08-24T14:15:22Z\",\n  \"endDate\": \"2019-08-25T14:15:22Z\",\n  \"isExclusive\": true,\n  \"type\": \"PRODUCT\",\n  \"promoCodes\": [[\"SUMMER100\", \"SUMMER20\"]],\n  \"buyOperator\": \"OR\",\n  \"stackingType\": \"STACKABLE\",\n  \"level\": 1,\n  \"termsAndConditions\": [{\n    \"title\": \"Terms Applied\",\n    \"description\": \"Items cannot be exchanged\"\n  }],\n  \"promotionMessages\": [{\n    \"title\": \"Buy 1 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  \"proximityMessages\": [{\n    \"threshold\": 1,\n    \"localizedMessages\": [{\n      \"locales\": [\"<string>\"],\n      \"message\": \"<string>\"\n    }]\n  }],\n  \"shipmentMethodIds\": [\"1000001\"],\n  \"eligiblePriceList\": [10000056],\n  \"note\": \"Independence day sale!\",\n  \"limits\": [{\n    \"kind\": \"ORDER\",\n    \"value\": 2\n  }],\n  \"additionalAttributes\": [{\n    \"key\": \"type\",\n    \"value\": \"Birthday\",\n    \"attributeId\": 100000\n  }]\n}")
  .asString();

Ruby

require 'uri'
require 'net/http'

url = URI("https://live.copilot.fabric.inc/api-offers/coupon/create")

http = Net::HTTP.new(url.host, url.port)
http.use_ssl = true

request = Net::HTTP::Post.new(url)
request["x-site-context"] = '<x-site-context>'
request["Authorization"] = 'Bearer <token>'
request["Content-Type"] = 'application/json'
request.body = "{\n  \"title\": \"CREATE COUPON\",\n  \"promo\": [\n    {\n      \"discount\": [\n        {\n          \"unit\": \"%OFF\",\n          \"value\": 10,\n          \"ON\": {\n            \"kind\": \"SKU\",\n            \"value\": \"*\",\n            \"quantity\": 2,\n            \"includeOperator\": \"OR\",\n            \"excludeOperator\": \"AND\"\n          },\n          \"discountId\": 1,\n          \"autoAdd\": false,\n          \"set\": []\n        }\n      ],\n      \"targetProducts\": [\n        {\n          \"kind\": \"SKU\",\n          \"value\": \"*\",\n          \"operator\": \"IN\",\n          \"discountId\": 1\n        }\n      ],\n      \"condition\": [\n        {\n          \"conditions\": [\n            {\n              \"key\": \"SKU\",\n              \"value\": \"*\",\n              \"operator\": \"IN\"\n            }\n          ],\n          \"includeOperator\": \"OR\",\n          \"excludeOperator\": \"AND\",\n          \"set\": \"A\"\n        }\n      ]\n    }\n  ],\n  \"startDate\": \"2019-08-24T14:15:22Z\",\n  \"endDate\": \"2019-08-25T14:15:22Z\",\n  \"isExclusive\": true,\n  \"type\": \"PRODUCT\",\n  \"promoCodes\": [[\"SUMMER100\", \"SUMMER20\"]],\n  \"buyOperator\": \"OR\",\n  \"stackingType\": \"STACKABLE\",\n  \"level\": 1,\n  \"termsAndConditions\": [{\n    \"title\": \"Terms Applied\",\n    \"description\": \"Items cannot be exchanged\"\n  }],\n  \"promotionMessages\": [{\n    \"title\": \"Buy 1 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  \"proximityMessages\": [{\n    \"threshold\": 1,\n    \"localizedMessages\": [{\n      \"locales\": [\"<string>\"],\n      \"message\": \"<string>\"\n    }]\n  }],\n  \"shipmentMethodIds\": [\"1000001\"],\n  \"eligiblePriceList\": [10000056],\n  \"note\": \"Independence day sale!\",\n  \"limits\": [{\n    \"kind\": \"ORDER\",\n    \"value\": 2\n  }],\n  \"additionalAttributes\": [{\n    \"key\": \"type\",\n    \"value\": \"Birthday\",\n    \"attributeId\": 100000\n  }]\n}"

response = http.request(request)
puts response.read_body

Responses

Our response, on success

200 OK - returns details about the created coupon

{
  "_id": "abcdefg1ee7ce20123456789",
  "promoId": 100013,
  "promoCodes": [
    "SUMMER100",
    "SUMMER20"
  ],
  "state": "SCHEDULED",
  "isImplicit": false,
  "title": "CREATE PROMO",
  "buyOperator": "OR",
  "promo": [
    {
      "discount": [
        {
          "unit": "%OFF",
          "value": 10,
          "ON": {
            "kind": "SKU",
            "value": "*",
            "quantity": 2,
            "includeOperator": "OR",
            "excludeOperator": "AND"
          },
          "discountId": 1,
          "autoAdd": false,
          "set": []
        }
      ],
      "targetProducts": [
        {
          "kind": "SKU",
          "value": "*",
          "operator": "IN",
          "discountId": 1
        }
      ],
      "condition": [
        "620d84a715f2d00001234567"
      ]
    }
  ],
  "startDate": "2019-08-24T14:15:22Z",
  "endDate": "2019-08-25T14:15:22Z",
  "isExclusive": true,
  "type": "PRODUCT",
  "stackingType": "STACKABLE",
  "level": 1,
  "termsAndConditions": [
    {
      "title": "Terms Applied",
      "description": "Items cannot be exchanged"
    }
  ],
  "promotionMessages": [
    {
      "title": "Buy 1 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": [
            "<string>"
          ],
          "message": "<string>"
        }
      ]
    }
  ],
  "shipmentMethodIds": [
    1000001
  ],
  "eligiblePriceList": [
    10000056
  ],
  "limits": [
    {
      "kind": "ORDER",
      "value": 2
    }
  ],
  "note": "Independence day sale!",
  "createdAt": "2019-08-20T14:15:22Z",
  "updatedAt": "2019-08-20T14:15:22Z"
}

Error responses

400 DATE_ERROR - if the start date is not earlier than the end date or not a future date.

{
  "code": "DATE_ERROR",
  "message": "The start date should be earlier than the end date and it should be a future date."
}

500 INTERNAL_SERVER_ERROR - when there is an unexpected error on the server side.

{
  "code": "INTERNAL_SERVER_ERROR",
  "message": "Internal server error."
}