A space to discuss online store customization, theme development, and Liquid templating.
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?
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
Hi Liam,
That's right, it's not set to be public. The custom app will be used internally only.
There's a couple things you could try to narrow down what's 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
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:
Here's a screenshot of the successful test I made in postman:
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:
Hey Liam,
Regarding the "request for protected access" this is the note that I was referring to:
Not sure where to request that as it is nowhere to be found in the Partner dashboard.
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
Alright, thank you for clarifying regarding that. Looking forward for your response about this matter.
Have a great day ahead Liam!
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
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.
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
Hi Liam,
Will file a ticket to the partner support team regarding this.
Really appreciate you looking into this.
Thanks,
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.
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
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!
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.
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
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:
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,
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.
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!
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.
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!
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 @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 😅
Same here, if our Shopify partner support comes back with anything related, I will update here.
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!
@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.
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 😞
you guys try do
save({ update: false })