Coupons
This article contains all actions for retrieving and managing coupons.
Get coupon by ID#
query {
getCoupon(id: "1") {
id
siteid
label
provider
config
datestart
dateend
status
mtime
ctime
editor
}
}
const body = JSON.stringify({'query':
`query {
getCoupon(id: "1") {
id
siteid
label
provider
config
datestart
dateend
status
mtime
ctime
editor
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"getCoupon": {
"id": "1",
"siteid": "1.",
"label": "demo-voucher",
"provider": "Voucher",
"config": "{\\"voucher.productcode\\":\\"demo-rebate\\"}",
"datestart": null,
"dateend": null,
"status": 1,
"mtime": "2022-12-01 11:59:03",
"ctime": "2022-12-01 11:59:03",
"editor": "core"
}
}
}
Search coupons#
The filter parameter is explained in the filter section of the GraphQL basics article.
query {
searchCoupons(filter: "{\\"~=\\": {\\"coupon.label\\":\\"demo\\"}}") {
items {
id
siteid
label
provider
config
datestart
dateend
status
mtime
ctime
editor
}
total
}
}
let filter = {
"~=": {"coupon.label":"demo"}
};
const fstr = JSON.stringify(JSON.stringify(filter));
const body = JSON.stringify({'query':
`query {
searchCoupons(filter: ` + fstr + `) {
items {
id
siteid
label
provider
config
datestart
dateend
status
mtime
ctime
editor
}
total
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"searchCoupons": {
"items": [
{
"id": "1",
"siteid": "1.",
"label": "demo-voucher",
"provider": "Voucher",
"config": "{\\"voucher.productcode\\":\\"demo-rebate\\"}",
"datestart": null,
"dateend": null,
"status": 1,
"mtime": "2022-12-01 11:59:03",
"ctime": "2022-12-01 11:59:03",
"editor": "core"
},
{
"id": "2",
"siteid": "1.",
"label": "demo-percent",
"provider": "PercentRebate",
"config": "{\\"percentrebate.productcode\\":\\"demo-rebate\\",\\"percentrebate.rebate\\":\\"10\\"}",
"datestart": null,
"dateend": null,
"status": 1,
"mtime": "2022-12-01 11:59:03",
"ctime": "2022-12-01 11:59:03",
"editor": "core"
}
],
"total": 2
}
}
}
Fetch coupon configuration#
To retrieve the backend configuration for a coupon provider and the added decorators use:
query {
getCouponConfig(provider: "Voucher,Basket") {
code
type
label
}
}
const body = JSON.stringify({'query':
`query {
getCouponConfig(provider: "Voucher,Basket") {
code
type
label
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"getCouponConfig": [
{
"code":"voucher.productcode",
"type":"string",
"label":"Product code of the rebate product"
},{
"code":"basket.total-value-min",
"type":"map",
"label":"Minimum total value of the basket"
},{
"code":"basket.total-value-max",
"type":"map",
"label":"Maximum total value of the basket"
}
]
}
}
Save single coupon#
mutation {
saveCoupon(input: {
label: "Test coupon"
provider: "PercentRebate"
config: "{\\"percentrebate.productcode\\":\\"demo-rebate\\",\\"percentrebate.rebate\\":\\"25\\"}"
}) {
id
}
}
Aimeos.query(`mutation {
saveCoupon(input: {
label: "Test coupon"
provider: "PercentRebate"
config: "{\\"percentrebate.productcode\\":\\"demo-rebate\\",\\"percentrebate.rebate\\":\\"25\\"}"
}) {
id
}
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
saveCoupon(input: {
label: "Test coupon"
provider: "PercentRebate"
config: "{\\"percentrebate.productcode\\":\\"demo-rebate\\",\\"percentrebate.rebate\\":\\"25\\"}"
}) {
id
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"saveCoupon": {
"id": "4"
}
}
}
Save multiple coupons#
mutation {
saveCoupons(input: [{
label: "Test coupon 2"
provider: "PercentRebate"
config: "{\\"percentrebate.productcode\\":\\"demo-rebate\\",\\"percentrebate.rebate\\":\\"7.5\\"}"
}
{
label: "Test coupon 3"
provider: "FixedRebate,BasketValues"
config: "{\\"fixedrebate.productcode\\":\\"demo-rebate\\",\\"fixedrebate.rebate\\":{\\"EUR\\":"10.00"},\\"basket.total-value-min\\":{\\"EUR\\":100}}"
}]) {
id
}
}
Aimeos.query(`mutation {
saveCoupons(input: [{
label: "Test coupon 2"
provider: "PercentRebate"
config: "{\\"percentrebate.productcode\\":\\"demo-rebate\\",\\"percentrebate.rebate\\":\\"7.5\\"}"
}
{
label: "Test coupon 3"
provider: "FixedRebate,BasketValues"
config: "{\\"fixedrebate.productcode\\":\\"demo-rebate\\",\\"fixedrebate.rebate\\":{\\"EUR\\":"10.00"},\\"basket.total-value-min\\":{\\"EUR\\":100}}"
}]) {
id
}
}`).then(data => {
console.log(data)
})
const body = JSON.stringify({'query':
`mutation {
saveCoupons(input: [{
label: "Test coupon 2"
provider: "PercentRebate"
config: "{\\"percentrebate.productcode\\":\\"demo-rebate\\",\\"percentrebate.rebate\\":\\"7.5\\"}"
}
{
label: "Test coupon 3"
provider: "FixedRebate,BasketValues"
config: "{\\"fixedrebate.productcode\\":\\"demo-rebate\\",\\"fixedrebate.rebate\\":{\\"EUR\\":"10.00"},\\"basket.total-value-min\\":{\\"EUR\\":100}}"
}]) {
id
}
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"saveCoupons": [
{
"id": "5"
},
{
"id": "6"
}
]
}
}
Delete single coupon#
mutation {
deleteCoupon(id: "4")
}
const body = JSON.stringify({'query':
`mutation {
deleteCoupon(id: "4")
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"deleteCoupon": "4"
}
}
Delete multiple coupons#
mutation {
deleteCoupons(id: ["5", "6"])
}
const body = JSON.stringify({'query':
`mutation {
deleteCoupons(id: ["5", "6"])
}`});
fetch('<GraphQL URL>', {
method: 'POST',
credentials: 'same-origin',
headers: { // Laravel only
'X-CSRF-TOKEN': '<CSRF token>'
},
body: body
}).then(response => {
return response.json();
}).then(data => {
console.log(data);
});
Response:
{
"data": {
"deleteCoupons": [
"5",
"6"
]
}
}