Skip to content

Instantly share code, notes, and snippets.

@drugoi
Created May 18, 2022 12:51
Show Gist options
  • Save drugoi/356576d7e1cdf328c5c3c13f55d5677d to your computer and use it in GitHub Desktop.
Save drugoi/356576d7e1cdf328c5c3c13f55d5677d to your computer and use it in GitHub Desktop.
const orders = [];
const fetchOrders = async (next = 1) => {
const response = await fetch(
`https://arbuz.kz/api/v1/order/list?page=${next}&limit=10`,
{
headers: {
accept: "application/json, text/plain, */*",
},
referrer: "https://arbuz.kz/ru/profile",
referrerPolicy: "strict-origin-when-cross-origin",
body: null,
method: "GET",
mode: "cors",
credentials: "include",
}
);
const responseJson = await response.json();
orders.push(...responseJson.data);
if (
responseJson.page.next &&
responseJson.page.next !== responseJson.page.current
) {
fetchOrders(responseJson.page.next);
} else {
console.log(
orders.reduce((sum, order) => {
return sum + order.amount;
}, 0)
);
}
};
fetchOrders();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment