Solved

API Update Order Tag

aaronroach
New Member
4 0 0

Hello,

 

I've been trying to update an open order to include the tag imported via the rest API.

 

My API body matches the documentation exactly from what i can see however i seem to be getting a 400 response.

 

PUT  admin/api/2019-10/orders/186023031616.json

{ "order": { "id": 186023031616, "tags": "Imported" } }

 When executing the below i get the following response:

{
    "errors": {
        "order": "Required parameter missing or invalid"
    }
}

 

If there's any more information i can give to help find a resolution, let me know!

Accepted Solution (1)
hassain
Shopify Staff (Retired)
624 104 188

This is an accepted solution.

Hey @aaronroach ,

 

In PostMan, change the type of the Body of your PUT request from "Text" to "JSON". Also make sure that the header of "Content-Type"="application/json" has been added to your request. That should resolve your issue.

Here are some screenshots that demonstrate what I am talking about:

19-11-hq463-6f0qm

19-11-ulj4h-kndtk

 

To learn more visit the Shopify Help Center or the Community Blog.

View solution in original post

Replies 12 (12)

hassain
Shopify Staff (Retired)
624 104 188

Hi @aaronroach ,

 

I was able to perform this exact same PUT request for my test store, and I can verify from my end that it worked correctly and my order was updated to have the new "Imported" tag. See the following screenshot: 

19-11-3iw2p-w5nny

Perhaps your error may have come from a formatting issue. If you are still experiencing this same error, could you please provide me with the value of the "X-Request-ID" header from the API Response? With this value I can go through the logs on our end and see why this error may be occurring

 

To learn more visit the Shopify Help Center or the Community Blog.

aaronroach
New Member
4 0 0

Hi @hassain ,

 

Yeah, this seems like a very strange one, I cant seem to see any formatting errors, as what i copied above was exactly what i am sending (all be it with a different ID)

 

An example failure is X-Request-Id: 960bb787-aaec-4abe-979f-7d1bf926ee2e

 

Thanks for your help!

hassain
Shopify Staff (Retired)
624 104 188

Hey @aaronroach ,

 

I was able to find your specific request with the 400 error response through the Shopify platform logs, but unfortunately I was unable to find any information that would indicate why the error was being thrown.

 

Could you verify you are passing the body of with the PUT request? Or using the correct API Access Token with your request? If you could provide a screenshot of the agent you are using to make the request (i.e. POSTMan, Insomnia, cURL) or provide the code that is generating the request, that could help. Thanks

 

To learn more visit the Shopify Help Center or the Community Blog.

aaronroach
New Member
4 0 0

Hi @hassain ,

 

I'm using VB.net to issue the request, however because i was experiencing the issue, i tried to debug it in Postman, however i'm getting the same issue. i'm passing a basic authorisation in the header, and presume its working as I'm not getting any authorisation errors. Using the same token method and auth, i am able to retrieve orders.

 

Its definitely being sent as a PUT as seen below:

 

error 400.png

 

 

hassain
Shopify Staff (Retired)
624 104 188

This is an accepted solution.

Hey @aaronroach ,

 

In PostMan, change the type of the Body of your PUT request from "Text" to "JSON". Also make sure that the header of "Content-Type"="application/json" has been added to your request. That should resolve your issue.

Here are some screenshots that demonstrate what I am talking about:

19-11-hq463-6f0qm

19-11-ulj4h-kndtk

 

To learn more visit the Shopify Help Center or the Community Blog.

aaronroach
New Member
4 0 0

Hi @hassain ,

 

Thanks for this, I completely overlooked that, adding the content type solved it!

Thanks for your help in resolving this issue, and your prompt replies!

 

MJaspan
Shopify Partner
16 1 2

This is a great post! I am looking to do this very thing, BUT, at the Thank you page or immediately after the order is placed. 

 

Can anyone offer me advise in the best way to call the Shop's API post order placement?

MJaspan
Shopify Partner
16 1 2

I am thinking something like this...

 

    <script>
       jQuery.post('/cart/update.js'"updates[{{ all_products[settings.exclusive_product].first_available_variant.id }}]=1");
    </script>
 
hassain
Shopify Staff (Retired)
624 104 188

Hey @MJaspan ,

 

You can look into the concept of Webhooks (https://help.shopify.com/en/manual/sell-online/notifications/webhooks). Webhooks are notifications that Shopify will fire out to your app whenever an event happens that your app is subscribed to. So for example, your app can subscribe to a store's "order/create" topic and then it will receive webhook notifications every time an order happens on that store. 

 

Once you get the webhook notification, you can can then fire the PUT request with the Admin API to update that order to have a new tag (https://shopify.dev/docs/admin-api/rest/reference/orders/order#update-2020-01). 

 

 

To learn more visit the Shopify Help Center or the Community Blog.

MJaspan
Shopify Partner
16 1 2

Thank you @hassain! I will keep this in mind. And, I was able to address it via Workflow. Thankfully my store is Shopify Plus, so we can take advantage of that.

MJaspan
Shopify Partner
16 1 2

Thank you for the feedback! Thank you for the API and Webhooks suggestion, that is definitely an acceptable solution. Thankfully, being that we are a Shopify Plus customer, we are were able to take advantage of the Workflow functionality. Easy to setup and it works like a charm! Thank you all so much.

muhammadsalmank
Shopify Partner
21 1 4

i also had same problem.

its because when you have PUT you must mention type like this:

--header 'Content-Type: application/json'

then problem will be solved.

Thanks