Skip to content

Instantly share code, notes, and snippets.

@gbrits
Created December 9, 2018 11:34
Show Gist options
  • Save gbrits/7cb07d890faf7faa8468c5a003899bbc to your computer and use it in GitHub Desktop.
Save gbrits/7cb07d890faf7faa8468c5a003899bbc to your computer and use it in GitHub Desktop.
How to retrieve from an API sequentially via AXIOS. Open to improvement.
function retrievePagesSequentially() {
var index = 1;
function request() {
return window.axios.get(`/api/cache/${index}`).then((response) => {
let dataSet = response.data.length;
jQuery('#headerTop').text(`${((index - 1) * 250) + dataSet} Orders`);
ShopifyApp.flashNotice(`Page ${index} retrieved...`);
index++;
if (dataSet < 250) {
setTimeout(() => {
ShopifyApp.Bar.loadingOff();
ShopifyApp.flashNotice('All orders retrieved successfully!');
location.reload();
}, 1000);
return 'done'
}
return request();
});
}
return request();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment