I need to fetch 12 different nums for every object, and there are 31 different objects.
Basically, the API string ends like this:
/count?publishedAt_gte=2022-01-01&publishedAt_lte=2022-02-01&newsSite_contains=1&_limit=500
‘_contains=1′ determines the object, =2 will render the next one, =3 the one after and so forth until ‘_contains=31’
‘_gte=2022-01-01&publishedAt_lte=2022-02-01’ determines the specific num value, as changing the months (2022-01-01 becomes 2022-02-01 and 2022-02-01 becomes 03..) will return a different num.
So the function should fetch the num value from the base url, push it in a array, then raise the months numbers by 1 and repeat 12 times, to then return at the starting month to change the ‘contains’ part and raise it by 1 – all of this 31 times. So we’ll have 31 arrays, each with 12 nums.
Do you think it’s doable, and how?
>Solution :
If it runs with Node you can use the URL module. It has methods to get/set and such for the query params.
If it runs in the browser you can use the URLSearchParams web API.
Regarding implementation, you can tell me the environment this function would be invoked in and I can write something down for you.