We're moving the community! Starting July 7, the current community will be read-only for approx. 2 weeks. You can browse content, but posting will be temporarily unavailable. Learn more

Access Shopify API from extension-only app

Access Shopify API from extension-only app

Samirjs
Shopify Partner
7 0 1

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.

 

Samirjs_0-1734320096351.png

 

Reply 1 (1)

DaisyVo
Shopify Partner
4469 501 599

Hi @Samirjs 

 

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:

  1. 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.
  2. 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 😊

 

I hope this helps

 

Best regards,
Daisy

 

Please let us know if our reply is helpful by giving it a Like or marking it as a Solution!

Avada SEO & Image Optimizer - The #1 SEO solution