Out now! Check out the Poll results: Do you have a Shopify store?
Our Partner & Developer boards on the community are moving to a brand new home: the .dev community forums! While you can still access past discussions here, for all your future app and storefront building questions, head over to the new forums.

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

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

CharlesMoreno
Shopify Partner
22 0 14

Hi everyone,

 

I'm currently trying out to duplicate a pdp theme template via custom app (part of a bigger feature). To do so, I believe this Rest API reference should do the thing: Reference Link

 

I believe these are the only requirements needed for it to work:

* `write_themes` scope added

* API version set to `2024-01`

 

I have also tested it in POSTMAN  and I can verify that it works using the Develop App credentials. However, for our React/Remix custom app, it doesn't.

 

Here's the example of code:

export const action = async ({ request }) => {
   const { admin, session } = await authenticate.admin(request);
   const asset = new admin.rest.resources.Asset({session: session});

   asset.theme_id = "123456"; // replace with valid theme id
   asset.key = "templates/test-pdp-template.json";
   asset.source_key = "templates/product.json";

   await asset.save({ update: true });
}

 

Given example is for test sake. When submit is executed, it should create a pdp theme template based from the `templates/product.json` which by default exists. However, what I'm getting is 404.

 

Did I miss something? 

Replies 35 (35)

Liam
Community Manager
3108 344 889

Hi Charles,

 

Just to confirm, the React/Remix based app is not set up to be a public app, correct? 

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

CharlesMoreno
Shopify Partner
22 0 14

Hi Liam,

 

That's right, it's not set to be public. The custom app will be used internally only.

Liam
Community Manager
3108 344 889

There's a couple things you could try to narrow down what's happening:

  • Can you try adding the `read themes` scope too to see if this makes a difference?
  • Could you try testing to see if there any other API calls (eg: creating a product) that are not working, or if it's only calls to the Asset API?
  • Check if the code that works in postman is the exact same?

 

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

CharlesMoreno
Shopify Partner
22 0 14

Hey Liam,

 

Yes, `read_themes` is already added too. Here's the scopes that we're using:

 

scopes = "read_products,write_products,read_orders,write_orders,read_customers,write_discounts,read_metaobjects,read_metaobject_definitions,read_themes,write_themes"

 

 

In Shopify Partner:
Screenshot 2024-01-31 at 8.34.28 PM.png

 

 

 

 

 

 

 

 

 


Here's a screenshot of the successful test I made in postman:

Screenshot 2024-01-31 at 8.29.13 PM.png

 

 

 

 

 

 

 

 

 

 

 

 

 

 

 

Can confirm too that I can create product using the `admin.rest.resources.Product`. Here's an example of my code:

 

export async function createProduct(request) {
  const { admin, session } = await authenticate.admin(request);
  
  const product = new admin.rest.resources.Product({session: session});
  product.title = "1 Test Product from custom app";
  product.body_html = "<strong>Test Description</strong>";
  product.status = "draft";
  await product.save({
    update: true,
  });
}

 

 

Screenshot of the product that got created:

Screenshot 2024-01-31 at 8.39.04 PM.png

 

CharlesMoreno
Shopify Partner
22 0 14

Hey Liam, 

 

Regarding the "request for protected access" this is the note that I was referring to:

Screenshot 2024-01-31 at 8.40.34 PM.png

 

 

 

 

 

 

 

 

 

 

Not sure where to request that as it is nowhere to be found in the Partner dashboard.

Liam
Community Manager
3108 344 889

This request for access should only be required if your app is a public app - and it should not apply to custom apps. Will connect with our internal dev team to try to understand why this is happening. 

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

CharlesMoreno
Shopify Partner
22 0 14

Alright, thank you for clarifying regarding that. Looking forward for your response about this matter.

 

Have a great day ahead Liam! 

Liam
Community Manager
3108 344 889

Hi again Charles,

 

Still looking into this, are you 100% certain that the credentials you are using in Postman to successfully make a PUT request to the Asset API are the same as the one that is failing in the remix app?

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

CharlesMoreno
Shopify Partner
22 0 14

Hey Liam,

 

I think I have mentioned in one of my reply that I was using a Develop App's credentials in postman (the one that you can create via "Apps and sales channels" option in the settings). So I believe it is using a different one than the remix app.

Liam
Community Manager
3108 344 889

Okay - I think that may be the issue, it's very possible that the credentials that you're using on the remix app is associated with an app that is not set up as a custom app. You may need to connect with our partner support team to look into this app specifically to confirm. 

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

CharlesMoreno
Shopify Partner
22 0 14

