Forum Discussion

Daz4's avatar
Daz4
Helper I
5 years ago
Solved

Dataflows - Web API - authentication

Hi Power BI Community!

 

I can access a particular web api via Power BI desktop, by using the URL, adding the below header and selecting Anonymous. 

 

Header = APIKEY

Value = xxxxxxxx

 

However, I cannot for the life of me work out how to connect to the same Web API using Dataflow. I cannot see anywhere to add the header, and if i tag it onto the end or the url (ie. &apikey=xxx) or whatever I try, I just get Incorrect Credentials error. 

 

I would massively appreciate any assstance on this as its doing my head in. 

 

I have been able to setup a Dataflow to another Web api, however that one uses a User name so I can configure it under Basic. The one i have issues with doesnt provide a username. 

 

Cheers!

  • If you have it working through Desktop, you can create a Dataflow from Blank Query and copy/paste your M code from the Advanced Editor in Desktop.  Have you tried that?

     

    Pat

     

7 Replies

    • Daz4's avatar
      Daz4
      Helper I

      Hey Stephen, sorry for the delayed response, but this didnt help. I cant see anywhere in the options for setting up a dataflow to put the correct api authentication, and that document seems more focused on power query. Any other ideas? As I said, I can acess other aapis fine, and can access this one via Power BI desktop, just not through Dataflows. 

      • mahoneypat's avatar
        mahoneypat
        Microsoft Employee

        If you have it working through Desktop, you can create a Dataflow from Blank Query and copy/paste your M code from the Advanced Editor in Desktop.  Have you tried that?

         

        Pat

         

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Daz4 ,


    Sorry to disturb you...


    But did I answer your question ? Please mark my reply as solution. Thank you very much.

     

    Best Regards,
    Stephen Tao

  • I believe that Daz4 was asking how to add headers to an http GET via Web.Contents.

     

    See code snippet below which shows how to encode user/password for Basic authentication.  Also demonstrates how to include multiple Headers in a Web.Contents call.

    let
      Username = "[your username]",
      Password = "[your password or TOKEN]",
      UserPass = Username & ":" & Password,
      Bytes = Text.ToBinary(UserPass),
      Base64_UserPass = Binary.ToText(Bytes, BinaryEncoding.Base64),
      TargetURL = "[target URL]",
    //TargetURL = "https://companyxyz.atlassian.net/rest/api/latest/search",
      Source = Json.Document(Web.Contents(TargetURL,
      [
         Headers = [
          #"Authorization" = "Basic " & Base64_UserPass, 
          #"Content-Type" = "application/json"
         ]
      ]
      ))
    in
      Source

      

    Once you have verified that your included Headers work... THEN you can follow mahoneypat suggestions of copying M Query from Desktop Power BI.  Again, the problem stated was related to including Headers in a Web.Contents call, as PowerApps DataFlow to Dataverse connection properties do not allow Basic (or other) Authentication methods besides Anonymous and Organization. 

     

    Note... this works great with JIRA extraction... see commented example inline.