Skip to main content
Solved

How to loop an HTML Caller

  • June 15, 2023
  • 15 replies
  • 487 views

navid.fotovaty
Contributor
Forum|alt.badge.img+3

Hey everyone,

I have an API that hold historical data. I would need to retrieve all the data for the past year. I am using a HTTP Caller to retrieve data.

The API only allows for 30 days for one location to be retrieved at once.

I have 36 locations, and about 15 months worth of data to retrieve.

I already have workbench that retrieve one month for one location worth of data.

How can I create a loop that would go through all these locations and date list automatically?

Best answer by nielsgerrits

For each location:

  • Calculate number of days from date start and date end. AttributeCreator, @DateTimeDiff()
  • Then divide number of days by 30, the max you are allowed to request. This is the number of questions you need to as for one location. AttributeCreator, @Evaluate() Days / 30.
  • Then clone the feature the number you find in the previous step. Cloner, numder
  • Then calculate the start time and end time for each question from clone number, start date and number of days to ask in one step (30).

Attached sample workspace demonstrating this.

 

This post is closed to further activity.
It may be an old question, an answered question, an implemented idea, or a notification-only post.
Please check post dates before relying on any information in a question or answer.
For follow-up or related questions, please post a new question or idea.
If there is a genuine update to be made, please contact us and request that the post is reopened.

15 replies

nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2940 replies
  • June 16, 2023

Multiple ways to solve this:

  • Pre create all needed requests.
    • Calculate number of days based on startdate and enddate using @DateTimeDiff()
    • Create a feature for every 30 days using a Cloner and the number of days.
    • Feed all features to the HTTPCaller.
  • Create a custom transformer with a loop.

 

As a custom transformer has its limitations and is more difficult to build, pre creating the requests is the preferred route.


david_r
Celebrity
  • 8394 replies
  • June 16, 2023

navid.fotovaty
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 16 replies
  • June 16, 2023

Hi David,

Thank you, but I have seen those already and unfortunately they are not helping in my case as far as i could see.

I can only pass one location id and one date range each time. I cant see a way for the loop to input new variable on each iteration.


navid.fotovaty
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 16 replies
  • June 16, 2023

Multiple ways to solve this:

  • Pre create all needed requests.
    • Calculate number of days based on startdate and enddate using @DateTimeDiff()
    • Create a feature for every 30 days using a Cloner and the number of days.
    • Feed all features to the HTTPCaller.
  • Create a custom transformer with a loop.

 

As a custom transformer has its limitations and is more difficult to build, pre creating the requests is the preferred route.

Hello there,

the HTTPCaller can only accept one location ID and one date range.

I came up with a similar idea to yours before reading your post, please see below:

imageI was going to create a separate HTTPCaller for each location and then find a way to loop through the dates.

Could you clarify on on using the @dateTimeDiff() can help me here? How Would that help with the iteration? Or I need to create 432 features? There are 36 locations and each has at least 12 months worth of data.


david_r
Celebrity
  • 8394 replies
  • June 16, 2023

Hi David,

Thank you, but I have seen those already and unfortunately they are not helping in my case as far as i could see.

I can only pass one location id and one date range each time. I cant see a way for the loop to input new variable on each iteration.

If we can assume that you know exactly how many http calls to make (36 * 15), then you could e.g. use two Cloners in series, the first one to make 36 clones, then the next one to make 15 clones of those again. For example:

imageIt's then simply a matter of mapping location_no (0..35) and period_no (0..14) to whatever your API expects and pass it into a single HTTPCaller.


nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2940 replies
  • June 16, 2023

Hello there,

the HTTPCaller can only accept one location ID and one date range.

I came up with a similar idea to yours before reading your post, please see below:

imageI was going to create a separate HTTPCaller for each location and then find a way to loop through the dates.

Could you clarify on on using the @dateTimeDiff() can help me here? How Would that help with the iteration? Or I need to create 432 features? There are 36 locations and each has at least 12 months worth of data.

I think you need only one HTTPCaller, and generate features for all possible combinations. Then you can ask:

For location A, return data for day 1 to 30.

For location A, return data for day 31 to 61.

For location B, return data for day 1 to 30.

For location B, return data for day 31 to 61.

etc.

 

You can use attribute input in both the Request URL (and body if POST), so you can use one HTTPCaller for all locations combined with all date ranges. You just need to prepare all the "questions" you want to ask, and feed those in the tool that asks, the HTTPCaller.


navid.fotovaty
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 16 replies
  • June 16, 2023

Sorry guys, but am I missing something about the cloners?

imageHow would the cloners know which date range or location to produce based on the HTTPCaller above?

