Creates a Promotion
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
promotion: {
name: 'Promotions Used in 2021',
code: 'BLK-FRI',
description: 'Save today with discount code XYZ at checkout.',
usage_limit: 100,
advertise: true,
starts_at: '<string>',
ends_at: '<string>',
store_ids: ['2']
}
})
};
fetch('http://{defaultHost}/api/v2/platform/promotions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"data": {
"id": "35",
"type": "promotion",
"attributes": {
"description": "First 1000 Customers Save 20%",
"expires_at": "2022-11-12T19:35:03.283Z",
"starts_at": "2022-11-08T19:35:03.283Z",
"name": "Black Friday 20% Off",
"type": "Spree::Promotion",
"usage_limit": 1000,
"match_policy": "any",
"code": "BLK-20",
"advertise": true,
"path": "/black-fri/today",
"created_at": "2022-11-08T19:35:03.521Z",
"updated_at": "2022-11-08T19:35:03.533Z",
"public_metadata": {},
"private_metadata": {}
},
"relationships": {
"promotion_category": {
"data": {
"id": "15",
"type": "promotion_category"
}
},
"promotion_rules": {
"data": []
},
"promotion_actions": {
"data": []
},
"stores": {
"data": [
{
"id": "382",
"type": "store"
},
{
"id": "383",
"type": "store"
},
{
"id": "381",
"type": "store"
}
]
}
}
}
}Bearer authentication header of the form Bearer <token>, where <token> is your auth token.
Select which associated resources you would like to fetch, see: https://jsonapi.org/format/#fetching-includes
Show child attributes
Record created
Show child attributes
Was this page helpful?
const options = {
method: 'POST',
headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'},
body: JSON.stringify({
promotion: {
name: 'Promotions Used in 2021',
code: 'BLK-FRI',
description: 'Save today with discount code XYZ at checkout.',
usage_limit: 100,
advertise: true,
starts_at: '<string>',
ends_at: '<string>',
store_ids: ['2']
}
})
};
fetch('http://{defaultHost}/api/v2/platform/promotions', options)
.then(res => res.json())
.then(res => console.log(res))
.catch(err => console.error(err));{
"data": {
"id": "35",
"type": "promotion",
"attributes": {
"description": "First 1000 Customers Save 20%",
"expires_at": "2022-11-12T19:35:03.283Z",
"starts_at": "2022-11-08T19:35:03.283Z",
"name": "Black Friday 20% Off",
"type": "Spree::Promotion",
"usage_limit": 1000,
"match_policy": "any",
"code": "BLK-20",
"advertise": true,
"path": "/black-fri/today",
"created_at": "2022-11-08T19:35:03.521Z",
"updated_at": "2022-11-08T19:35:03.533Z",
"public_metadata": {},
"private_metadata": {}
},
"relationships": {
"promotion_category": {
"data": {
"id": "15",
"type": "promotion_category"
}
},
"promotion_rules": {
"data": []
},
"promotion_actions": {
"data": []
},
"stores": {
"data": [
{
"id": "382",
"type": "store"
},
{
"id": "383",
"type": "store"
},
{
"id": "381",
"type": "store"
}
]
}
}
}
}