Wait time between API calls with Power Query

Kazlik

Board Regular
Joined
Dec 9, 2014
Messages
68
I have the following function I pass many URL's to doing this #"Added Custom" = Table.AddColumn(#"First Row as Header", "Custom", each SharedCount ()), I would like to add in a wait ...l="&URL&"")) in Source in GetCounts
 

Excel Facts

Pivot Table Drill Down
Double-click any number in a pivot table to create a new report showing all detail rows that make up that number
Try this:

Code:
let
GetCounts = (URL as text)=>
let
    //Define Wait function
    Wait = (seconds as number, action as function) => 
            if (List.Count(
             List.Generate(
              () => DateTimeZone.LocalNow() + #duration(0,0,0,seconds), 
              (x) => DateTimeZone.LocalNow() < x, 
              (x) => x)
              ) = 0) 
               then null else action(),
    //Pause x seconds between calls
    Pause = Wait(.25,DateTime.LocalNow),

    //Request data from URL
    Source = Json.Document(Web.Contents("https://free.sharedcount.com/url?apikey=myapikey&url="&URL&""))
in
Source
in
GetCounts
 
Upvote 0
Function.InvokeAfter() should work too. Can you try the following please?



Code:
(URL as text)=> 
Function.InvokeAfter(
()=>Json.Document(Web.Contents("https://free.sharedcount.com/url?apikey=myapikey&url="&URL&"")),
#duration(0,0,0,2))

Chris
 
Upvote 0
Thank you Chris and Ken for all your help with this problem. Both implementations worked and now I have a wait time between my API calls.
 
Upvote 0

Forum statistics

Threads
1,215,227
Messages
6,123,738
Members
449,116
Latest member
alexlomt

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top