Skip to main content

Using Requests in Widgets

Widgets can call APIEase requests through JavaScript. The widget's JavaScript runs in the browser, but the request runs on the server. This separation keeps integrations secure by keeping credentials and private logic off the storefront.

For the JavaScript call below, add the Storefront App Proxy trigger to the directly called request and save it. The JavaScript sends a storefront call through Shopify's app proxy. The widget contains the storefront UI, the request performs the server-side work, and an App Block or App Embed determines where the widget loads.

Configure a request call

  1. Get the handle for the request you want to run.
  2. In the widget edit page, the Liquid field is required; you can use a simple placeholder like <div></div>.
  3. Paste the JavaScript below into the widget's JavaScript field to call the APIEase integration endpoint with fetch and read the JSON response:
const queryParams = new URLSearchParams({
requestId: 'product-details-proxy',
});

fetch('/apps/apiease/integration/caller/call?' + queryParams)
.then(function (response) {
return response.json();
})
.then(function (jsonResponse) {
console.log(jsonResponse);
});

Security warning

Never place sensitive credentials (API keys, access tokens, passwords) in a widget. Widgets are delivered to the browser and are inspectable. Configure credentials inside the APIEase request so they are stored securely and only used on the server.