Forum Discussion

jwillis07's avatar
jwillis07
Icon for Advocate I rankAdvocate I
5 years ago

How to Authenticate a REST API in Power BI?

Good evening all, I'm in need of some help and I hope I've come to the right place...

 

I've only ever worked with local files or open APIs however this time, I'm trying to access a REST API but I'm currently unable to get past the authentication.

 

The API URL is... https://psa.pulseway.com/api/servicedesk/tickets

The documentation for the API can be found at... https://psa.pulseway.com/api

 

Within the documentation it says that I need to include the following header parameters...

 

Accept = application/json

Content-Type = application/x-www-form--urlencoded

grant_type = password

username = Authenticated user username value (my Pulseway username)

password = Authenticated user password value (my Pulseway password)

tenant = Authenticated user company tenant value (my Pulseway company tenant name)

 

So, in Power BI Desktop, I'm following the below steps:

 

1. Get Data > Other > Web

2. Click advanced, and enter my API URL as whole, not in parts.

3. Add in the header parameters as above, when complete, it looks like the below:

 

*I've left my credentials blank for security purposes but I fill them in before moving to the next step 

 

4. Press OK

5. I then get a failure to authenticate message as below,

 

6. As I've already included my credentials in the headers, I believe I should now just click "Anonymous" and then "Connect" - Only this doesn't work and I get the same error message again...

 

 

I have no idea what I'm doing wrong and have gotten lost in documentation to just get this far, so if anyone can point me in the right direction it'd be hugely appreciated and you might just save my job!

 

Thank you in advance,

Jason

8 Replies

  • If anyone even has any links to tutorials or anything, it would help more than you know.

    I just can't get my head around this ðŸ˜ž

    • kurrysamir's avatar
      kurrysamir
      Icon for Helper I rankHelper I

      Could you help here, in steps how did you solve it?

      • singam_santhu's avatar
        singam_santhu
        New Member

        1. Register the App. in Azure Portal

        2. Add the permissions to the App by usine API Permissions tab,

        3. Use this script for token creation

        4. For extracting reports for entire organization,

        let
        token = Access_Token(),

        headers = [
        #"Authorization" = "Bearer " & token,
        #"Content-Type" = "application/json"
        ],

        GetPage = (url as text) as record =>
        let
        response = Web.Contents(url, [Headers = headers]),
        json = Json.Document(response),
        data = json[value],
        nextLink = try Record.Field(json, "@odata.nextLink") otherwise null
        in
        [Data = data, Next = nextLink],

        GetAllPages = (url as text, acc as list) =>
        let
        page = GetPage(url),
        combined = List.Combine({acc, page[Data]}),
        result = if page[Next] <> null then @GetAllPages(page[Next], combined) else combined
        in
        result,

        // ✅ Use includeMetadata=true here
        baseUrl = "https://api.powerbi.com/v1.0/myorg/admin/reports?&includeMetadata=true",

        allData = GetAllPages(baseUrl, {}),
        Reports = Table.FromRecords(allData)
        in
        Reports

        5. chnage the api in the (baseURL) link for your requirement.

         



  • Pree's avatar
    Pree
    New Member

    Did you solve the problem? I am getting the same error. I am looking for the soluction to this problem too. 

  • v-henryk-mstf's avatar
    v-henryk-mstf
    Icon for Community Support rankCommunity Support

    Hi jwillis07 ,

     

    If you want to Authenticate a REST API in Power BI. You should first need to clear the permission in the data source setting, the choose "Web API" instead of "Anonymous", then make a try.

     

     

    Provide corresponding official documents for reference: Power Query Web connector | Microsoft Docs


    If the problem is still not resolved, please provide detailed error information and let me know immediately. Looking forward to your reply.

    Best Regards,
    Henry

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

    • BizviG's avatar
      BizviG
      New Member

      Hi v-henryk-mstf!

      I think what we are looking for is a way to pass the authentication in the header INSTEAD of the Web API Key
      If indeed that would be the method for activating auth through the header parameters in the case described, what would one write in the KEY-field? Would that be whatever was returned with the Authorization: Basic?

  • Hi Guys,

    Getting the same problem as the discussion, using a REST API with Authorisation set as Basic Auth having username/password and header including api-key, Did anyone find a solution for this? 

    Thanks in advance.