Documentation
Feedback
Guides
API Reference

Guides
Promotions
Creating and managing coupons with Promotions API

A coupon is a code that when entered in the cart grants the customer a discount on the price of purchase for a determined product.

To make a coupon available for use you need to associate the coupon to a Promotion.

A single coupon can be associated with one or more promotions by filling the utmSource or utmCampain fields with the same values for both coupon and promotion configuration.

Coupons cannot be deleted, only archived. It is important to emphasize that you can only archive one coupon at a time. You can edit and reuse a coupon, but the coupon code can not be modified.

Restrictions

There’s a quantity limit to the active coupons. We recommend reusing coupons because a high number of coupons can compromise the Promotions & Taxes performance.

How to create a coupon

You can create one coupon or multiple coupons at a time.

If you try to create a coupon with an existing coupon code, the API will update the existing coupon.

How to edit a coupon

Coupons can be edited and reused as you wish. However, the coupon code cannot be modified.

There is a limited quantity of active coupons. Coupon reuse is highly recommended since a high number of coupons may compromise the Promotions & Taxes performance.

How to archive a coupon

As said before, you can only archive one coupon at a time. You must use the POST Archive coupon by coupon code endpoint to do so.

Examples of usage

Creating 50 coupons

To create 50 different coupons with coupon codes randomly generated, you must use the Create multiple coupons endpoint with quantity set to 50.

If you want to define the coupon codes, you can use this route as well, setting the coupon codes params with the desired values and quantity as 1 for each coupon configuration, as the example below.


_24
[
_24
{
_24
"quantity": 1,
_24
"couponConfiguration": {
_24
"utmSource": "cupom1",
_24
"utmCampaign": null,
_24
"couponCode": "test1",
_24
"isArchived": false,
_24
"maxItemsPerClient": 10,
_24
"expirationIntervalPerUse": "00:00:00"
_24
}
_24
},
_24
{
_24
"quantity": 1,
_24
"couponConfiguration": {
_24
"utmSource": "cupom2",
_24
"utmCampaign": null,
_24
"couponCode": "test2",
_24
"isArchived": false,
_24
"maxItemsPerClient": 5,
_24
"expirationIntervalPerUse": "00:10:00"
_24
}
_24
}
_24
]

You can associate these 50 coupons to a single promotion by repeating the same utmSource or utmCampaign in all of them, and then linking that UTM tag to the promotion. This can be done for any number of coupons.

To create or update a promotion, check the post Create Or Update Promotion endpoint.

Creating single-use coupon and promotion

Sandy is a frequent client of your store and it is her birthday. You can use the Create coupon endpoint with the coupon code set to Birthday123, associate it to a promotion then, send it to her.

To enable the single-use of a coupon, you must restrict the promotion to a single-use as well so she use the Birthday123 code on her checkout for only one purchase. To do so, follow the steps bellow:

  1. In the Admin, select the Promotions & Taxes module.
  2. Click on Promotions.
  3. Click on the New Promotion > Regular button.
  4. Check the selection box of utm_source and add the Birthday123 code to the field.
    {"base64":"  ","img":{"width":637,"height":381,"type":"png","mime":"image/png","wUnits":"px","hUnits":"px","length":18456,"url":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/creating-and-managing-coupons-with-promotions-api-0.png"}}
  5. Uncheck the unlimited selection boxes from the How many times will your promotion be applied in your store and How many times will your promotion be applied in your store per client fields.
  6. Add the number one to each field to enable the single-use promotion.
    {"base64":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAQAAAACCAIAAADwyuo0AAAACXBIWXMAABYlAAAWJQFJUiTwAAAAJUlEQVR4nAEaAOX/ACUlJQwMDFFRUbS0tACfn5+cnZ3Fx8fp6elycQxkwAGATAAAAABJRU5ErkJggg==","img":{"src":"https://cdn.jsdelivr.net/gh/vtexdocs/dev-portal-content@main/images/creating-and-managing-coupons-with-promotions-api-1.png","width":638,"height":254,"type":"png"}}
  7. Click on Save.

Coupon massive generation

To create a large number of coupons with the same settings, you can use the Coupon Massive Generation endpoint. This endpoint will generate the determined quantity of coupons differing only their names through automatic generation.

First, set the query param quantity to 10, for example. Then, make the following request body:


_10
{
_10
"utmSource": "cupom",
_10
"utmCampaign": null,
_10
"couponCode": "ctest",
_10
"isArchived": false,
_10
"maxItemsPerClient": 1,
_10
"expirationIntervalPerUse": "00:00:00"
_10
}

The result for the request will be the creation of ten coupons with the same settings and the following response body:


_12
[
_12
"ctest-wzcp5lwt7yz1s7n",
_12
"ctest-rb6smoassp2xe71",
_12
"ctest-vpw84ag9tfi8khv",
_12
"ctest-ne26wgmidp5ctht",
_12
"ctest-127ng0ox09tho5l",
_12
"ctest-qsowch8c8s7jipo",
_12
"ctest-6acbsst6zpss75l",
_12
"ctest-0bksc2tzh5ai946",
_12
"ctest-4jjx8u2rrqj4ck9",
_12
"ctest-hxiox1isdp6padl"
_12
]

Contributors
2
Photo of the contributor
Photo of the contributor
+ 2 contributors
Was this helpful?
Yes
No
Suggest edits (Github)
Contributors
2
Photo of the contributor
Photo of the contributor
+ 2 contributors
On this page