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
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 {
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/2024-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
JSON{
"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
JSON{
"discountAutomaticBasicCreate": {
"automaticDiscountNode": {
"id": "gid://shopify/DiscountAutomaticNode/1057371276",
"automaticDiscount": {
"title": "$10 off orders over $100 (combinable with shipping discounts)",
"startsAt": "2025-01-07T06:28:55Z",
"combinesWith": {
"productDiscounts": false,
"shippingDiscounts": true,
"orderDiscounts": false
},
"minimumRequirement": {
"greaterThanOrEqualToSubtotal": {
"amount": "100.0",
"currencyCode": "USD"
}
},
"customerGets": {
"value": {
"amount": {