Hi Liam,

 

Will file a ticket to the partner support team regarding this.

 

Really appreciate you looking into this.

 

Thanks,

axeltta
Shopify Partner
20 1 4

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

Liam
Community Manager
3108 344 889

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

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

WarrenWolff
Shopify Partner
16 3 11

Hello @CharlesMoreno and @Liam , there are any news on the Assets API PUT Remix app?
I'm encountering the same issue.
We have developed an app that relies on AssetsApi, it is already in production. It has the exemption to use the AssetsAPI.

For now, the production app works, but on local environment it does not work anymore, even trying to downgrade version of the shopify-api, I tried 2023-01, 2023-10, and 2024-01.
Assets API for the GET works fine.
There is no doubt that the API request is well written, as it is the same a per Shopify's documentation and also, is the same as the one in Prod which is currently working, and no changes were done.

 

Let me know, anything that could be helpful. Thank you!

CharlesMoreno
Shopify Partner
22 0 14

Hi @WarrenWolff,

 

I feel bad that you're encountering the same but that's great to know that I'm not the only one that's having this problem. I already escalated this issue via sending a support ticket in the Shopify Partner dashboard. I already gave them all the essential information that they need and just waiting for their response about it.

 

Will definitely update you once I hear from them.

CharlesMoreno
Shopify Partner
22 0 14

Hey @WarrenWolff , 

 

While I'm in the process of giving them more information about the problem that we're facing. My last test without changing anything seems to have worked already. I was able to create/modify assets using the Assets API in the Remix App. 

 

I already asked for a confirmation whether they released a fix for it already. Let me know if it is the same on your end.

 

Thanks,

Charles Moreno

WarrenWolff
Shopify Partner
16 3 11

Hi @CharlesMoreno , fantastic news for you.
I just tested and unfortunately for me it is not yet working. Now I'm wondering why it works for you. Maybe ApiVersion or node package.
I'm using 2024-01 on shopify.server.ts and I'm also using new admin.rest.resources.Asset({ session }) to then asset.save(), one thing that is worth to check with you is the package version: 

"@shopify/shopify-api": "^9.0.1" -> which scaffolds the 9.0.2
WarrenWolff_2-1707492360326.png

 


WarrenWolff_0-1707492124499.png

 

CharlesMoreno
Shopify Partner
22 0 14

Hey @WarrenWolff,

 

Just received the confirmation from them that they have rolled out a fix for it! Hopefully it is resolved on your end as well.

 

Have a great day!

 

Thanks,

 

WarrenWolff
Shopify Partner
16 3 11

Nothing, I tried package @Shopify/shopify-api: 9.2.0 which was release 1 hour ago more or less. And it still doesn't work, it is quite incredible.

CharlesMoreno
Shopify Partner
22 0 14

Hi @WarrenWolff,

 

Sorry for getting back to you late.

 

I just verified again that it is indeed not working again. 

I will reach out again to the support regarding this. Hold on tight, will update you soon! 

 

 

CharlesMoreno
Shopify Partner
22 0 14

Hey @WarrenWolff,

 

I just noticed from your screenshot that you're still getting a 404 error rather than 422. Have you tried to check your Shopify Partner App if it's already distributed as a custom app? You can do so by going to the "Distribution" then choose "Custom Distribution". Take note that this does not entirely resolve your issue.

 

After that, your app should have a "Custom App" tag when viewed in the apps list. With that, the error changed from 404 to 422 to me. Will update you soon once I hear back from the support of why we're still getting these errors.

WarrenWolff
Shopify Partner
16 3 11

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.

CharlesMoreno
Shopify Partner
22 0 14

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!

Darshan13
Shopify Partner
11 0 2

Wow, it's very good @CharlesMoreno 

CharlesMoreno
Shopify Partner
22 0 14

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! 

Darshan13
Shopify Partner
11 0 2

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.

Darshan13
Shopify Partner
11 0 2

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

 

CharlesMoreno
Shopify Partner
22 0 14

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! 

 

Darshan13
Shopify Partner
11 0 2

Thank you.

WarrenWolff
Shopify Partner
16 3 11

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 😅

 

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

CharlesMoreno
Shopify Partner
22 0 14

@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!

1080
Shopify Partner
301 9 65

@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.

WarrenWolff
Shopify Partner
16 3 11

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.

MichaelBallen
Shopify Partner
1 0 0

Hi @CharlesMoreno @WarrenWolff 
How did it go?
I'm still having the same problem 😞


DMaxito
Shopify Partner
1 0 0

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