Create/Update using Assets API on Shopify React/Remix custom app returns 404

Ehi! @CharlesMoreno ,

Ah, sad to know that you are still on my same boat. Yes, I don’t see anyway around. It really seems like that does PUT/DEL endpoint got somehow compromised and not on the library itself but rather on their servers, it is or the endpoint got must more restricted with authentication, or they got renamed/moved/deleted.

As the app stopped working at random without any update of the package on our side, then we have nothing that we can do. We can only wait for Shopify support. My team also submitted a ticket, let’s hope soon they will solve this issue.

Btw, we have the app up and running in the Shopify App store, and there it is still working.

Hi @WarrenWolff ,

While we’re waiting for their response. I come up with a solution that works with our remix application. As an alternative, we can just make a Rest API call instead (did this inside the action router):

const { admin, session } = await authenticate.admin(request);

// Used admin.rest.resources.Theme for this
const mainTheme = await fetchMainTheme(request);

const options = {
  method: 'PUT',
  headers: {
    'X-Shopify-Access-Token': session.accessToken,
    'Content-Type': 'application/json'
  },
  body: JSON.stringify({
    "asset": {
       "key": "templates/product.test-pdp-template.json",
       "source_key": "templates/product.json"
    }
  })
}
fetch(`https://${session.shop}/admin/api/2024-01/themes/${mainTheme.id}/assets.json`, options)
    .then(response => response.json())
    .then(data => {
       console.log("Data: ")
       console.log(data);
    })
    .catch(error => console.error("Error:" + error));

Sample Response:

01:32:15 │ remix │ {
01:32:15 │ remix │    asset: {
01:32:15 │ remix │      key: 'templates/product.test-pdp-3-template.json',
01:32:15 │ remix │      public_url: null,
01:32:15 │ remix │      created_at: '2024-02-14T12:32:15-05:00',
01:32:15 │ remix │      updated_at: '2024-02-14T12:32:15-05:00',
01:32:15 │ remix │      content_type: 'application/json',
01:32:15 │ remix │      size: 1629,
01:32:15 │ remix │      checksum: 'c797e11d248ad1a7a34d8b96dd4e8f03',
01:32:15 │ remix │      theme_id: 158160519488,
01:32:15 │ remix │      warnings: []
01:32:15 │ remix │   }
01:32:15 │ remix │ }

Hope this helps!

Wow, it’s very good @CharlesMoreno

Hi @Darshan13 ,

Good to know that it helped you as well. Feel free to mark it as an accepted solution while we wait for them to fix it on their end.

Will appreciate it. Thank you so much!

Hi @CharlesMoreno ,
can you explain what I write in this function and what is meaning to write this function?
const mainTheme = await fetchMainTheme(request);

Thank you.

Hey, @CharlesMoreno & @WarrenWolff have you found any solution for this?

Hey @Darshan13 ,

Did not hear anything yet from the Shopify Partner support. Will definitely inform here once I hear from them.

By the way, regarding with the

const mainTheme = await fetchMainTheme(request);

It’s just function that I create that calls the Theme API in the remix app then find the current LIVE theme, nothing much.

Hope that helps!

Thank you.

Yes, this will help us keep going the development process smooth! Thanks.

So, it doesn’t seem an issue on the endpoint themself but the library itself. Great to have a workaround, thanks a lot @CharlesMoreno we could have tried out it before :sweat_smile:

Same here, if our Shopify partner support comes back with anything related, I will update here.

@WarrenWolff ,

Yup, likely that’s what it is. haha. You’re welcome!

Yes please do let us know incase they response back to you.

Have a great day ahead!

No official answer from Shopify support.
But for our needs I have submitted 2 more app exemption, explaining within the form the reasons and that the app itself won’t anyhow go in PROD and is a copy of what is already in PROD. They did not hesitate to accept it, it happened even over just 1 day.

And for these app, the AssetsAPI works fine.

So, with the exemption this REST API works:

const asset = new admin.rest.resources.Asset({session: session});
...
await asset.save({ update: true });

I would say would be cool if Shopify instead of returning 404 would return 401 Unauthorized or similar with a brief explanation regarding the required exemption. I don’t know if it was on purpose but to me it makes sense as they want developers to NOT rely on it, hide it behind a permission on their side even for DEV and testing purposes.

Hi @CharlesMoreno @WarrenWolff
How did it go?
I’m still having the same problem :disappointed_face:

you guys try do
save({ update: false })

hey liam, just to double check, my app is a public app on the shopify app store, does this mean that if i want to edit theme files (PUT) I need an excemption, if so how long does it usually take as I have already requested one.

Thanks

HI Axeltta - correct you’ll need to request an exception, you should hear back in approx one week.

@CharlesMoreno Thanks for the Code snippets it’s look like working fine but. I have tried with the Rest API call using the Postman but getting the 404 . could you please help me the payload to pass.