Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Lag_2
Regular Visitor

How to deal with reaching maximum number of calls from an API

Hello,

 

Just so you know i'm new to power BI and power query en general, so i'm not comfortably yet with working with these tools and M code. I know VBA and python so i know at least a bit programming. I got the following problem.

 

I'm using the Alpha Vantage API to get the financial data from all the stocks of the S&P index (505 in total) , i created a query as a custom fuctions that makes the call to the API, for that function i'm using the stocks symbol as it's parameter. I have a table with all the 505 stocks symbol from which i call the custom function that in turn calls the API. My problem seems to be that as power bi tries to make as many calls as fast as it can, after around 5/6 calls i get an error from the API telling me i'm overdoing the calls. 

 

The Alpha Vantage documentations suggest to make less than one call per second, how can i tell my function to wait X amount of time between calls and in case of getting an error to wait Y amount of time and to try again. This basically error handling, but M code is kind of weird so i'm a bit lost.

 

This the code generated by query:

let
    Source = Json.Document(Web.Contents("https://www.alphavantage.co/query?function=TIME_SERIES_DAILY" & "&symbol=" & Symbol & "&outputsize=compact" & "&apikey=My API Key", [Timeout=#duration(0, 0, 0, 30)])),
    #"Time Series (Daily)" = Source[#"Time Series (Daily)"],
    #"Converted to Table" = Record.ToTable(#"Time Series (Daily)"),
    #"Expanded Value" = Table.ExpandRecordColumn(#"Converted to Table", "Value", {"1. open", "2. high", "3. low", "4. close", "5. volume"}, {"Value.1. open", "Value.2. high", "Value.3. low", "Value.4. close", "Value.5. volume"}),
    #"Changed Type" = Table.TransformColumnTypes(#"Expanded Value",{{"Name", type date}}),
    #"Removed Columns" = Table.RemoveColumns(#"Changed Type",{"Value.1. open", "Value.3. low", "Value.5. volume"}),
    #"Changed Type1" = Table.TransformColumnTypes(#"Removed Columns",{{"Value.2. high", type number}, {"Value.4. close", type number}}),
    #"Renamed Columns" = Table.RenameColumns(#"Changed Type1",{{"Value.2. high", "High"}, {"Value.4. close", "Close"}, {"Name", "Date"}}),
    #"Added Custom" = Table.AddColumn(#"Renamed Columns", "Symbol", each Symbol),
    #"Reordered Columns" = Table.ReorderColumns(#"Added Custom",{"Symbol", "Date", "High", "Close"})
in
    #"Reordered Columns"

 

1 ACCEPTED SOLUTION
v-frfei-msft
Community Support
Community Support

Hi  @Lag_2,

 

Please refer to this blog to add in a wait time between API calls.

https://www.mrexcel.com/forum/power-bi/863971-wait-time-between-api-calls-power-query.html

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

View solution in original post

1 REPLY 1
v-frfei-msft
Community Support
Community Support

Hi  @Lag_2,

 

Please refer to this blog to add in a wait time between API calls.

https://www.mrexcel.com/forum/power-bi/863971-wait-time-between-api-calls-power-query.html

 

Regards,

Frank

Community Support Team _ Frank
If this post helps, then please consider Accept it as the solution to help the others find it more quickly.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.