Theme App Extension

Theme App Extension

iuzairaziz
Shopify Partner
7 0 2

Hi!
I am trying to make a shopify APP, I have made a custom API in my web folder and the API is returning data but when I try to call the same API in a js file in my theme app extension i get 404 internal server error.
From what I have seen, the baseURL in requestURL is different. When we hit the API from admin side it is like "{somerandomURL/api/products}" but when the API is hit on store side on cart page the url is "{myshopname.shopify.com/api/products}".
How can I call that API in my js file any leads?
TIA

Replies 2 (2)

Liam
Shopify Staff
2823 310 805

Hi Iuzairaziz,

 

When you're working within the Shopify Admin or using embedded apps, your code runs in the context of the Shopify Admin. This context has its own set of permissions and behaviors.

And when your code runs on the storefront (like a theme app extension), it operates in a different context - which is why you might be seeing errors when making the same API call from a JS file in your theme app extension.

 

Specifically what API call are you looking to make within the theme app extension? Also you should ensure that your app has the necessary permissions to access the data you're trying to fetch. If you're using the Shopify API, make sure you've requested and been granted the correct scopes.

 

Hope this helps!

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

iuzairaziz
Shopify Partner
7 0 2

Hi Liam! 
Thank you for the above answer and making things a bit more clear! Much Appreciated! 

So in our shopify app we have made a custom table, where we are storing certain Product-Ids. We have also made a custom API to get data from our custom table and it's working fine, so now I want to call that custom API in the js file of our theme app extension to return the productID store in our custom table. 
App and theme app extension are same.
Our app has permission to read and write both. Is there any other permission we need to give and how can I access this api in my theme app extension?