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
Yash48
Frequent Visitor

How to solve a schedule refresh problem for getting data from API?

Hi guys, I am using the below power query code for getting the data from an API. I am using a loop to get the data for many rows as the API can provide onpy 5000 rows for a call. But I am not able to apply data refresh. I even tried using Relative path as suggested by few people, but it's still not working. I cannot provide the API key as it is confidential. Also, keep in mind that I do not want to use personal gateway. Thank you in advance.

 

let
#"FullQuery" = let

pageSize = 5000,
sendRequest = (page) =>
let
APIKey = "test",
APIUrl = "https://api.genscape.com/",
startDate = Date.ToText(Date.AddMonths(Date.From(DateTimeZone.UtcNow()),-11),"yyyy-MM-dd"),

Response = Web.Contents(
"https://api.genscape.com/",
[
RelativePath ="storage/oil/v1/tank-volumes",
Query=
[
revision="published",
format="json",
startDate=startDate,
limit = Number.ToText(pageSize),
offset = Number.ToText(page * pageSize)
],
Headers=[#"Gen-Api-Key"= APIKey]
]),
Data = Json.Document(Response)[data]
in
Data,
Loop = (page as number, AccumData as list) =>
let
Data = Function.InvokeAfter(()=>sendRequest(page), #duration(0,0,0,2)),
Result =
if List.Count(Data) < pageSize
then Table.FromRecords(List.Combine({AccumData, Data}))
else @Loop(page + 1, List.Combine({AccumData, Data}))
in
Result
in
Loop(0, {})
in
#"FullQuery"

 

I am getting the below error when I try to schedule refresh.

 

Yash48_0-1636186242242.png

 

1 ACCEPTED SOLUTION

Sorry I hadn't read your post correctly.  What you need is a base URL that actually exists on the service.

 

https://api.genscape.com/ is not valid (the server refuses to serve that page). 

 

Select "skip test"  and ignore the error.

View solution in original post

7 REPLIES 7
lbendlin
Super User
Super User

"But I am not able to apply data refresh"

 

Please elaborate. What error message did you get?

Hi lbendlin,

 

I am getting the below error message.

 

Yash48_1-1636186118412.png

 

Thank you,

Yash

 

Sorry I hadn't read your post correctly.  What you need is a base URL that actually exists on the service.

 

https://api.genscape.com/ is not valid (the server refuses to serve that page). 

 

Select "skip test"  and ignore the error.

Can you successfully fetch a single page? The first ten records? The error message indicates that the URL is incorrect.

Yes, I can fetch a single page when I use the below way to load data instead of using query to load many pages using loop.

 

Yash48_1-1636200483695.png

 

Hi  @Yash48 ,

 

Try the measure provided by Chris to deal with 404 error from Web.Contents:

https://blog.crossjoin.co.uk/2016/08/09/handling-404-not-found-errors-with-web-contents-in-power-que...

 

Best Regards,
Kelly

Did I answer your question? Mark my reply as a solution!

Hi Kelly,

 

That article was not able to solve my problem. The api url is working fine when I use in PowerBI desktop, but not when published.

 

Thank you,

Yash

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.

Top Solution Authors
Top Kudoed Authors