How to create automatic discount for amount off products in shopify using Graphql

How to create automatic discount for amount off products in shopify using Graphql

user_spritle
Shopify Partner
1 0 0

There is a option to create a automatic discount using API on shopify for amount off order. I want to create a automatic discount for amount off product using graphql

I tried to alter this JSON to apply the discount for products, but it didn't work. is there any possibility to achieve this? https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/discountAutomaticBasicCreate

 


{
  "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": "$100 off all orders over $500 for all customers",
      "startsAt": "2024-01-01T00:00:00Z",
      "endsAt": "2024-12-31T23:59:59Z",
      "minimumRequirement": {
        "subtotal": {
          "greaterThanOrEqualToSubtotal": 500
        }
      },
      "customerGets": {
        "value": {
          "discountAmount": {
            "amount": 100,
            "appliesOnEachItem": false
          }
        },
        "items": {
          "all": true
        }
      }
    }
  }
}
Reply 1 (1)

asisnaira
Visitor
2 0 0

@user_spritle wrote:

There is a option to create a automatic discount using API on shopify for amount off order. I want to create a automatic discount for amount off product using graphql

I tried to alter this JSON to apply the discount for products, but it didn't work. is there any possibility to achieve this? https://shopify.dev/docs/api/admin-graphql/2024-07/mutations/discountAutomaticBasicCreate

 


{
  "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": "$100 off all orders over $500 for all customers",
      "startsAt": "2024-01-01T00:00:00Z",
      "endsAt": "2024-12-31T23:59:59Z",
      "minimumRequirement": {
        "subtotal": {
          "greaterThanOrEqualToSubtotal": 500
        }
      },
      "customerGets": {
        "value": {
          "discountAmount": {
            "amount": 100,
            "appliesOnEachItem": false
          }
        },
        "items": {
          "all": true
        }
      }
    }
  }
}

To create an automatic discount for a specific amount off products in Shopify using GraphQL, you can follow these steps:

  1. Set Up Your Shopify Store: Ensure you have access to the Shopify Admin API and have the necessary permissions to create discounts.

  2. Use the GraphQL Admin API: You'll want to interact with the API to create a discount. Specifically, you'll use the discountCodeCreate mutation.

  3. Construct Your Mutation: Here’s a basic example of how to structure your mutation for an amount-off discount.