Order Edit mutation to apply discount gives mutation error

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: 100, description: “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.

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.

Kindly help me where am i wrong.

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

1 Like

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

ERROR:

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: “/admin/api/graphql.json”

It works with “/admin/api/2020-10/graphql.json”

1 Like