Skip to main content

Pardot API returns a next page token when number of items in response is bigger than the limit. I was looking for a way to iterate responses in a way that will use the new “next page token” on each loop iteration.

The solution: calculated delay, delay, retrieve token, api call, store token.

This is how i did it.

Before the loop:

  1. Run first iteration of api call and actions after.
  2. Store the refresh token in storage

The way i resolved it is by using delay, storage and some math.

  1. loop iteration through the max amount of iterations need, you can calculate it if you have access to the db.
  2. Calculate with formatter how much the delay should be (how much one request takes + a bit more). i had to slow it down to 5 iterations per minute.
  3. Retrieve the token stored
  4. At this point i added a filter to make sure i got the value and right after removed the value in order to make sure i don’t repeat the same iteration twice. this caused me to slow the delay to 4 per minute.
  5. Delay action by the part of the minute needed calculated in #2
  6. call api with the refresh token
  7. store the new refresh token 
  8. Perform the actions you wanted to do with the data.

This should work, i ran into some max data retrieval limits but im able to control the date i want to start with so easy to run again.