Join us for an upcoming Shopify Partner webinar on February 27, 2024. Discover the latest Checkout Extensibility features, and deep dive on improvements to Shopify Functions and Web Pixels. Register now for either the 10am EST or 2pm EST sessions.
Solved

PUT product does not update the title

ciiboivy
Tourist
3 2 1

 

I'm trying to start using the REST API, so am working in Postman first. I can get products, but I am unable to update a product's title. The PUT appears to work (I get back a 301) but the title never changes in the store. I am sure I am doing something really stupid. 

 

Here's what I am trying (this is Postman's code output, replaced sensitive info with '{}') :

 

curl --location --request PUT 'https://{}.myshopify.com/admin/api/2023-10/products/8852085932353.json' \
--header 'Content-Type: application/json' \
--header 'X-Shopify-Access-Token: {}' \
--header 'Cookie: request_method=PUT' \
--data '{
  "product": {
    "id": 8852085932353,
    "title": "New product title"
  }
}'

Here's the raw log of the request/response:

PUT / HTTP/1.1
Content-Type: application/json
X-Shopify-Access-Token: {}
User-Agent: PostmanRuntime/7.35.0
Accept: */*
Postman-Token: c9c09924-97d4-45ce-985b-83d21d50ffbe
Host: {}.myshopify.com
Accept-Encoding: gzip, deflate, br
Connection: keep-alive
Content-Length: 80
Cookie: request_method=PUT

HTTP/1.1 301
Date: Tue, 02 Jan 2024 16:33:25 GMT
Content-Type: text/html; charset=utf-8
Transfer-Encoding: chunked
Connection: keep-alive
X-Sorting-Hat-PodId: 320
X-Sorting-Hat-ShopId: 81694359873
referrer-policy: origin-when-cross-origin
x-frame-options: DENY
x-shopid: 81694359873
x-shardid: 320
location: https://{}.myshopify.com/admin/api/2023-10/products/8852085932353.json
strict-transport-security: max-age=7889238
server-timing: processing;dur=23
x-shopify-stage: canary
content-security-policy: default-src 'self' data: blob: 'unsafe-inline' 'unsafe-eval' https://* shopify-pos://*; block-all-mixed-content; child-src 'self' https://* shopify-pos://*; connect-src 'self' wss://* https://*; frame-ancestors 'none'; img-src 'self' data: blob: https:; script-src https://cdn.shopify.com https://cdn.shopifycdn.net https://checkout.shopifycs.com https://api.stripe.com https://mpsnare.iesnare.com https://appcenter.intuit.com https://www.paypal.com https://js.braintreegateway.com https://c.paypal.com https://maps.googleapis.com https://www.google-analytics.com https://v.shopify.com 'self' 'unsafe-inline' 'unsafe-eval'; upgrade-insecure-requests; report-uri /csp-report?source%5Baction%5D=update&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=c091d9c3-5d3b-477a-af3b-422c957f19fc
x-content-type-options: nosniff
x-download-options: noopen
x-permitted-cross-domain-policies: none
x-xss-protection: 1; mode=block; report=/xss-report?source%5Baction%5D=update&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=c091d9c3-5d3b-477a-af3b-422c957f19fc
x-envoy-upstream-service-time: 25
X-Request-ID: c091d9c3-5d3b-477a-af3b-422c957f19fc
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=H9tNb8lMlYy71J3h%2FO%2FnP2GI7b%2BD1NhEauVvlewCDZviCrz8cc%2B5y5%2B6CFxugi3aqFPDezvH7BeBtO9BlcmcIU3nNbMkh93YpCNgfd8sn99%2FFhxu34%2FTGH3%2BzK1SZCjV9VAxKfi7xg4%3D"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}
Server-Timing: cfRequestDuration;dur=72.999954
Server: cloudflare
CF-RAY: 83f467588a5beae9-DFW
alt-svc: h3=":443"; ma=86400

 

The 301 results in the unchanged product coming back, and the Shopify admin confirms the title has not been updated.

 

Any ideas?

Accepted Solutions (2)
ciiboivy
Tourist
3 2 1

This is an accepted solution.

So...newbie error. I was using the external friendly domain name of my store instead of my store name that you can see when logging into the admin (e.g. 'https://admin.shopify.com/store/999xxx) - the '999xxx' part is what you should be using as '999xxx.myshopify.com' - this works for GETs but not for anything else. It was 301 redirecting me back to the correct URL with a GET.

View solution in original post

ciiboivy
Tourist
3 2 1

This is an accepted solution.

I should have said that the my public store URL works when issuing a GET, but fails on a PUT/POST/DELETE - you will get 301 redirected back to a  '999xxx.myshopify.com' URL. To fix the problem, always use '999xxx.myshopify.com' as the domain, and all 4 verbs will work.

View solution in original post

Replies 4 (4)

Liam
Shopify Staff
2669 288 730

Hi Ciiboivy,

 

If you're seeing a 301 being returned, this suggests that something related to a redirect is taking place - ideally you should be seeing a 200 response. I would doublecheck that the URL you're using in the PUT request is correct (that the store URL is accurate and the endpoint is in the right format.

 

One thing to check would be to run the request in Terminal to see if there's a config issue in Postman that might be causing this. 

Liam | Developer Advocate @ 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

ciiboivy
Tourist
3 2 1

This is an accepted solution.

So...newbie error. I was using the external friendly domain name of my store instead of my store name that you can see when logging into the admin (e.g. 'https://admin.shopify.com/store/999xxx) - the '999xxx' part is what you should be using as '999xxx.myshopify.com' - this works for GETs but not for anything else. It was 301 redirecting me back to the correct URL with a GET.
Liam
Shopify Staff
2669 288 730

Glad you figured this out - I was think it was URL/ domain related. Best of luck with the rest of your project!

Liam | Developer Advocate @ 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

ciiboivy
Tourist
3 2 1

This is an accepted solution.

I should have said that the my public store URL works when issuing a GET, but fails on a PUT/POST/DELETE - you will get 301 redirected back to a  '999xxx.myshopify.com' URL. To fix the problem, always use '999xxx.myshopify.com' as the domain, and all 4 verbs will work.