Forum Discussion

MyThumbsClick's avatar
MyThumbsClick
Helper II
2 years ago
Solved

API auth - Use parameter instead of Data Source Setting GUI

Hi All

Very new to Power BI but slowly figuring things out. I have a json API source that currently uses a web source and Basic authentication via the Data Source GUI. This works great. 

 

Username: <API Key>

Password: Blank

 

I would like to set the API key as a parameter and reference it in a query instead of using the GUI - Something like below (with FreshserviceAuthHeader as the parameter):

 

 

(PageNo as number) =>
    let
        Source = Json.Document(Web.Contents(FreshserviceBaseURL,
            [RelativePath="/tickets?",
            Query=[workspace_id="2", 
            page=Number.ToText(PageNo),
	    Headers=[Authorization="Basic "&FreshserviceAuthHeader]]))
    in 
        Source

 

  But this doesn't work. Is this technically possible?

 

Thanks

  • lbendlin's avatar
    lbendlin
    2 years ago

    change your data source settings to anonymous auth.

10 Replies

  • RelativePath must be only "tickets" 

     

    Usually an APIKey is part of the URL but consult the documentation of your API for the details. Spacing is important so use 

    Headers=[Authorization="Basic " & FreshserviceAuthHeader]
    • MyThumbsClick's avatar
      MyThumbsClick
      Helper II

      Thanks for your help. I went back to the API documentation and found this article detailing how to connect via powershell.

       

      Running that powershell script with the Base64 key works (and i can get data from the API).

      $credPair = "<your-freshservice-api-token>:.";
      $encodedCredentials = [System.Convert]::ToBase64String([System.Text.Encoding]::ASCII.GetBytes($credPair));
      $headers = @{ Authorization = "Basic $encodedCredentials" };
      $url = "https://<your-subdomain>.freshservice.com/api/v2/tickets/1?include=assets";
      $Response = Invoke-WebRequest -Uri $url -Method Get -Headers $headers -UseBasicParsing;
      $Response.Content;

       

      The format for the headers line matches what you suggested and what i have in my query but i get the following error:

       

      • lbendlin's avatar
        lbendlin
        Super User

        Show the definition of FreshServiceBaseURL

    • MyThumbsClick's avatar
      MyThumbsClick
      Helper II

      That was a typo in my post. Heres what it currently looks like:

      let
          Source = Json.Document(Web.Contents(FreshserviceBaseURL,
          [RelativePath="tickets",
          Headers=[Authorization="Basic " & FreshserviceAuthHeader]]))
      in
          Source

       

      • lbendlin's avatar
        lbendlin
        Super User

        change your data source settings to anonymous auth.