Forum Discussion

ChrisWeeks92's avatar
ChrisWeeks92
Helper I
8 years ago

Refreshing data from REST API

Hi

 

I have a REST API setup as one of my datasets.  What is the best way to get it to schedule refreshes, say 3x a day like 8am,12pm,3pm to capture the latest data in my report.  

 

My REST API code is as follows.  Is there a line i should add to the API code or any other way that i can get this to update automatically. 

 

let    
url = "API LINK HERE", 
body = "{""Username"": ""xxxxxxxx"", ""Password"": ""xxxxxxxx"", ""CustomerID"": ""x""}",   

Source  = Json.Document(Web.Contents(url,   [ 
     Headers = [#"Content-Type"="application/json"],
     Content=Text.ToBinary(body)   
]   
)   
),
in
    #"Renamed Columns1"

4 Replies

  • v-micsh-msft's avatar
    v-micsh-msft
    Microsoft Employee

    Have you tried to follow the article below to configure Shceduled Refresh?

    Configuring scheduled refresh

     

    If yes, what is the error messages?

     

    If there are errors popped out, please share it here.

     

    The code you posted should be the connection string stored in Power BI Desktop, which belongs to the web contents, please check the article below and see if it would work in your scenario:

    Dynamic Web.Contents() and Power BI Refresh Errors

     

    Regards,

    Michael

    • ChrisWeeks92's avatar
      ChrisWeeks92
      Helper I

      Hi 

       

      Sorry for the delay, i have been busy on other projects.  

       

      I have just tried Scheduled refresh as below.  It comes back with 

       

      Failed to update data source credentials: Web.Contents failed to get contents from 'API URL' (405): Method Not AllowedHide details

       

      I do have a personal gateway setup for this as i think it mentions that it would need a personal data gateway too but it comes back with "Your data source can't be refreshed because the credentials are invalid. Please update your credentials and try again." I have tried my Microsoft ID, API username/password and my computer login details.  so any help will be much appreciated to where i am going wrong.

       

      I don't quite understand where your second article is referencing in my case, what should i add/change in my file to refresh the API without actually opening the file and refreshing the data.  

       

      Thanks

      Chris

      • aduval's avatar
        aduval
        New Member

        Did this get resolved? I am having same issue.