cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Helper III
Helper III

Using Cookies in Power Query(M)

Hi Team 

 

I need some help in working with cookies. Flow is:

 

1. I will use the OAuth flow to get the access token(I'm getting it)

2. Use this token and hit our cookie url using the GET method(https://domain/CurrentAssessment/api/cookie) 

I'm getting the access_token successfully but I'm not able to use it to send it to our cookie url. I've tried a lot of different ways and researched online but haven't had any success. Please note the token method below:

 

TokenMethod = (grantType, tokenField, code) =>
let
queryString = [
client_id=client_id,
scope= Json.Document(Extension.Contents("Source.json")) [source] [scope],
grant_type="password",
response_type="token",
username=username,
password=password
],
queryWithCode = Record.AddField(queryString, tokenField, code),

tokenResponse = Web.Contents(token_uri, [
Content = Text.ToBinary(Uri.BuildQueryString(queryWithCode)),
Headers = [
#"Content-type" = "application/x-www-form-urlencoded",
#"Accept" = "application/json"
],
ManualStatusHandling = {400}
]),
body = Json.Document(tokenResponse),
result = if (Record.HasFields(body, {"error", "error_description"})) then
error Error.Record(body[error], body[error_description], body)
else
body

in
result;


I would appreciate any suggestions/help on this. Here is my powershell code which has the cookie method if it helps:

 

#Get the tenant cookie
$cookieResponse = Invoke-WebRequest -Method Get -Uri "https://$cloudUrl/CurrentAssessment/api/cookie" -Headers $requestHeaders -SessionVariable cookieSession -UseBasicParsing

$tenantCookie = $cookieSession.Cookies.GetCookies("https://$cloudUrl") | where Name -eq "CurrentAssessment"

 

12 REPLIES 12

Helpful resources

Announcements
secondImage

Happy New Year from Power BI

This is a must watch for a message from Power BI!

December Update

Check it Out!

Click here to read more about the December 2020 Updates!

Community Blog

Check it Out!

Click here to read the latest blog and learn more about contributing to the Power BI blog!

Get Ready for Power BI Dev Camp

Get Ready for Power BI Dev Camp

Mark your calendars and join us for our next Power BI Dev Camp!.