Problems using draftOrderUpdate mutation

Solved
Jamie_StackUp
New Member
6 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!

0 Likes
Jamie_StackUp
New Member
6 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?

0 Likes
syf_
Shopify Staff
Shopify Staff
81 18 14

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
6 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!

0 Likes
Jamie_StackUp
New Member
6 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!

0 Likes
syf_
Shopify Staff
Shopify Staff
81 18 14

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

0 Likes