Have I created the caller wrong? I did consider passing the location ids and date ranges as attribute under value, but was not sure how to do that, is that what the cloners are suppose to do?


david_r
Celebrity
  • 8394 replies
  • June 16, 2023

Sorry guys, but am I missing something about the cloners?

imageHow would the cloners know which date range or location to produce based on the HTTPCaller above?

Have I created the caller wrong? I did consider passing the location ids and date ranges as attribute under value, but was not sure how to do that, is that what the cloners are suppose to do?

The following phrase was collapsed under my answer: It's then simply a matter of mapping location_no (0..35) and period_no (0..14) to whatever your API expects and pass it into a single HTTPCaller.

You can e.g. use a couple of AttributeValueMappers to e.g. map location_no 0 to 30215, etc.


nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2940 replies
  • June 16, 2023

Sorry guys, but am I missing something about the cloners?

imageHow would the cloners know which date range or location to produce based on the HTTPCaller above?

Have I created the caller wrong? I did consider passing the location ids and date ranges as attribute under value, but was not sure how to do that, is that what the cloners are suppose to do?

For each location:

  • Calculate number of days from date start and date end. AttributeCreator, @DateTimeDiff()
  • Then divide number of days by 30, the max you are allowed to request. This is the number of questions you need to as for one location. AttributeCreator, @Evaluate() Days / 30.
  • Then clone the feature the number you find in the previous step. Cloner, numder
  • Then calculate the start time and end time for each question from clone number, start date and number of days to ask in one step (30).

nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2940 replies
  • Best Answer
  • June 16, 2023

For each location:

  • Calculate number of days from date start and date end. AttributeCreator, @DateTimeDiff()
  • Then divide number of days by 30, the max you are allowed to request. This is the number of questions you need to as for one location. AttributeCreator, @Evaluate() Days / 30.
  • Then clone the feature the number you find in the previous step. Cloner, numder
  • Then calculate the start time and end time for each question from clone number, start date and number of days to ask in one step (30).

Attached sample workspace demonstrating this.

 


navid.fotovaty
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 16 replies
  • June 16, 2023

Thank you both, please allow me some time to go over the materials you provided, and get back to you.


navid.fotovaty
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 16 replies
  • June 16, 2023

For each location:

  • Calculate number of days from date start and date end. AttributeCreator, @DateTimeDiff()
  • Then divide number of days by 30, the max you are allowed to request. This is the number of questions you need to as for one location. AttributeCreator, @Evaluate() Days / 30.
  • Then clone the feature the number you find in the previous step. Cloner, numder
  • Then calculate the start time and end time for each question from clone number, start date and number of days to ask in one step (30).

Hi,

Thank you so much, I understand now. One more thing. I need to send the date to the API as datetime, at which stage should i convert the date to datetime?


david_r
Celebrity
  • 8394 replies
  • June 16, 2023

For each location:

  • Calculate number of days from date start and date end. AttributeCreator, @DateTimeDiff()
  • Then divide number of days by 30, the max you are allowed to request. This is the number of questions you need to as for one location. AttributeCreator, @Evaluate() Days / 30.
  • Then clone the feature the number you find in the previous step. Cloner, numder
  • Then calculate the start time and end time for each question from clone number, start date and number of days to ask in one step (30).

REST APIs normally don't have a notion of a datetime data type, they usually expect a string that can be reliably interpreted as a datetime, e.g. ISO 8601 or similar. So my suggestion is to use the DateTimeConverter before the HTTPCaller, but only if necessary.


navid.fotovaty
Contributor
Forum|alt.badge.img+3
  • Author
  • Contributor
  • 16 replies
  • June 16, 2023

For each location:

  • Calculate number of days from date start and date end. AttributeCreator, @DateTimeDiff()
  • Then divide number of days by 30, the max you are allowed to request. This is the number of questions you need to as for one location. AttributeCreator, @Evaluate() Days / 30.
  • Then clone the feature the number you find in the previous step. Cloner, numder
  • Then calculate the start time and end time for each question from clone number, start date and number of days to ask in one step (30).

Thank you so much both. I believe I have what I need now.


nielsgerrits
VIP
Forum|alt.badge.img+60
  • 2940 replies
  • June 16, 2023

For each location:

  • Calculate number of days from date start and date end. AttributeCreator, @DateTimeDiff()
  • Then divide number of days by 30, the max you are allowed to request. This is the number of questions you need to as for one location. AttributeCreator, @Evaluate() Days / 30.
  • Then clone the feature the number you find in the previous step. Cloner, numder
  • Then calculate the start time and end time for each question from clone number, start date and number of days to ask in one step (30).

Nice :)