API reference
Create a coupon
How to create a coupon via API
To create a new coupon, send a POST request to the /api/coupons endpoint, passing the resource arguments in the request body.

Request

POST https://yourdomain.commercelayer.io/api/coupons

Arguments

Body Parameter
Type
Required
type
string
Required
attributes.code
string
Required
attributes.customer_single_use
boolean
Optional, default is 'false'
attributes.usage_limit
integer
Required
attributes.recipient_email
string
Optional
attributes.reference
string
Optional
attributes.reference_origin
string
Optional
attributes.metadata
object
Optional
relationships.promotion_rule
object
Required

Example

Request
Response
The following request creates a new coupon:
1
curl -g -X POST \
2
'https://yourdomain.commercelayer.io/api/coupons' \
3
-H 'Accept: application/vnd.api+json' \
4
-H 'Authorization: Bearer your-access-token' \
5
-H 'Content-Type: application/vnd.api+json' \
6
-d '{
7
"data": {
8
"type": "coupons",
9
"attributes": {
10
"code": "04371af2-70b3-48d7-8f4e-316b374224c3",
11
"usage_limit": 50
12
},
13
"relationships": {
14
"promotion_rule": {
15
"data": {
16
"type": "coupon_codes_promotion_rules",
17
"id": "QWERtyUpBa"
18
}
19
}
20
}
21
}
22
}'
Copied!
On success, the API responds with a 201 Created status code, returning the created resource object:
1
{
2
"data": {
3
"id": "xYZkjABcde",
4
"type": "coupons",
5
"links": {
6
"self": "https://yourdomain.commercelayer.io/api/coupons/xYZkjABcde"
7
},
8
"attributes": {
9
"code": "04371af2-70b3-48d7-8f4e-316b374224c3",
10
"customer_single_use": false,
11
"usage_limit": 50,
12
"usage_count": 20,
13
"recipient_email": "[email protected]",
14
"created_at": "2018-01-01T12:00:00.000Z",
15
"updated_at": "2018-01-01T12:00:00.000Z",
16
"reference": "ANY-EXTERNAL-REFEFERNCE",
17
"reference_origin": "ANY-EXTERNAL-REFEFERNCE-ORIGIN",
18
"metadata": {
19
"foo": "bar"
20
}
21
},
22
"relationships": {
23
"promotion_rule": {
24
"links": {
25
"self": "https://yourdomain.commercelayer.io/api/coupons/xYZkjABcde/relationships/promotion_rule",
26
"related": "https://yourdomain.commercelayer.io/api/coupons/xYZkjABcde/promotion_rule"
27
}
28
}
29
},
30
"meta": {
31
"mode": "test"
32
}
33
}
34
}
Copied!
Copy link