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

July 7 - July 17 | Round 2 of the Power BI Dataviz World Championships. Don't miss your chance! Learn more

Reply
Anonymous
Not applicable

Using Cookies Headers

Hi Team 

 

Based on the suggestion from one of our community members, I was trying cookies as Headers to see if it works. I was trying in PowerBI Desktop but it didn't work as the result for Headers was NULL. Then, I tried this in Visual Studio this morning and struck at a point. Maybe you can help. Here is my code:

 

Cookies.Feed = () =>

let
Source = Web.Contents(Uri.Combine("https://abc.123.com", "/api/cookie"), [Headers =[#"Authorization"= "Bearer "&TokenMethod("password", "token", "code")[access_token]]]),
Source_Headers = Value.Metadata(Source)[Headers],
Auth_Cookie_Header = Source_Headers[#"Set-Cookie"]
in
Auth_Cookie_Header;

 

In this code above, TokenMethod is a function that gets me the access_token.

 

My code is big, so sharing what is relevant here. I want to use cookies along with the access_token as HEADERS in this function below:

 

System.Feed = (url as text) =>
let
source = Web.Contents(url, [Headers = DefaultRequestHeaders]),
json = Json.Document(source),

in 

Json;

 

I've defined DefaultRequestHeaders as mentioned below:

 

DefaultRequestHeaders = [

#"Authorization"= "Bearer "&TokenMethod("password", "token", "code")[access_token],
#"Cookie"=Cookies.Feed()[Auth_Cookie_Header]
];

 

When I try this, it returns an error stating "We cannot apply field access to the type text". I think its not the right way for me to define DefaultRequestHeaders and use it in my System.Feed function as Headers. 

 

Could you please help me correct the way it has to be defined. If someone has handled this in their connector, I would appreciate if you could share an example. 

3 REPLIES 3
lbendlin
Super User
Super User

Use the "Diagnose step" feature in Power Query to see the network traffic, or use Fiddler.

Anonymous
Not applicable

@lbendlin I've tried that but it says the credentials provided for the source are invalid. Although, I see the token response successfully. Is there a way to see what is actually returned in the Cookies, that is not being accepted as proper credentials? It is from this function:

 

Cookies.Feed = () =>

let
Source = Web.Contents(Uri.Combine("https://abc.123.com", "/api/cookie"), [Headers =[#"Authorization"= "Bearer "&TokenMethod("password", "token", "code")[access_token]]]),
Source_Headers = Value.Metadata(Source)[Headers],
Auth_Cookie_Header = Source_Headers[#"Set-Cookie"]
in
Auth_Cookie_Header;

lbendlin
Super User
Super User

DefaultRequestHeaders = [

"Authorization"= "Bearer "&TokenMethod("password", "token", "code"),

"Cookie"=Cookies.Feed()
];

Helpful resources

Announcements
FabCon and SQLCon Barcelona 2026

FabCon & SQLCon – Barcelona 2026

Join us in Barcelona for FabCon and SQLCon, the Fabric, Power BI, SQL, and AI community event. Save €200 with code FABCMTY200.

60 days of Data Days Carousel

Data Days 2026

Join Data Days 2026: 60 days of free live/on-demand sessions, challenges, study groups, and certification opportunities.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.