GraphQL mutation to create a Shopify BXGY automatic discount with all products selected failes

I am creating a Shopify app and using a GraphQL mutation to create a BXGY automatic discount. The mutation works fine when I specify a specific product in the customerBuys.items field. However, when I remove the products field from the customerBuys field and set customerBuys.items.all to true (to apply it to all products) I get the following error:

{
  "discountAutomaticBxgyCreate": {
    "userErrors": [
      {
        "field": [
          "automaticBxgyDiscount",
          "customerBuys",
          "items"
        ],
        "message": "Items in 'customer buys' must be defined",
        "code": "BLANK"
      }
    ],
    "automaticDiscountNode": null
  }
}

I’m not sure why this error is happening, as I have followed the Shopify API documentation correctly. Could this be a problem with the Shopify API or is there something wrong with my mutation?

My Mutation:

mutation CreateDiscount($amount: Decimal!, $productId: ID!) {
        discountAutomaticBxgyCreate(automaticBxgyDiscount: {
            title: "BXGY discount test",
            startsAt: "2022-01-01",
            endsAt: "2024-04-18T02:38:45Z",
            usesPerOrderLimit: "1",
            customerBuys: {
                value: {
                    amount: $amount
                }
                items: {
                    all: true
                }
            },
            customerGets: {
        value: {
            discountOnQuantity: {
            quantity: "1"
            effect: {
              percentage: 1
            }
          }
        }
                items: {
                    products: {
                        productsToAdd: [$productId]
                    }
                }
            }}) {
            userErrors {
                field
                message
                code
            }
            automaticDiscountNode {
                id
                automaticDiscount {
                ... on DiscountAutomaticBxgy {
                    title
                    summary
                    status
                }
                }
            }
        }
    }

Any help or suggestions would be appreciated. Thank you!

1 Like

I’m trying to use this API with very simple parameters and every time it gives Request Error, even this most simple version:

mutation {
  discountAutomaticBxgyCreate(automaticBxgyDiscount: {
    combinesWith: {
      orderDiscounts: false,
      productDiscounts: true,
      shippingDiscounts: false
    },
    customerBuys: {
      items: {
        all: true
      },
      value: {
        quantity: 2
      }
    },
    customerGets: {
      items: {
        all: true
      },
      value: {
          percentage: 0.3
      }
    },
    title: "Buy 2 Get 1 Free"
  }) {
    automaticDiscountNode {
      id
    }
    userErrors {
      field,
      message
    }
  }
}

The answer always is:

{
  "errors": [
    {
      "message": "Internal error. Looks like something went wrong on our end.\nRequest ID: 52a4672d-e8bb-4685-bc5f-ad6b979e37ad (include this in support requests).",
      "extensions": {
        "code": "INTERNAL_SERVER_ERROR",
        "requestId": "52a4672d-e8bb-4685-bc5f-ad6b979e37ad"
      }
    }
  ]
}