Re: Update and delete not working only get

Solved

Update and delete not working only get

andretrevas
Shopify Partner
4 1 0

I'm attempting to update an asset in my store using an API. All GET requests function correctly, but when I attempt to perform an update (PUT) or deletion, the API returns the list of assets instead of performing the intended update or deletion on the asset. Here's an example:

GET -> themes/xxxx/assets.json -> Return list of assets
GET -> themes/xxxx/assets.json,  $query = ['query' => ['asset' => ['key' => 'snippets/yyyy.liquid']]]; -> Return this
specific asset (key, public_url, value, created_at, etc)
PUT -> themes/xxxx/assets.json,  $json = ['json' => ['asset' => ['key' => 'snippets/yyyy.liquid', 'value' => 'test']]]; -> Return list of assets, like the first request.
DELETE -> themes/xxxx/assets.json,  $query = ['query' => ['asset' => ['key' => 'snippets/yyyy.liquid']]]; -> Return list of assets, like the first request.
 

I've reviewed the permissions of my app, which currently include "write_themes" and "read_themes" access. I have another store where the same code works. This leads me to believe that the issue might stem from a configuration setting within my Shopify setup.

I tried various API versions, from 2022-10 to 2013-10. I also deleted and recreated the app, but unfortunately, none of these steps have yielded successful results.

 

This error also manifests in other endpoints, such as when attempting to create or update an order. 

Accepted Solution (1)

andretrevas
Shopify Partner
4 1 0

This is an accepted solution.

I sent to Shopify developers and they clarified the problem:

Merchants can change their .myshopify.com domain once, but it doesn't actually change the old one, it makes a new one and some things redirect back to the old one.
 
With API requests you get redirected to the original .myshopify.com domain for the store, and some HTTP clients will change POST/PUT requests to GET requests when handling the redirect. So if you take a really close look at yout logs you should notice that those requests that return a list of all the assets are actually GET requests to a different domain than what they originally reached out to.


For me it is an unexpected behavior. I ask to them if they plan to correct this behavior.


Solution: Use the original .myshopify.com instead of renamed .myshopify.com and it will work

View solution in original post

Replies 5 (5)

umerjaved94
Shopify Partner
11 0 0

I would recommend posting this in Shopify Discord Server.

Certified Shopify Developer and Consultant - I make branded stores that reflect authenticity - Most of my work is related to Liquid Coding and Theme Customization.
andretrevas
Shopify Partner
4 1 0

I posted there, no response

andretrevas
Shopify Partner
4 1 0

More information:

When I get both response headers (one working) it is missing Location Headers and the X-XSS-Protection is also wrong. It is ignoring the path, don't know why.

PHP example code:

use GuzzleHttp\Client;
$headers = [ 'headers' => [ 'X-Shopify-Access-Token' => 'xxxxxxxxxxxxxxx', 'Accept' => 'application/json', 'Content-type' => 'application/json', ], ];
$body = ['json' => ['asset' => ['key' => 'snippets/test-checkout.liquid', 'value' => 'test']]];
$options = [ 'timeout' => 10, 'connect_timeout' => 5, ]; $guzzle = new Client($options);
$params = array_merge($body, $headers);
$data = $response->getBody()->getContents();

andretrevas
Shopify Partner
4 1 0

This is an accepted solution.

I sent to Shopify developers and they clarified the problem:

Merchants can change their .myshopify.com domain once, but it doesn't actually change the old one, it makes a new one and some things redirect back to the old one.
 
With API requests you get redirected to the original .myshopify.com domain for the store, and some HTTP clients will change POST/PUT requests to GET requests when handling the redirect. So if you take a really close look at yout logs you should notice that those requests that return a list of all the assets are actually GET requests to a different domain than what they originally reached out to.


For me it is an unexpected behavior. I ask to them if they plan to correct this behavior.


Solution: Use the original .myshopify.com instead of renamed .myshopify.com and it will work

conradbeach
Shopify Partner
2 0 0

Thanks so much for this, Andretrevas. We had this same issue and I've been hunting for the problem and solution for a few days. Your solution worked for my case as well. Thanks for sharing.