Forum Discussion

Yash48's avatar
Yash48
Frequent Visitor
4 years ago
Solved

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.

 

 

  • 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.

7 Replies

  • "But I am not able to apply data refresh"

     

    Please elaborate. What error message did you get?

    • Yash48's avatar
      Yash48
      Frequent Visitor

      Hi lbendlin,

       

      I am getting the below error message.

       

       

      Thank you,

      Yash

       

      • lbendlin's avatar
        lbendlin
        Super User

        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.