Focusing on managing products, variants, and collections through the API.
I'm having an issue where posting a product is returning 301, and not returning the single product response I would expect from posting 1 product. The 301 seems to make it return a GET response that returns all products which I'm not expecting. I see this on both 2023-04 and 2024-01.
POST Product requestID: 7790f680-e2cb-4351-9a76-aee6875291c7
GET Products requestid that is returned after I make the above call: ff4c8faf-aa81-4a86-9076-722ba5ed4c32
I'm not seeing any internal messages when I check the logs on our side - can you share the full query without any sensitive info? Also does the request match the structure in our docs, and are you using a service like Postman to make this request?
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
Sure, here is the POST and 301 response I'm seeing.
POST https://treadyway.myshopify.com/admin/api/2024-01/products.json HTTP/1.1
Host: treadyway.myshopify.com
Accept: application/json, text/json, text/x-json, text/javascript, application/xml, text/xml
X-Shopify-Access-Token: XXXXX
User-Agent: RestSharp/106.15.0.0
Connection: Keep-Alive
Accept-Encoding: gzip, deflate
Content-Type: application/json
Content-Length: 2410
{
"product": {
"body_html": "body",
"title": "Title",
"vendor": "Vendor",
"variants": [
{
"barcode": "abarcode",
"price": 12.8200,
"inventory_quantity": 48,
"sku": "asku1",
"weight": 14.39,
"weight_unit": "oz"
}
],
"images": [
{
"position": 1,
"src": "imgurl1.jpg"
},
{
"position": 2,
"src": "imgurl2.jpg"
},
{
"position": 3,
"src": "imgurl3.jpg"
},
{
"position": 4,
"src": "imgurl4.jpg"
},
{
"position": 5,
"src": "imgurl5.jpg"
},
{
"position": 6,
"src": "imgurl6.jpg"
}
]
}
}
HTTP/1.1 301 Moved Permanently
Date: Tue, 02 Jan 2024 20:53:20 GMT
Content-Type: text/html; charset=utf-8
Connection: keep-alive
X-Sorting-Hat-PodId: 303
X-Sorting-Hat-ShopId: 83690848560
Referrer-Policy: origin-when-cross-origin
X-Frame-Options: DENY
X-ShopId: 83690848560
X-ShardId: 303
Location: https://376e40.myshopify.com/admin/api/2024-01/products.json
Strict-Transport-Security: max-age=7889238
Set-Cookie: request_method=POST; path=/; SameSite=Lax
Server-Timing: processing;dur=26
X-Shopify-Stage: production
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=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=7790f680-e2cb-4351-9a76-aee6875291c7
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=create&source%5Bapp%5D=Shopify&source%5Bcontroller%5D=admin%2Fproducts&source%5Bsection%5D=admin_api&source%5Buuid%5D=7790f680-e2cb-4351-9a76-aee6875291c7
X-Dc: gcp-us-south1,gcp-us-central1,gcp-us-central1
X-Request-ID: 7790f680-e2cb-4351-9a76-aee6875291c7
CF-Cache-Status: DYNAMIC
Report-To: {"endpoints":[{"url":"https:\/\/a.nel.cloudflare.com\/report\/v3?s=OamjZsxzuFQnMl%2BtwdgMh%2FOIHiKPUWHTPZhJKxEqgRCqSqcSUa3UYIS%2BFFD8%2BoeheDKp5hgL1ovk%2FVbMr3dIXqX1yuep%2BmlaRyjWePVUsvsyxdAwX2oGT3O7JQFtFUBiEc0O5yl%2F9vQ4"}],"group":"cf-nel","max_age":604800}
NEL: {"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}
Server-Timing: cfRequestDuration;dur=83.000183
Server: cloudflare
CF-RAY: 83f5e411cdd8285d-DFW
alt-svc: h3=":443"; ma=86400
Content-Length: 0
We were able to get around this by having the user re-authorize using the different shop name that the 301 was directing to. I believe this customer had a shop name change, and when using that new shop name it caused the 301.
Hi again - this this makes sense a store URL change would trigger a 301 redirect, glad you figured this out!
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