Discussing APIs and development related to customers, discounts, and order management.
I'm working on an extension that exports orders into a CSV file.
Currently, I'm having an issue with how 'since_id' is working because I need to be able to retrieve X orders since the very first one (#1001) but that's not possible since there's no order #1000 thus I can only get all the orders after #1001, but in that case #1001 will not be included in the CSV file.
Any suggestions?
Solved! Go to the solution
This is an accepted solution.
Hi,
Hmm, a simple solution for your workflow can be something like this:
This is an accepted solution.
Hi,
Hmm, a simple solution for your workflow can be something like this:
Thanks, I was trying to take a similar approach to what you've suggested without luck before.
Was trying to make it work this way again but still, it only exports 1002-1005 even though I concat the arrays and my final array has order #1001 added to the end.
Here's some code:
setTimeout(function() {
var url = formatUrl(orderId, page, limit);
$.get(url).then(function(response) {
var orders = response.orders;
if (orders.length) {
allOrders = allOrders.concat(orders);
if (including_first === 1) {
var url_first = formatUrlForFirstOrder(orderId);
$.get(url_first).then(function (response) {
var first_order = response.order;
allOrders = allOrders.concat(first_order);
console.log(JSON.stringify(allOrders)); // console.log the final array to see if it was successfully combined
});
}
if (
allOrders.length <= limit
) {
exportCSV(allOrders, filters);
}
});
}, 100);
}
Any ideas?
Edit: It took a few seconds to build that new array, and it didn't work because I was sending the old array before the new one was formed.
It works now after adding setTimeout.
Thanks.