Order Edit mutation to apply discount gives mutation error

Highlighted
Tourist
26 0 0

Hi All,

I have followed the guide https://shopify.dev/tutorials/edit-an-existing-order-with-admin-api & https://shopify.dev/docs/admin-api/graphql/reference/orders/ordereditaddlineitemdiscount

to edit and order by adding an discounted variant.

 body: JSON.stringify({
     query: `mutation orderEditAddLineItemDiscount($input: ID!, $lineItemId: ID!, $discount: OrderEditAppliedDiscountInput!) {
      orderEditAddLineItemDiscount(id: $input, lineItemId: $lineItemId, discount: $discount){
        addedDiscountStagedChange {
          id
        }
        calculatedLineItem {
          id
        }
        calculatedOrder {
          id
        }
         userErrors {
           field
           message
         }
       }
     }`,
     variables: { "input": "gid://shopify/CalculatedOrder/"+calculatedOrdrID,
                   "lineItemId":  "gid://shopify/ProductVariant/"+calculatedLineItem,
                   discount: {percentValue: 100description: "freee"}
      }
   })
 
Am getting error as {"errors":[{"message":"Field 'orderEditAddLineItemDiscount' doesn't exist on type 'Mutation'","locations":[{"line":2,"column":7}],"path":["mutation addDiscount","orderEditAddLineItemDiscount"],"extensions":{"code":"undefinedField","typeName":"Mutation","fieldName":"orderEditAddLineItemDiscount"}},{"message":"Variable $input is declared by addDiscount but not used","locations":[{"line":1,"column":1}],"path":["mutation addDiscount"],"extensions":{"code":"variableNotUsed","variableName":"input"}},{"message":"Variable $lineItemId is declared by addDiscount but not used","locations":[{"line":1,"column":1}],"path":["mutation addDiscount"],"extensions":{"code":"variableNotUsed","variableName":"lineItemId"}},{"message":"Variable $discount is declared by addDiscount but not used","locations":[{"line":1,"column":1}],"path":["mutation addDiscount"],"extensions":{"code":"variableNotUsed","variableName":"discount"}}]}
 
The fieldname is given as per document only. But it says it doesn't exist on type "Mutation".Can anyone help me on this.
0 Likes
Highlighted
Tourist
26 0 0

Hi @HunkyBill ,

I want to edit an order and add a free variant(variant would already be selected by the user on a form submission and added to customer metafield)

Once the order is placed, we need to edit the order and add the selected variant as free to the user.

So, i followed the guide https://shopify.dev/tutorials/edit-an-existing-order-with-admin-api#add-a-discount-to-the-variant and https://shopify.dev/docs/admin-api/graphql/reference/orders/ordereditaddlineitemdiscount.

I took the orderID and got the calculatedOrderID, using that calculatedOrderID, i added the variant as lineItem and got the calculatedLineItem.

Now using the calculatedlineItem, i need to apply 100% discount to that variant.

Please check my code.  Am doing as per the documentation.

 

Graphql mutation for applying discountGraphql mutation for applying discount

 

ErrorError

 

Kindly help me where am i wrong.

0 Likes
Highlighted
Shopify Expert
4259 32 432

A Line Item ID is not a product variant ID. For one...

Custom Shopify Apps built just for you! hunkybill@gmail.com http://www.resistorsoftware.com
1 Like
Highlighted
Tourist
26 0 0

Thanks @HunkyBill for the heads up. I had changed the lineItemID. But still am facing the same error.

error2.png

 

ERROR:

Error1.png

0 Likes
Highlighted
Tourist
26 0 0

I had made a minor mistake and wanted to share so that it might help someone.

This orderEditAddLineItemDiscount is available in latest version

so Field 'orderEditAddLineItemDiscount' doesn't exist on type 'Mutation'  in this url:  "<myshop>/admin/api/graphql.json"

It works with  "<myshop>/admin/api/2020-10/graphql.json"

 

0 Likes