discount Automatic Basic Createmutation
mutation
2025-01release candidate
Requires Apps must have
write_discounts
access scope.
Creates a basic automatic discount.
Arguments
The input data used to create the automatic discount.
Was this section helpful?
DiscountAutomaticBasicCreatePayload returns
The created automatic discount.
The list of errors that occurred from executing the mutation.
Was this section helpful?
Examples
Hide code
DescriptionCopy
mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) { discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBasic { startsAt endsAt minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount currencyCode } } } customerGets { value { ... on DiscountAmount { amount { amount currencyCode } appliesOnEachItem } } items { ... on AllDiscountItems { allItems } } } } } } userErrors { field code message } } }
curl -X POST \ https://your-development-store.myshopify.com/admin/api/2025-01/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 { startsAt endsAt minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount currencyCode } } } customerGets { value { ... on DiscountAmount { amount { amount currencyCode } appliesOnEachItem } } items { ... on AllDiscountItems { allItems } } } } } } userErrors { field code message } } }", "variables": { "automaticBasicDiscount": { "title": "$50 off all orders over $200 during the summer of 2022", "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": 200 } }, "customerGets": { "value": { "discountAmount": { "amount": 50, "appliesOnEachItem": false } }, "items": { "all": true } } } } }'
const { admin } = await authenticate.admin(request); const response = await admin.graphql( `#graphql mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) { discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBasic { startsAt endsAt minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount currencyCode } } } customerGets { value { ... on DiscountAmount { amount { amount currencyCode } appliesOnEachItem } } items { ... on AllDiscountItems { allItems } } } } } } userErrors { field code message } } }`, { variables: { "automaticBasicDiscount": { "title": "$50 off all orders over $200 during the summer of 2022", "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": 200 } }, "customerGets": { "value": { "discountAmount": { "amount": 50, "appliesOnEachItem": false } }, "items": { "all": true } } } }, }, ); const data = await response.json();
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 { startsAt endsAt minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount currencyCode } } } customerGets { value { ... on DiscountAmount { amount { amount currencyCode } appliesOnEachItem } } items { ... on AllDiscountItems { allItems } } } } } } userErrors { field code message } } } QUERY variables = { "automaticBasicDiscount": { "title": "$50 off all orders over $200 during the summer of 2022", "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": 200 } }, "customerGets": { "value": { "discountAmount": { "amount": 50, "appliesOnEachItem": false } }, "items": { "all": true } } } } response = client.query(query: query, variables: variables)
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 { startsAt endsAt minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount currencyCode } } } customerGets { value { ... on DiscountAmount { amount { amount currencyCode } appliesOnEachItem } } items { ... on AllDiscountItems { allItems } } } } } } userErrors { field code message } } }`, "variables": { "automaticBasicDiscount": { "title": "$50 off all orders over $200 during the summer of 2022", "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": 200 } }, "customerGets": { "value": { "discountAmount": { "amount": 50, "appliesOnEachItem": false } }, "items": { "all": true } } } }, }, });
use Shopify\Clients\Graphql; $client = new Graphql("your-development-store.myshopify.com", $accessToken); $query = <<<QUERY mutation discountAutomaticBasicCreate($automaticBasicDiscount: DiscountAutomaticBasicInput!) { discountAutomaticBasicCreate(automaticBasicDiscount: $automaticBasicDiscount) { automaticDiscountNode { id automaticDiscount { ... on DiscountAutomaticBasic { startsAt endsAt minimumRequirement { ... on DiscountMinimumSubtotal { greaterThanOrEqualToSubtotal { amount currencyCode } } } customerGets { value { ... on DiscountAmount { amount { amount currencyCode } appliesOnEachItem } } items { ... on AllDiscountItems { allItems } } } } } } userErrors { field code message } } } QUERY; $variables = [ "automaticBasicDiscount" => [ "title" => "$50 off all orders over $200 during the summer of 2022", "startsAt" => "2022-06-21T00:00:00Z", "endsAt" => "2022-09-21T00:00:00Z", "minimumRequirement" => [ "subtotal" => [ "greaterThanOrEqualToSubtotal" => 200, ], ], "customerGets" => [ "value" => [ "discountAmount" => [ "amount" => 50, "appliesOnEachItem" => false, ], ], "items" => [ "all" => true, ], ], ], ]; $response = $client->query(["query" => $query, "variables" => $variables]);
Hide code
Input variables
Copy
{ "automaticBasicDiscount": { "title": "$50 off all orders over $200 during the summer of 2022", "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "minimumRequirement": { "subtotal": { "greaterThanOrEqualToSubtotal": 200 } }, "customerGets": { "value": { "discountAmount": { "amount": 50, "appliesOnEachItem": false } }, "items": { "all": true } } } }
Hide code
Response
JSON
{ "discountAutomaticBasicCreate": { "automaticDiscountNode": { "id": "gid://shopify/DiscountAutomaticNode/1057371197", "automaticDiscount": { "startsAt": "2022-06-21T00:00:00Z", "endsAt": "2022-09-21T00:00:00Z", "minimumRequirement": { "greaterThanOrEqualToSubtotal": { "amount": "200.0", "currencyCode": "USD" } }, "customerGets": { "value": { "amount": { "amount": "50.0", "currencyCode": "USD" }, "appliesOnEachItem": false }, "items": { "allItems": true } } } }, "userErrors": [] } }