Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid id error on orderEditSetQuantity - GraphQL #1148

Open
saeedasma opened this issue Jan 27, 2025 · 1 comment
Open

Invalid id error on orderEditSetQuantity - GraphQL #1148

saeedasma opened this issue Jan 27, 2025 · 1 comment

Comments

@saeedasma
Copy link

Hello,

I am trying to update the line item quantity on an order in Shopify using GraphQL and I am getting "invalid id" error. Can you please help figure out what the issue is? I verified the order and line item id exists in Shopify.

This is my code:

var graphRequest = new GraphRequest()
{
query = """
mutation orderEditSetQuantity($id: ID!, $lineItemId: ID!, $quantity: Int!) {
orderEditSetQuantity(id: $id, lineItemId: $lineItemId, quantity: $quantity) {
calculatedLineItem {
id
quantity
}
calculatedOrder {
id
}
userErrors {
field
message
}
}
}
""",
variables = new
{
id = $"gid://shopify/Order/{orderID}",
lineItemId = $"gid://shopify/LineItem/{lineItemID}",
quantity = 0
}
};

var service = new GraphService(Url, Token);

var resultType = typeof(ShopifySharp.GraphQL.OrderEditSetQuantityPayload);

var result = await service.PostAsync(graphRequest, resultType);

@nozzlegear
Copy link
Owner

Hey @saeedasma! Thanks for reaching out about this. Your GraphQL IDs look correct to me based off of this reference provided by Shopify. I think the problem might be because you're using the deprecated variables property on GraphRequest instead of the recommended Variables which replaced it. The way variables (old one) gets serialized is slightly different, so that may be where things are going awry.

Try this instead:

var graphRequest = new GraphRequest()
{
    Query = 
        """
        mutation orderEditSetQuantity($id: ID!, $lineItemId: ID!, $quantity: Int!) {
            orderEditSetQuantity(id: $id, lineItemId: $lineItemId, quantity: $quantity) {
                calculatedLineItem {
                    id
                    quantity
                }
                calculatedOrder {
                    id
                }
                userErrors {
                    field
                    message
                }
            }
        }
        """,
    Variables = new Dictionary<string, object>
    {
      {"id", $"gid://shopify/Order/{orderID}"},
      {"lineItemId", $"gid://shopify/LineItem/{lineItemID}"},
      {"quantity", 0}
    }
};

var service = new GraphService(Url, Token);
var resultType = typeof(ShopifySharp.GraphQL.OrderEditSetQuantityPayload);
var result = await service.PostAsync(graphRequest, resultType);

Let me know if that works!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants