Forum Discussion

chizzle's avatar
chizzle
Regular Visitor
2 years ago
Solved

Avoiding credentials in Datamart Power Query

I am trying to pull information via API into a Datamart. I have a function in Power Query that pulls APIs using a project ID as the source requires the pull by project ID rather than all data. I have...
  • chizzle's avatar
    2 years ago

    FYI, I figured out that if you use the base URL and create a connectoin for that then use a relative path for the rest, it works itself out. Here is how the code was structured:

    let
    
            BaseUrl = "https://url/base/",
    
            StartDate = Date.ToText(Date.AddDays(Date.From(DateTime.LocalNow()), -365), "yyyy-MM-dd"),  // Current date - 365 days
    
            EndDate = Date.ToText(Date.From(DateTime.LocalNow()), "yyyy-MM-dd"),  // Current date
    
            Headers = [
    
                #"X-Auth-Token" = "xxx", 
    
                #"X-Auth-Realm" = "xxx" 
    
            ],
    
            Source = Json.Document(
                        Web.Contents(
                            BaseUrl, 
                            [
                                RelativePath="api/v2/time/ByProject/" & ProjectID, 
                                Query=[StartDt=StartDate, EndDt=EndDate, View="Detailed"], 
                                Headers=Headers
                            ]
                        )
                    )
    
        in
    
            Source