I am looping over an array of strings and want to pass these in chunks of 30 into the axios GET request as query params but I dont know how to do it correctly.
const ids = ["1","2", "3", "4", "5"] //up to 10K entries
What I need is 30 ids as a query parameter with the same key on each request like this
axios.get("/endpoint?id=1&id=2&id=3&id=4") ecetera. My approach doesnt work and I would welcome some tips on how to approach this correctly.
what I have
const assets = await getRepository(Asset).find({ collection: collection })
const token_ids = assets.map(a => {
return a.token_id
})
const asset_count = assets.length;
let config: AxiosRequestConfig = {
headers: this.header,
params: {
limit: 50,
offset: 0,
side: 1,
sale_kind: 0,
order_by: "eth_price",
order_direction: "asc",
asset_contract_address: assets[0].asset_contract.address
}
}
while (true) {
const ids = token_ids.splice(0,30); //get 30 ids for pagination (max)
//apply ids to params
for( let i=0; i< ids.length; i++){
config.params["id"] = ids[i]; //this wont work cause duplicate keys arent allows
}
const response = await axios.get(this.API_BASE_URL + "/orders", config)
//do something
}