Is there a way to make a direct api request on Theme App Extension? I’m trying to make requests to shopify API on an extension-only app.
I tried to use fetch to call graphql API. It worked on development store, but when I installed the app on a real store it started to throw an cors error.
The issue you’re facing happens because Shopify’s API doesn’t allow direct requests from the browser due to CORS restrictions (Read more about it here) . This is done for security reasons. Here are some solutions:
Use a Backend Server:
Instead of calling the Shopify API directly from your theme, send the request to your own server.
Your server will then make the request to Shopify’s API and send the response back to the theme.
Use Shopify App Proxy:
Shopify provides App Proxies to help you securely fetch data.
You can configure a proxy in your app’s admin under App Setup > App Proxy.
This way, the theme makes requests to a safe proxy URL, and your server handles the API calls.
Unfortunately, direct client-side API calls aren’t allowed in live stores as Shopify’s security model blocks such attempts to prevent abuse. Setting up a backend or app proxy will solve the issue