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.

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

CharlesMoreno
Shopify Partner
19 0 8

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 27 (27)

Liam
Shopify Staff
2602 281 716

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
19 0 8

Hi Liam,

 

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

Liam
Shopify Staff
2602 281 716

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
19 0 8

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
19 0 8

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
Shopify Staff
2602 281 716

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
19 0 8

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

 

Have a great day ahead Liam! 

Liam
Shopify Staff
2602 281 716

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
19 0 8

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
Shopify Staff
2602 281 716

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
19 0 8

Hi Liam,

 

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

 

Really appreciate you looking into this.

 

Thanks,

WarrenWolff
Shopify Partner
8 2 6

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
19 0 8

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
19 0 8

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
8 2 6

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
19 0 8

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
8 2 6

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
19 0 8

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
19 0 8

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
8 2 6

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
19 0 8

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 1

Wow, it's very good @CharlesMoreno 

CharlesMoreno
Shopify Partner
19 0 8

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 1

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 1

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

 

CharlesMoreno
Shopify Partner
19 0 8

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 1

Thank you.