Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MyThumbsClick
Helper I
Helper I

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

1 ACCEPTED SOLUTION

change your data source settings to anonymous auth.

View solution in original post

10 REPLIES 10
lbendlin
Super User
Super User

no, the ) afterwards.

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

MyThumbsClick_0-1711645421839.png

 

change your data source settings to anonymous auth.

Ok, Looking at this with fresh eyes, setting to anonymous auth does do the trick. Thank you for your help!

lbendlin
Super User
Super User

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]

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:

MyThumbsClick_0-1711620558037.png

 

Show the definition of FreshServiceBaseURL

I have tested omitting the variable, instead inserting the API straight into the query like below but no dice.

Headers=[Authorization="Basic <Base64encoded APIKEY>)"]

 The value of the Parameter is: 

Basic <Base64encoded API Key>

is that extra parenthesis a typo?

are you reffering to the <> charecters? They were for illistrutive purposes and not actually in use - sorry for conufusion

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors
Top Kudoed Authors