const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) {
discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) {
codeDiscountNode {
codeDiscount {
... on DiscountCodeBxgy {
title
codes(first: 10) {
nodes {
code
}
}
startsAt
endsAt
customerBuys {
items {
...collectionsFragment
}
value {
... on DiscountQuantity {
quantity
}
}
}
customerGets {
appliesOnOneTimePurchase
appliesOnSubscription
value {
... on DiscountOnQuantity {
effect {
... on DiscountPercentage {
percentage
}
}
quantity {
quantity
}
}
}
items {
...collectionsFragment
}
}
customerSelection {
... on DiscountCustomerAll {
allCustomers
}
}
appliesOncePerCustomer
usesPerOrderLimit
}
}
}
userErrors {
field
code
message
}
}
}
fragment collectionsFragment on DiscountCollections {
collections(first: 10) {
nodes {
id
title
}
}
}`,
{
variables: {
"bxgyCodeDiscount": {
"code": "SUMMERSALE",
"customerBuys": {
"items": {
"collections": {
"add": [
"gid://shopify/Collection/1007901140"
]
}
},
"value": {
"quantity": "3"
}
},
"customerGets": {
"items": {
"collections": {
"add": [
"gid://shopify/Collection/711838235"
]
}
},
"value": {
"discountOnQuantity": {
"effect": {
"percentage": 0.2
},
"quantity": "2"
}
}
},
"customerSelection": {
"all": true
},
"endsAt": "2022-09-21T00:00:00Z",
"startsAt": "2022-06-21T00:00:00Z",
"title": "20% off up to two snowboards that are on sale for every three featured snowboards you buy.",
"usesPerOrderLimit": 3
}
},
},
);
const data = await response.json();