I have a database in Stripe which contains more than 100K customers. A part of customers have a metadata start
, its value is like 2024-04-05T06:58:12.386Z
.
Now, I would like to write a nodejs code to find out all the customers who have this start
field in their metadata and its value is between 2024-04-05T00:00:00
and 2024-04-05T23:59:59Z
.
It seems that we cannot even do pagination with https://docs.stripe.com/search#search-query-language. I tried the following code first, and it returned me an error Error: StripeInvalidRequestError: Received unknown parameter: starting_after
.
let allCustomers = [];
let lastCustomerId = null;
try {
while (true) {
const response = await stripe.customers.search({
query: `-metadata["start"]:null`,
limit: 100,
starting_after: lastCustomerId
});
allCustomers = allCustomers.concat(response.data);
if (!response.has_more) {
break;
}
console.log('customers found:', allCustomers.length);
lastCustomerId = response.data[response.data.length - 1].id;
}
console.log('Total customers found:', allCustomers.length);
return allCustomers;
} catch (error) {
console.error('Error:', error);
}
Does anyone know how to do that?