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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
chrisyan_manalu
Helper II
Helper II

Get data from API

Hi All,

 

I got error while trying to get the data using web api with basic authentication. 

 

chrisyan_manalu_0-1652242522052.png

 

From the message error as I attached, is that true ?

 

Or any solution for my issue ? 

 

Please help

 

Thanks

4 REPLIES 4
chrisyan_manalu
Helper II
Helper II

Dear @PhilipTreacy 

 

Yes, Web.BrowserContents only supports anonymous connections

> Well noted. 

 

What exactly are you trying to do?

> I'm trying to get data using that API

 

If you need to provide authentication to an API you can use a different web connector and provide the auth that way

> I have been using all of these web conector in power bi like Web, OData, Web API but cannot reach the data

 

Thanks

@chrisyan_manalu 

 

have you tried adapting my code to get your API data?

 

Please post the query you are currently using (removing any username and password) so I can see how it needs to be modified to get it working.

 

Regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


PhilipTreacy
Super User
Super User

Hi @chrisyan_manalu 

 

Yes, Web.BrowserContents only supports anonymous connections.  What exactly are you trying to do?

 

If you need to provide authentication to an API you can use a different web connector and provide the auth that way.  Something like this

let
    // Get the API Token
    api_url = "https://api.paypal.com/",
    token_path = "v1/oauth2/token",
    ClientID = "xxxxxxxx",
    Secret = "xxxxxxxx",
    
    EncodedCredentials = "Basic " & Binary.ToText(Text.ToBinary(ClientID & ":" & Secret), BinaryEncoding.Base64),
    
    Token_Response  = Json.Document(Web.Contents(api_url,
    [ 
      RelativePath = token_path,
      Headers = [#"Content-Type"="application/x-www-form-urlencoded",#"Authorization"=EncodedCredentials],
      Content=Text.ToBinary("grant_type=client_credentials")
    ]
    )
    ),
in 
    Token_Response

 

Further reading which may help you

 

Getting Started with API's in Power Query • My Online Training Hub

 

Connecting to an OAuth API Like PayPal With Power Query • My Online Training Hub

 

regards

 

Phil



Did I answer your question? Then please mark my post as the solution.
If I helped you, click on the Thumbs Up to give Kudos.


Blog :: YouTube Channel :: Connect on Linkedin


Proud to be a Super User!


Hi @PhilipTreacy 

 

Sorry for late replay.

I tried to using your code to get the data, but still no get that. 

chrisyan_manalu_0-1653462366318.png

 

If you dont mind, could you help me to write correctly. Currently, this is the code like this

 

(SelectedService as text,Authentication as text) =>
let
#"BaseURL" = "My Url", //this url just masking for your demo
#"ConstantVar" = "my constant var", //this url just masking for your demo
response = Web.Contents(
#"BaseURL",
[
Headers = [Authorization= Authentication],
RelativePath = #"ConstantVar" & SelectedService
]
),
jsonResponse = Json.Document(response),
Navigation = jsonResponse[data],
#"Navigation 1" = Navigation{0},
#"Converted to table" = Record.ToTable(#"Navigation 1"),
#"Transposed table" = Table.Transpose(#"Converted to table"),
#"Promoted headers" = Table.PromoteHeaders(#"Transposed table", [PromoteAllScalars = true])
in
#"Promoted headers" 

 

Thanks



Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

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.