A space to discuss GraphQL queries, mutations, troubleshooting, throttling, and best practices.
I'm trying to update some order info after an order is created. I'm able to successfully authenticate with the API, but a PUT request doesn't update the fields like I'd expect. For example, trying to update the note field, the response is a 200 status code, but the response body does not contain the updated information:
PUT /admin/api/2020-04/orders/2146398797903.json
body
{ "order": { "id": 2146398797903, "note": "foo" } }
response
{ "order": { "id": 2146398797903, "closed_at": null, "created_at": "2020-03-31T11:59:55-05:00", "updated_at": "2020-04-03T12:58:29-05:00", "note": null, //... } }
I'm testing the API using Postman. Trying to authenticate using the "Authorization: Basic [base64 encoded username:password]" was unsuccessful. I have authenticated using the "X-Shopify-Access-Token" header, as explained here.
I suspect I'm missing a critical piece to be able to successfully update orders - any advice or resources to check out?
Hey @surefootme,
It's strange that you're getting a 200 response if the order isn't actually being updated. Can you try sending the request with the auth credentials in the URL? Like https://{{api_key}}:{{api_secret}}@shop.myshopify.com/admin/api...
Also please provide the X-Request-ID value from the response headers of your call, and I'll check our logs for more information.
JB | Solutions Engineer @ Shopify
- Was your question answered? Mark it as an Accepted Solution
- To learn more visit Shopify.dev or the Shopify Web Design and Development Blog
Using Postman, are you adding Content-Type: application/json as a header? And the body is defined as raw: JSON?
Thanks for the reply, I figured it out! I was using the full domain of the site to hit the API endpoint, rather than shop.myshopify.com as the domain. Things are working as expected now!
you need a print provider api
How did you make the put request, can u give me an example of code?
I thought the OP already did above. Here is another sanitized example, where I simply add a note to an existing order. Hope this helps!
PUT https://{my_shop}.myshopify.com/admin/api/2020-04/orders/1897779691572.json HTTP/1.1
Content-Type: application/json
Authorization: Basic {my_auth}
User-Agent: PostmanRuntime/7.26.8
Accept: */*
Postman-Token: 50745ffe-9ff4-47f9-b657-76a711ef2160
Host: {my_shop}.myshopify.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 86
{
"order": {
"id": 1897779691572,
"note": "test-note"
}
}
is this using postman?
As the PUT request header indicated, indeed it is. But the barebones request headers, the PUT URL, the PUT request body, etc. are generically applied regardless of what tool you are using to issue the request, right?
That's right, i am having hard time changing order phone number using put request, i am trying with js right now i wrote "get" request and got the order with response, but now i need to update it to admin with api call request, i am kinda new with shopify api so i am trying this on js syntax:
PUT /admin/api/2020-10/orders/450789469.json
{ "order": { "id": 450789469, "phone": "+15145556677" } }
$.ajax({
method: "PUT",
url: api_url_post,
data: {
"order": {
"id": hiddennumber,
"phone": "0000"
}
},
contentType: "application/json;",
crossDomain: true,
dataType: "json",
success: function (data, status, jqXHR) {
alert("success");// write success in " "
},
error: function (jqXHR, status) {
// error handler
console.log(jqXHR);
alert('fail' + status.code);
}
});
});
this returns undefiend ( the url link is variable )
sorry to bother
I would simplify things before delving into if the AJAX might be incorrect. First try issuing the basic request using curl, Postman, etc. If it works then you know the actual PUT request is okay. One thing I recall is that I think it's the Shopify API provider that validates phone numbers, e-mail address, etc. So if you are using dummy values for those the API request might fail due to that...