Discussing APIs and development related to customers, discounts, and order management.
Hi Team,
I'm trying to create a new product variant with GraphQL API in the existing order.
here is the json code that I am using
{"query":"mutation orderEditAddVariant($id: ID!, $quantity: Int!, $variantId: ID!) {\r\n\t\t\t\t\torderEditAddVariant(id: $id, quantity: $quantity, variantId: $variantId) {\r\n\t\t\t\t\t\tcalculatedOrder {\r\n\t\t\t\t\t\t\tid\r\n\t\t\t\t\t\t\taddedLineItems(first:5) {\r\n\t\t\t\t\t\t\t edges {\r\n\t\t\t\t\t\t\t\t node {\r\n\t\t\t\t\t\t\t\t id\r\n\t\t\t\t\t\t\t\t quantity\r\n\t\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\tlineItems(first:10){\r\n\t\t\t\t\t\t\t\tedges {\r\n\t\t\t\t\t\t\t\t\tnode {\r\n\t\t\t\t\t\t\t\t\t id\r\n\t\t\t\t\t\t\t\t\t quantity\r\n\t\t\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t\t\t }\r\n\t\t\t\t\t\t\t}\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t\tcalculatedLineItem {\r\n\t\t\t\t\t\t\tid\r\n\t\t\t\t\t\t\ttitle\r\n\t\t\t\t\t\t}\r\n\t\t\t\t\t userErrors {\r\n\t\t\t\t\t\tfield\r\n\t\t\t\t\t\tmessage\r\n\t\t\t\t\t }\r\n\t\t\t\t\t}\r\n\t\t\t\t}","variables":{"allowDuplicates":true,"id":"gid:\/\/shopify\/CalculatedOrder\/28891938905","quantity":1,"variantId":"gid:\/\/shopify\/ProductVariant\/12408611176537"}}
But I am getting an error that this item is not able to add it's already added. But as you see I added "allowDuplicates":true, in my query that is used to allow duplicate products with order edit.
{"data":{"orderEditAddVariant":{"calculatedOrder":null,"calculatedLineItem":null,"userErrors":[{"field":["id"],"message":"All things American Black Tank Top - Black \/ S was not added because it's already on the order."}]}},"extensions":{"cost":{"requestedQueryCost":29,"actualQueryCost":10,"throttleStatus":{"maximumAvailable":10000.0,"currentlyAvailable":9990,"restoreRate":500.0}}}}
Can anyone help me with this issue? as its really urgent for me to fix this.
Thanks,
Villiam
Solved! Go to the solution
This is an accepted solution.
Hi @Villiamjit,
Thanks for your post. When using the orderEditAddVariant mutation in a test store with v2023-01 it's working as expected, returning that same error if the variant is already on the order unless allowDuplicates is set to true in which case it adds the item.
One thing that seems unusual about the example you provided is that in the return value calculatedOrder shows as null instead of showing some info about the calculatedOrder which could be a clue. As it is we have not been able to replicate that same problem with the information at hand.
Here's the query that was tested and which worked, perhaps trying this alternative formatting will help to track down what's going wrong:
mutation addVariantToOrder {
orderEditAddVariant(
id: "gid://shopify/CalculatedOrder/47100000123"
variantId: "gid://shopify/ProductVariant/3130000005456"
quantity: 1
allowDuplicates: true
) {
calculatedOrder {
id
addedLineItems(first: 5) {
edges {
node {
id
quantity
}
}
}
}
userErrors {
field
message
}
}
}
If you're still having trouble after the above an option is to reach out to API support by choosing the Support option in the Partner dash, choosing the API option, and providing more specific details to enable a closer look at the environment.
Have a great day,
Jon551
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
This is an accepted solution.
Hi @Villiamjit,
Thanks for your post. When using the orderEditAddVariant mutation in a test store with v2023-01 it's working as expected, returning that same error if the variant is already on the order unless allowDuplicates is set to true in which case it adds the item.
One thing that seems unusual about the example you provided is that in the return value calculatedOrder shows as null instead of showing some info about the calculatedOrder which could be a clue. As it is we have not been able to replicate that same problem with the information at hand.
Here's the query that was tested and which worked, perhaps trying this alternative formatting will help to track down what's going wrong:
mutation addVariantToOrder {
orderEditAddVariant(
id: "gid://shopify/CalculatedOrder/47100000123"
variantId: "gid://shopify/ProductVariant/3130000005456"
quantity: 1
allowDuplicates: true
) {
calculatedOrder {
id
addedLineItems(first: 5) {
edges {
node {
id
quantity
}
}
}
}
userErrors {
field
message
}
}
}
If you're still having trouble after the above an option is to reach out to API support by choosing the Support option in the Partner dash, choosing the API option, and providing more specific details to enable a closer look at the environment.
Have a great day,
Jon551
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
I do not believe this is accurate. I am getting the same error even when I have allowDuplicates set to true.
Hi @benbenben1
I've ran that query again, adding a duplicate variant to an existing order with the same query that Jon shared above, and I can confirm that we are still unable to replicate the error. I was successfully able to add a duplicate line item with the orderEditAddVariant mutation, with allowDuplicates: true.
Since we are unable to replicate the error on our end, and the mutation is working as expected, we will need further context from you to be able to help look into the error you are receiving, with specific examples of api calls that have failed.
If you can please prepare answers to the following troubleshooting questions, and reach out to our Partner Support team via your Partner Dashboard and provide Partner Support with your answers to the questions below. Once you've reached out through the Support team we can help look into the error occurring with your app specifically in further detail. This is required so that we can authenticate with the store and app where the error is occurring and look into this further within in our internal logs if needed.
Troubleshooting questions needed to look into this further, Please fill this out with as much detail as possible:
1. Expected Behavior vs. Actual Behavior
2. Environment & Scope of the Issue
3. Timeframe
4. New Feature or Existing
5. Replication and Raw Example
We appreciate your understanding in that we do require ALL of the information above to fully troubleshoot and determine any issues that may be occurring when using our API.
I hope this helps, and I hope you have a great day 🙂
Developer Support @ Shopify
- Was this reply helpful? Click Like to let us 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
If you create a calculated order with "orderEditBegin" mutation then add a variant to that calculated order using the "orderEditAddVariant" (with allowDuplicates:true) -- I can even add the same variant twice with orderEditAddVariant, then commit that order edit with "orderEditCommit" mutation that all succeeds. So it seems like allowDuplicates is working as expected here.
The issue is introduced if I take the original order again and repeat the exact same steps. Create a new 2nd calculatedOrder with the orderEditBegin mutation and then try to add that same variant again... now I get an error saying it's already on the order.
Here's a screenshot of the exact request and response where you can see the issue even though allowDuplicates is true.
I think the Shopify docs should be updated to make it clearer that you are NOT able to use orderEditAddVariant to add a variant to an order if that variant is already on the original order. allowDuplicates allows you to add duplicates on the calculated order but not on the original order.
Hi @ben ,
There is an error in your graphQL mutation. You haven't used the variable for allowDuplicates in your mutation you have only defined in your variables so the mutation runs with the default false flag. The mutation needs to be updated as per below:
mutation orderEditAddVariant($id: !ID, $quantity: Int!, $variantID: ID!, $allowDuplicates: Boolean){
orderEditAddVariant(id: $id, quantity: $quantity, variantId: $variantId, allowDuplicates: $allowDuplicates) {
You need the allowduplicates in both the mutation definition and mutation type. Once there your variable will make its way into your mutation and correctly set the flag to True and allow you to add additional orderlines of the same variant.
Thanks,
Max
You're right Max 😳 thank you for checking that