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
jmclej
Helper I
Helper I

2 similar requests but one is not working

Hello,

Using Postman, I have this request (converted to C#) that I want to use in Power BI :

 

var client = new RestClient("https://myurl/docs/594354384545845");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("profile", "full-access");
request.AddHeader("enduser", "enduser");
request.AddHeader("Authorization", "Bearer XYXYXYXYXYXXYXYXYXYYXYXXYYXYX");
request.AddHeader("Cookie", "KDFHGJDISJDFDUKDFGJDFHDFO");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

 

I make this in Power BI, that works just fine :

 

= Json.Document(Web.Contents("https://myurl/docs/594354384545845", [Headers=[Authorization="Bearer "&GetToken(), #"profile"="full-access", #"enduser"="enduser"]]))

 

GetToken() is defined like this :

 

= ()=>
let
    url = "https://myurl/token",
    headers = [#"Content-Type" = "application/x-www-form-urlencoded", #"Authorization" = "Basic XYXYXYXYXYXXYXYXYXYYXYXXYYXYX"],
    postData = Text.ToBinary("grant_type=client_credentials&scope=business"),
    response = Web.Contents(url, [Headers = headers, Content = postData]),
    Data = Json.Document(response),
    access_token=Data[access_token]
in
    access_token

 

 

But when I try to add another very similar request like this from csharp in Postman :

 

var client = new RestClient("https://myurl/docs");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("profile", "full-access");
request.AddHeader("enduser", "enduser");
request.AddHeader("Authorization", "Bearer XYXYXYXYXYXYXYYXYXYXYXYX");
request.AddHeader("Cookie", "DSHGDUTSDFHFDGKDG");
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);

 

I make this in Power BI :

 

= Json.Document(Web.Contents("https://myurl/docs", [Headers=[Authorization="Bearer "&GetToken(), #"profile"="full-access", #"enduser"="enduser"]]))

 

But for an unknown reaser, I get the following error :

 

Expression.Error: The 'Authorization' header is only supported when connecting anonymously. These headers can be used with all authentication types: Accept, Accept-Charset, Accept-Encoding, Accept-Language, Cache-Control, Content-Type, If-Modified-Since, Prefer, Range, Referer

 

To be noted that if I reverse the order of the headers, then, in the error message, instead of "The 'Authorization' header", I get "The 'profile' header" or "The 'enduser' header", the message takes all the time the first header that I've set.

Do you have any idea what the issue can be please ? In Postman, it is the same code (and both requests are working), but when I use the same code in Power BI, it doesn't work...

2 ACCEPTED SOLUTIONS
PhilipTreacy
Super User
Super User

Hi @jmclej 

 

Check your data source settings.  The url's are different in each request so the 2nd one may have the method to access it set to somethign other than Anonymous.

 

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!


View solution in original post

jmclej
Helper I
Helper I

I have found the answer here : https://groups.google.com/g/outbrain-amplifyapi/c/4bkjoEUptTo I needed to specifically set the authorization to Anonymous in the data source settings. I missed that because for my second call, I started from Blank Query whereas for the first one I had selected from Web page, so it gave me more sirections.

View solution in original post

5 REPLIES 5
jmclej
Helper I
Helper I

I have found the answer here : https://groups.google.com/g/outbrain-amplifyapi/c/4bkjoEUptTo I needed to specifically set the authorization to Anonymous in the data source settings. I missed that because for my second call, I started from Blank Query whereas for the first one I had selected from Web page, so it gave me more sirections.

Hi @jmclej 

 

That's what I said, check your Data source settings !  Curious why you didn't mark my response as the answer.

 

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!


I've accepted your answer as solution

PhilipTreacy
Super User
Super User

Hi @jmclej 

 

Check your data source settings.  The url's are different in each request so the 2nd one may have the method to access it set to somethign other than Anonymous.

 

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!


Hello,

Thanks for having had a look. As I have shown with Postman, the two ways of calling the 2 endpoints are similar because it generates the same c# code, so there shouldn't be a reason for the call to be different from Power BI, no ?

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