Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

GraphQL: discountCodeBxgyCreate mutation, invalid value for error

Solved

GraphQL: discountCodeBxgyCreate mutation, invalid value for error

obihan
Shopify Partner
12 0 1

I am trying to use discountCodeBxgyCreate mutation and I am using the following structure;

 

              customerGets {
                value {
                  ... on DiscountOnQuantity {
                    effect {
                      ... on DiscountPercentage {
                        percentage
                      }
                      ... on DiscountAmount {
                        amount {
                          amount
                          currencyCode
                        }
                        appliesOnEachItem
                      }
                    }
                    quantity {
                      quantity
                    }
                  }
                }

 

and the following variables;

 

{
     discountOnQuantity: 
          {
          quantity: "1010", 
          effect: {
               amount: "50.00"
          }
     }
}

 

which is the same one Shopify itself uses when you try to create the same discount on standard Shopify discounts. However, I get the following error:

Error: Variable $bxgyCodeDiscount of type DiscountCodeBxgyInput! was provided invalid value for customerGets.value.discountOnQuantity.effect.amount (Field is not defined on DiscountEffectInput)


However, the documentation claims that DiscountEffect's possible types are DiscountAmount and DiscountPercentage.

 



Accepted Solution (1)

Liam
Community Manager
3108 344 910

This is an accepted solution.

It sounds like there's a mismatch between your GraphQL mutation structure and the expected input for the `discountCodeBxgyCreate` mutation in the Shopify Admin API.

Here's would you can try:

  • Define the Discount Effect: The effect field should be properly structured to reflect either a percentage or an amount. In your case, you want to use DiscountAmount.
  • Correctly Structure the Variables: Ensure that the variables you pass match the expected structure of the DiscountCodeBxgyInput type.
  • Use the Correct Types: GraphQL is strictly typed. Make sure that numerical values are not passed as strings unless the field is explicitly a string type.

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Reply 1 (1)

Liam
Community Manager
3108 344 910

This is an accepted solution.

It sounds like there's a mismatch between your GraphQL mutation structure and the expected input for the `discountCodeBxgyCreate` mutation in the Shopify Admin API.

Here's would you can try:

  • Define the Discount Effect: The effect field should be properly structured to reflect either a percentage or an amount. In your case, you want to use DiscountAmount.
  • Correctly Structure the Variables: Ensure that the variables you pass match the expected structure of the DiscountCodeBxgyInput type.
  • Use the Correct Types: GraphQL is strictly typed. Make sure that numerical values are not passed as strings unless the field is explicitly a string type.

Hope this helps,

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog