Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
6 years ago
Solved

REST API with a date variable not refreshing in PBI Service

I have created a connection to an API to show in my visual.  The following works in Desktop and I can refresh the dataset in Service.

 

 

 

let

    Source = Json.Document(Web.Contents("https://devhrba.xxxxxx.com/api/xxxxxxx/GetRecalculatedValues?day=16/04/2020", [Headers=[Authorization="Bearer xxxxxxxxxxxxxxxxx"]]))
in
    Source

 

 

 

I changed the code to make the date a variable to:

 

 

 

let
   Date = DateTime.ToText((DateTime.LocalNow()), "dd/MM/yyyy"),
   actualUrl = "https://devhrba.xxxxxx.com/api/xxxxxxx/GetRecalculatedValues?day=" & Date & "",
   options = [Headers=[Authorization="Bearer xxxxxxxxxxxxxxxxx"]],
   result = Web.Contents(actualUrl, options),
    #"Imported JSON1" = Json.Document(result,65001)
in
    #"Imported JSON1"

 

 

 

This works in Desktop, but in service the refresh now fails with: 

Data source error:Unable to refresh the model (id=10766460) because it references an unsupported data source.

 

 
  • Hi, Anonymous 

     

    I'd like to suggest you modify the codes in advanced editor as below to see if it helps.

     

    let
       Date = DateTime.ToText((DateTime.LocalNow()), "dd/MM/yyyy"),
       actualUrl = "https://devhrba.xxxxxx.com/api/xxxxxxx",
       URLRelativePath = "/GetRecalculatedValues?day=" & Date & "",
       options = [Headers=[Authorization="Bearer xxxxxxxxxxxxxxxxx"],RelativePath = URLRelativePath],
       result = Web.Contents(actualUrl, options),
        #"Imported JSON1" = Json.Document(result,65001)
    in
        #"Imported JSON1"

     

     

    For further information, you may refer the document .

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

1 Reply

  • v-alq-msft's avatar
    v-alq-msft
    Community Support

    Hi, Anonymous 

     

    I'd like to suggest you modify the codes in advanced editor as below to see if it helps.

     

    let
       Date = DateTime.ToText((DateTime.LocalNow()), "dd/MM/yyyy"),
       actualUrl = "https://devhrba.xxxxxx.com/api/xxxxxxx",
       URLRelativePath = "/GetRecalculatedValues?day=" & Date & "",
       options = [Headers=[Authorization="Bearer xxxxxxxxxxxxxxxxx"],RelativePath = URLRelativePath],
       result = Web.Contents(actualUrl, options),
        #"Imported JSON1" = Json.Document(result,65001)
    in
        #"Imported JSON1"

     

     

    For further information, you may refer the document .

     

    Best Regards

    Allan

     

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.