Anchor to discountAutomaticBasicCreatediscount
discountAutomaticBasicCreate
mutation
Requires Apps must have access scope.
Anchor to Arguments
Arguments
- Anchor to automaticBasicDiscountautomatic•
Basic Discount DiscountAutomatic requiredBasic Input! The input data used to create the automatic amount off discount.
Was this section helpful?
Anchor to DiscountAutomaticBasicCreatePayload returnsDiscountAutomaticBasicCreatePayload returns
- Anchor to automaticDiscountNodeautomatic•
Discount Node The automatic 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 combinable automatic discount
- Create a fixed amount off discount
- Create a percentage off discount with a minimum purchase
- discountAutomaticBasicCreate reference
Examples
1const { admin } = await authenticate.admin(request);23const response = await admin.graphql(4 `#graphql5 mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {6 discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {7 automaticDiscountNode {8 id9 automaticDiscount {10 ... on DiscountAutomaticBasic {11 title12 startsAt13 combinesWith {14 productDiscounts15 shippingDiscounts16 orderDiscounts17 }18 minimumRequirement {19 ... on DiscountMinimumSubtotal {20 greaterThanOrEqualToSubtotal {21 amount22 currencyCode23 }24 }25 }26 customerGets {27 value {28 ... on DiscountAmount {29 amount {30 amount31 currencyCode32 }33 }34 }35 items {36 ... on AllDiscountItems {37 allItems38 }39 }40 }41 }42 }43 }44 userErrors {45 field46 code47 message48 }49 }50 }`,51 {52 variables: {53 "automaticBasicDiscount": {54 "title": "$10 off orders over $100 (combinable with shipping discounts)",55 "startsAt": "2025-01-07T01:28:55-05:00",56 "minimumRequirement": {57 "subtotal": {58 "greaterThanOrEqualToSubtotal": "100.00"59 }60 },61 "customerGets": {62 "value": {63 "discountAmount": {64 "amount": "10.00",65 "appliesOnEachItem": false66 }67 },68 "items": {69 "all": true70 }71 },72 "combinesWith": {73 "productDiscounts": false,74 "shippingDiscounts": true,75 "orderDiscounts": false76 }77 }78 },79 },80);8182const data = await response.json();83
mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {
discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBasic {
title
startsAt
combinesWith {
productDiscounts
shippingDiscounts
orderDiscounts
}
minimumRequirement {
... on DiscountMinimumSubtotal {
greaterThanOrEqualToSubtotal {
amount
currencyCode
}
}
}
customerGets {
value {
... on DiscountAmount {
amount {
amount
currencyCode
}
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
}
}
}
userErrors {
field
code
message
}
}
}
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 discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) { discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBasic { title startsAt combinesWith { productDiscounts shippingDiscounts orderDiscounts } minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount currencyCode } } } customerGets { value { ... on DiscountAmount { amount { amount currencyCode } } } items { ... on AllDiscountItems { allItems } } } } } } userErrors { field code message } } }",
"variables": {
"automaticBasicDiscount": {
"title": "$10 off orders over $100 (combinable with shipping discounts)",
"startsAt": "2025-01-07T01:28:55-05:00",
"minimumRequirement": {
"subtotal": {
"greaterThanOrEqualToSubtotal": "100.00"
}
},
"customerGets": {
"value": {
"discountAmount": {
"amount": "10.00",
"appliesOnEachItem": false
}
},
"items": {
"all": true
}
},
"combinesWith": {
"productDiscounts": false,
"shippingDiscounts": true,
"orderDiscounts": false
}
}
}
}'
const { admin } = await authenticate.admin(request);
const response = await admin.graphql(
`#graphql
mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {
discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBasic {
title
startsAt
combinesWith {
productDiscounts
shippingDiscounts
orderDiscounts
}
minimumRequirement {
... on DiscountMinimumSubtotal {
greaterThanOrEqualToSubtotal {
amount
currencyCode
}
}
}
customerGets {
value {
... on DiscountAmount {
amount {
amount
currencyCode
}
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
}
}
}
userErrors {
field
code
message
}
}
}`,
{
variables: {
"automaticBasicDiscount": {
"title": "$10 off orders over $100 (combinable with shipping discounts)",
"startsAt": "2025-01-07T01:28:55-05:00",
"minimumRequirement": {
"subtotal": {
"greaterThanOrEqualToSubtotal": "100.00"
}
},
"customerGets": {
"value": {
"discountAmount": {
"amount": "10.00",
"appliesOnEachItem": false
}
},
"items": {
"all": true
}
},
"combinesWith": {
"productDiscounts": false,
"shippingDiscounts": true,
"orderDiscounts": false
}
}
},
},
);
const data = await response.json();
const client = new shopify.clients.Graphql({session});
const data = await client.query({
data: {
"query": `mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {
discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBasic {
title
startsAt
combinesWith {
productDiscounts
shippingDiscounts
orderDiscounts
}
minimumRequirement {
... on DiscountMinimumSubtotal {
greaterThanOrEqualToSubtotal {
amount
currencyCode
}
}
}
customerGets {
value {
... on DiscountAmount {
amount {
amount
currencyCode
}
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
}
}
}
userErrors {
field
code
message
}
}
}`,
"variables": {
"automaticBasicDiscount": {
"title": "$10 off orders over $100 (combinable with shipping discounts)",
"startsAt": "2025-01-07T01:28:55-05:00",
"minimumRequirement": {
"subtotal": {
"greaterThanOrEqualToSubtotal": "100.00"
}
},
"customerGets": {
"value": {
"discountAmount": {
"amount": "10.00",
"appliesOnEachItem": false
}
},
"items": {
"all": true
}
},
"combinesWith": {
"productDiscounts": false,
"shippingDiscounts": true,
"orderDiscounts": false
}
}
},
},
});
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 discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) {
discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) {
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBasic {
title
startsAt
combinesWith {
productDiscounts
shippingDiscounts
orderDiscounts
}
minimumRequirement {
... on DiscountMinimumSubtotal {
greaterThanOrEqualToSubtotal {
amount
currencyCode
}
}
}
customerGets {
value {
... on DiscountAmount {
amount {
amount
currencyCode
}
}
}
items {
... on AllDiscountItems {
allItems
}
}
}
}
}
}
userErrors {
field
code
message
}
}
}
QUERY
variables = {
"automaticBasicDiscount": {
"title": "$10 off orders over $100 (combinable with shipping discounts)",
"startsAt": "2025-01-07T01:28:55-05:00",
"minimumRequirement": {
"subtotal": {
"greaterThanOrEqualToSubtotal": "100.00"
}
},
"customerGets": {
"value": {
"discountAmount": {
"amount": "10.00",
"appliesOnEachItem": false
}
},
"items": {
"all": true
}
},
"combinesWith": {
"productDiscounts": false,
"shippingDiscounts": true,
"orderDiscounts": false
}
}
}
response = client.query(query: query, variables: variables)
Input variables
JSON1{2 "automaticBasicDiscount": {3 "title": "$10 off orders over $100 (combinable with shipping discounts)",4 "startsAt": "2025-01-07T01:28:55-05:00",5 "minimumRequirement": {6 "subtotal": {7 "greaterThanOrEqualToSubtotal": "100.00"8 }9 },10 "customerGets": {11 "value": {12 "discountAmount": {13 "amount": "10.00",14 "appliesOnEachItem": false15 }16 },17 "items": {18 "all": true19 }20 },21 "combinesWith": {22 "productDiscounts": false,23 "shippingDiscounts": true,24 "orderDiscounts": false25 }26 }27}
Response
JSON1{2 "discountAutomaticBasicCreate": {3 "automaticDiscountNode": {4 "id": "gid://shopify/DiscountAutomaticNode/1057371276",5 "automaticDiscount": {6 "title": "$10 off orders over $100 (combinable with shipping discounts)",7 "startsAt": "2025-01-07T06:28:55Z",8 "combinesWith": {9 "productDiscounts": false,10 "shippingDiscounts": true,11 "orderDiscounts": false12 },13 "minimumRequirement": {14 "greaterThanOrEqualToSubtotal": {15 "amount": "100.0",16 "currencyCode": "USD"17 }18 },19 "customerGets": {20 "value": {21 "amount": {22 "amount": "10.0",23 "currencyCode": "USD"24 }25 },26 "items": {27 "allItems": true28 }29 }30 }31 },32 "userErrors": []33 }34}