Solved

Problems using draftOrderUpdate mutation

Jamie_StackUp
New Member
10 0 0

Hi there,

I can't work out whether this is a problem on my end (i.e. am I using the wrong ID) or if this is a bug with Shopify.

I have a draft order and I want to update it with the Shopify Admin GraphQL API as per https://shopify.dev/docs/admin-api/graphql/reference/orders/draftorderupdate#draftorderinput-fields-...

I have a payload which I am passing into the input (note that this is a reduced version of what I am actually sending, but this should still work).

Mutation:

mutation draftOrderUpdate($id: ID!, $input: DraftOrderInput!) {
  draftOrderUpdate(id: $id, input: $input) {
    draftOrder {
      id
    }
    userErrors {
      field
      message
    }
  }
}

Variables:

{
  "id": "gid://shopify/DraftOrder/738221752504",
  "input": {
    "email": "joe@bloggs.com",
    "customerId": "customer-id-here",
    "lineItems": [
      {
        "quantity": 1,
        "variantId": "gid://shopify/Product/6186305716408"
      }
    ],
    "customAttributes": []
  }
}

However, when I try to run this mutation (either in my code or within the Insomnia API tool) I am getting this error:

{
  "data": {
    "draftOrderUpdate": null
  },
  "errors": [
    {
      "message": "invalid id",
      "locations": [
        {
          "line": 2,
          "column": 3
        }
      ],
      "path": [ "draftOrderUpdate" ]
    }
  ]
}

I'm completely at a loss. The only difference (between the payload I am sending and the Shopify example) that I could find was that the format of the order ID is different. See below:

My ID:

gid://shopify/DraftOrder/738221752504

Example ID from link posted earlier:

Z2lkOi8vU2hvcGlmeS9FeGFtcGxlLzE=

The example ID appears to be a base64 string, I decoded this and got:

gid://Shopify/Example/1

So, to rule this out, I also tried encoding my ID as a base64 string and received the same error.

Has anyone else experienced this issue? This functionality is pretty key to the app that I'm developing so I'm in a bit of a situation without this mutation!

Any help would be really appreciated.

Thanks!

Accepted Solution (1)
syf_
Shopify Staff
95 21 24

This is an accepted solution.

Hi @Jamie_StackUp,

I believe the error originates from the variantId of your variable. You've indicated a product id which is not what the field is expecting. You should be using "gid://shopify/ProductVariant" instead of "gid://shopify/Product". 

Hopefully this helps resolve the error you're getting. Let me know if you have any more questions on this.

Best,
Seth.

syf_ | Developer Support @ 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

Replies 7 (7)

Jamie_StackUp
New Member
10 0 0

Can someone from Shopify at least advise the best way to raise this as a possible bug and that the documentation is potentially showing incorrect information?

syf_
Shopify Staff
95 21 24

This is an accepted solution.

Hi @Jamie_StackUp,

I believe the error originates from the variantId of your variable. You've indicated a product id which is not what the field is expecting. You should be using "gid://shopify/ProductVariant" instead of "gid://shopify/Product". 

Hopefully this helps resolve the error you're getting. Let me know if you have any more questions on this.

Best,
Seth.

syf_ | Developer Support @ 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

Jamie_StackUp
New Member
10 0 0

Hi Seth, thank you so much for getting back to me.

I'll have a look at this in the morning but yes, I agree, now you've pointed that out it's clear as day!

I'll report back tomorrow and accept the answer if this works.

Thank you again!

Jamie_StackUp
New Member
10 0 0

Hey @syf_ you've hit the nail on the head there, that was certainly the problem.

Thanks for clearing it up and I'm sorry for taking up your time with my mistake!

syf_
Shopify Staff
95 21 24

Hey @Jamie_StackUp,

I'm glad the mutation is working as expected for you, and it was my pleasure to be of help. I do admit though that our error messages could be more specific, and if they were it would have helped you in debugging and identifying the cause of the error.

All the best as you continue to use our developer products!

Seth.

syf_ | Developer Support @ 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

bilal87
Shopify Partner
7 0 0

I am trying to run this mutation but it's not working, can you let me know what am I doing wrong?

mutation {
draftOrderUpdate(
id: "gid://shopify/DraftOrder/1140887388443"
input: {
email: "joe@bloggs.com",
lineItems: [
{
variantId: "gid://shopify/ProductVariant/47204229939483",
quantity: 1
}
]
}
) {
draftOrder {
id
}
}
}

ShopifyDevSup
Shopify Staff
1299 210 451

Hey @bilal87

I don't see anything in your mutation that stands out as an issue. I'd recommend looking in to any errors that were returned as that would give you more clarity. 

 

Adding in the user errors in your response can help: 

 

userErrors {
     field
     message
   }

You can also consult our documentation here for more clarity on these mutations - https://shopify.dev/docs/api/admin-graphql/2023-10/mutations/draftOrderUpdate#top 

 

Hope that helps, 

 

- Kyle G.

 

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