Solved

How do I create some kind of loop to retrieve all the data I need from an API?

  • 7 February 2023
  • 2 replies
  • 1 view

The request URL looks like this:

https://reportapi.application.com/dashboard?from=YYYY-MM-DD&to=YYYY-MM-DD&state=XXXXXX&api-version=1.0

 

How can I create some kind of setup (or loop) where I can easily retrieve the data from an entire year per month per state? The data itself doesn't have some kind of timestamp, so I'll have to retrieve each month separately.

So for example:

2022-01-01 till 2022-01-31 for Ohio

2022-01-01 till 2022-01-31 for Florida

2022-02-01 till 2022-02-31 for Ohio

2022-02-01 till 2022-02-31 for Florida

etc...

icon

Best answer by ebygomm 7 February 2023, 16:31

View original

2 replies

Userlevel 1
Badge +21

No need for a loop, if you have a start date for the year, you can clone a feature 12 times, then create start and end dates for each month based on the copynumber

e.g. for the start date for a month

@DateTimeAdd(@Value(startofyear),P@Value(_copynum)M)

Then for the end date you can add a month and minus a day to get the last day of the month

@DateTimeAdd(@DateTimeAdd(@Value(startdate),P1M),-P1D)

Then you should have everything needed to create your request url once you join in the state info

Thank you! That's just what I needed!

Reply