Anchor to discountCodeBxgyCreatediscount
discountCodeBxgyCreate
mutation
Requires Apps must have access scope.
Creates a buy X get Y discount (BXGY) that's applied on a cart and at checkout when a customer enters a code.
Anchor to Arguments
Arguments
- Anchor to bxgyCodeDiscountbxgy•
Code Discount DiscountCode requiredBxgy Input! The input data used to create the BXGY code discount.
Was this section helpful?
Anchor to DiscountCodeBxgyCreatePayload returnsDiscountCodeBxgyCreatePayload returns
- Anchor to codeDiscountNodecode•
Discount Node The code discount that was created.
- Anchor to userErrorsuser•
Errors [DiscountUser non-nullError!]! The list of errors that occurred from executing the mutation.
Was this section helpful?
- Create a basic Buy X get Y (BXGY) discount
- discountCodeBxgyCreate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation discountCodeBxgyCreate($bxgyCodeDiscount: DiscountCodeBxgyInput!) {6 discountCodeBxgyCreate(bxgyCodeDiscount: $bxgyCodeDiscount) {7 codeDiscountNode {8 codeDiscount {9 ... on DiscountCodeBxgy {10 title11 codes(first: 10) {12 nodes {13 code14 }15 }16 startsAt17 endsAt18 customerBuys {19 items {20 ...collectionsFragment21 }22 value {23 ... on DiscountQuantity {24 quantity25 }26 }27 }28 customerGets {29 appliesOnOneTimePurchase30 appliesOnSubscription31 value {32 ... on DiscountOnQuantity {33 effect {34 ... on DiscountPercentage {35 percentage36 }37 }38 quantity {39 quantity40 }41 }42 }43 items {44 ...collectionsFragment45 }46 }47 customerSelection {48 ... on DiscountCustomerAll {49 allCustomers50 }51 }52 appliesOncePerCustomer53 usesPerOrderLimit54 }55 }56 }57 userErrors {58 field59 code60 message61 }62 }63 }64 65 fragment collectionsFragment on DiscountCollections {66 collections(first: 10) {67 nodes {68 id69 title70 }71 }72 }`,73 {74 variables: {75 "bxgyCodeDiscount": {76 "code": "SUMMERSALE",77 "customerBuys": {78 "items": {79 "collections": {80 "add": [81 "gid://shopify/Collection/1007901140"82 ]83 }84 },85 "value": {86 "quantity": "3"87 }88 },89 "customerGets": {90 "items": {91 "collections": {92 "add": [93 "gid://shopify/Collection/711838235"94 ]95 }96 },97 "value": {98 "discountOnQuantity": {99 "effect": {100 "percentage": 0.2101 },102 "quantity": "2"103 }104 }105 },106 "customerSelection": {107 "all": true108 },109 "endsAt": "2022-09-21T00:00:00Z",110 "startsAt": "2022-06-21T00:00:00Z",111 "title": "20% off up to two snowboards that are on sale for every three featured snowboards you buy.",112 "usesPerOrderLimit": 3113 }114 },115 },116);117118const data = await response.json();119
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
}
}
}
curl -X POST \
https://your-development-store.myshopify.com/admin/api/2025-04/graphql.json \
-H 'Content-Type: application/json' \
-H 'X-Shopify-Access-Token: {access_token}' \
-d '{
"query": "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 { 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();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `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
}
},
},
});
session = ShopifyAPI::Auth::Session.new(
shop: "your-development-store.myshopify.com",
access_token: access_token
)
client = ShopifyAPI::Clients::Graphql::Admin.new(
session: session
)
query = <<~QUERY
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
}
}
}
QUERY
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
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "bxgyCodeDiscount": {3 "code": "SUMMERSALE",4 "customerBuys": {5 "items": {6 "collections": {7 "add": [8 "gid://shopify/Collection/1007901140"9 ]10 }11 },12 "value": {13 "quantity": "3"14 }15 },16 "customerGets": {17 "items": {18 "collections": {19 "add": [20 "gid://shopify/Collection/711838235"21 ]22 }23 },24 "value": {25 "discountOnQuantity": {26 "effect": {27 "percentage": 0.228 },29 "quantity": "2"30 }31 }32 },33 "customerSelection": {34 "all": true35 },36 "endsAt": "2022-09-21T00:00:00Z",37 "startsAt": "2022-06-21T00:00:00Z",38 "title": "20% off up to two snowboards that are on sale for every three featured snowboards you buy.",39 "usesPerOrderLimit": 340 }41}
Response
JSON1{2 "discountCodeBxgyCreate": {3 "codeDiscountNode": {4 "codeDiscount": {5 "title": "20% off up to two snowboards that are on sale for every three featured snowboards you buy.",6 "codes": {7 "nodes": [8 {9 "code": "SUMMERSALE"10 }11 ]12 },13 "startsAt": "2022-06-21T00:00:00Z",14 "endsAt": "2022-09-21T00:00:00Z",15 "customerBuys": {16 "items": {17 "collections": {18 "nodes": [19 {20 "id": "gid://shopify/Collection/1007901140",21 "title": "Featured items"22 }23 ]24 }25 },26 "value": {27 "quantity": "3"28 }29 },30 "customerGets": {31 "appliesOnOneTimePurchase": true,32 "appliesOnSubscription": false,33 "value": {34 "effect": {35 "percentage": 0.236 },37 "quantity": {38 "quantity": "2"39 }40 },41 "items": {42 "collections": {43 "nodes": [44 {45 "id": "gid://shopify/Collection/711838235",46 "title": "On Sale!"47 }48 ]49 }50 }51 },52 "customerSelection": {53 "allCustomers": true54 },55 "appliesOncePerCustomer": false,56 "usesPerOrderLimit": 357 }58 },59 "userErrors": []60 }61}