Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.
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...
Solved! Go to Solution.
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
Proud to be a Super User!
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.
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
Proud to be a Super User!
I've accepted your answer as solution
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
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 ?