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
AfsarP1
Helper IV
Helper IV

How to add dynamic Headers in an API call

Hi Team


I've been having some tough time with the cookies process with Power BI. I don't see any documentation that can be referred to. Just like how there is documentation for Authorization process(https://docs.microsoft.com/en-us/power-query/handlingauthentication), there should be something to work around Cookies Authentication as well. 

 

I'm trying to make an API call to our Cookies URL and sending the Bearer Token as an Authorization Header in Power BI:

 

let

Cookie = Web.Contents("https://domain/api/cookie", [Headers =[#"Authorization"= "Bearer "&Access_Token("password", "token", "code")[access_token], #"Cookie" = "set-cookie"]])

in
Cookie

 

This is asking me to specify how to connect and when I select "Edit Credentials" and use Anonymous, I get the response just as the domain. Example abc.domain.com. 

 

I've tried replicating the same in Postman by making an API call to the Cookie URL with just the Bearer token as an Authorization header and used Fiddler to monitor the traffic. 

 

Finding:

When the call is made to the Cookies URL the request headers has Cookie added automatically to it. I believe postman is doing this for me and we get a proper response. 

 

Request:

Now if I were to get this working in Power Query, first question is, is this possible and if yes how to go about it. I have tried many different things but haven't had any succcess. 

I've looked at code snippets in different languages from Postman(like Curl, PHP Curl, Swift URLSession, Java etc) and realized that it has one common thing that is adding Cookie as a Header.

How can we do this in Power Query?

 

I've tried using the Cookie as a Header in Power Query and it returns an error:

 

Expression.Error: 'Cookie' isn't a valid Web.Contents option. Valid options are: ApiKeyName, Content, ExcludedFromCacheKey, Headers, IsRetry, ManualStatusHandling, Query, RelativePath, Timeout
 
Simple Curl code snippet from PostMan:
 
curl --location --request GET 'https://domain/api/cookie' \
--header 'Authorization: Bearer eyJ0eXAiOiJKV1QiLCJ............' \
--header 'Cookie: clopeavwb-=xxxxxxxxxxxxxxxx; 
clopeavwb-agw=xxxxxxxxxxxxxxx; 
LSHttp=xxxxxxxxxxxxxxxx; 
currentAssessment=xxxxxxxxxxxxxxxx'
 
This xxxxxxxxxxx actually has values that I have removed here.
1 REPLY 1
AfsarP1
Helper IV
Helper IV

Can anyone share some information on this please. I've hit the road block and can't proceed any further until there is some information on how power query works with Cookies. It has become difficult as there is no documentation. 

Appreciate your valuable response. 

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.