Axios not working in App

Hi, I am trying to use axios in Retool App but it's not working. I have added it to the library according to documentation but I am still getting error "require not defined". This works perfectly in workflow but I need it to work in App

async function fetchShopifyOrdersLast30Days() {
console.log("Starting fetchShopifyOrdersLast30Days");

const accessToken = 'shpat_c********************';

const today = new Date();
today.setHours(0, 0, 0, 0); // Set time to midnight
const thirtyDaysAgo = new Date(today - 30 * 24 * 60 * 60 * 1000).toISOString();
let baseUrl = https:///{store}.myshopify.com/admin/api/2023-07/orders.json?status=any&created_at_min=${thirtyDaysAgo};

console.log("Base URL:", baseUrl);

let orders = [];
let nextPageUrl = baseUrl;

while (nextPageUrl) {
console.log("Fetching:", nextPageUrl);

try {
  const response = await axios.get(nextPageUrl, {
    headers: {
      'X-Shopify-Access-Token': accessToken
    }
  });
  console.log("Response:", response.data);

  if (response.data && response.data.orders) {
    orders = orders.concat(response.data.orders);
  } else {
    console.log("No orders in this batch:", response.data);
  }

  const linkHeader = response.headers.link;
  console.log("Link header:", linkHeader);
  nextPageUrl = getNextPageUrl(linkHeader);
  console.log("Next page URL:", nextPageUrl);

} catch (error) {
  console.error("Error fetching orders:", error);
  break;
}

}

if (orders.length === 0) {
console.log("No orders fetched.");
return [];
}

const result = orders.map(order => ({ name: order.name, created_at: order.created_at }));
console.log("Result:", result);

return result;
}

function getNextPageUrl(linkHeader) {
console.log("Processing linkHeader:", linkHeader);

if (!linkHeader || !linkHeader.includes('rel="next"')) {
console.log("No next page link found");
return null;
}

const nextPageUrlMatch = linkHeader.match(/<([^>]+)>;\s*rel="next"/);
if (nextPageUrlMatch && nextPageUrlMatch[1]) {
console.log("Found next page URL:", nextPageUrlMatch[1]);
return nextPageUrlMatch[1];
}
console.log("No match for next page URL in linkHeader");
return null;
}

return fetchShopifyOrdersLast30Days();

Hey @Omotoke_Okeyemi this is similar to this thread - you can't use require in apps, so if you want to use axios you'd need to pull it from somewhere like here and then use the name the library generates when you import it.

I'd be curious to know why you need to use axios specifically! REST queries are definitely recommended, and if those don't work for some reason then the fetch API is accessible in apps. I might be missing something, but i'd probably suggest rewriting your script with a combination of JS and awaited REST query triggers :thinking: