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

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
sugna66
Frequent Visitor

Need Cookie in my Rest API Custom data connector - Help please.

// This file contains your Data Connector logic
section SynDNA;

[DataSource.Kind="SynDNA", Publish="SynDNA.Publish"]
shared SynDNA.Feed = Value.ReplaceType(SynDNAImpl, type function (url as Uri.Type) as any);

SynDNAImpl = (url as text) =>

    let
        Credential = Extension.CurrentCredential(),

        CredentialConnectionString = [ UID = Credential[Username], PWD = Credential[Password] ],

       login = Record.ToTable(Json.Document(Web.Contents(url & "/api/login/" & CredentialConnectionString[UID] & "/" & CredentialConnectionString[PWD], [ Headers = DefaultRequestHeaders ]))),
       FilterLogin = Table.SelectRows(login, each _[Name] = "hash" ),
       hash = List.First(Table.Column(FilterLogin, "Value")),
       //source = Web.Contents(url & "/api/report/1/output/Reports/Angus/test_test?auth=" & hash, [ Headers = DefaultRequestHeaders ]),
       source = Web.Contents(url & "/api/reports/search?auth=" & hash & "&keyword=EXCEL", [ Headers = DefaultRequestHeaders ]),
       json = Json.Document(source)
        
        
    in json;



     DefaultRequestHeaders = [
    #"Cookie" = "userkey=1/2321bf021c4a45f23037826cd49fa5d8b619fd6d/8c836beea0263a6f95b59c3e2d6e44ccd741ce50",
    #"Accept" = "application/json;odata.metadata=minimal",  // column name and values only
    #"OData-MaxVersion" = "4.0"                             // we only support v4
];

// Data Source Kind description
SynDNA = [
    Authentication = [
        // Key = [],
         UsernamePassword = []
        // Windows = [],
       // Implicit = [],
       //   Anonymous = []
    ],
    Label = Extension.LoadString("DataSourceLabel")
];

I need a way to generate a cookie to pass to my API. In the code above has a key borrowed from making my request in Chrome. This request works in any browser and curl. But in Visual Studio it doesn't add the Cookie as part of a default request header. If I manually add the cookie from a browser request (like I have above the request works) if not I get a 403 error. Help please.

12 REPLIES 12
rlemmi
Frequent Visitor

You might want to use fiddler to inspect the HTTP requests and from there obtain the correct address where you receive the Cookie value.

In one of my custom connectors, I get my cookie value with the following:

let
Source = Web.Contents(Uri.Combine(url, "authentication-point/authenticate"), [ Headers = DefaultRequestHeaders ]),
Source_Headers = Value.Metadata(Source)[Headers],
Auth_Cookie_Header = Source_Headers[#"Set-Cookie"],

Web API returns the headers and I retrieve them using Value.Metadata(). The cookie value I need is under the [#"Set-Cookie"].

Can you explain this a little more? I'm struggling with this and I don't know if I need to build a custom connector (which I have no clue how to do). I have a login api that is using username and password as post method. Then I am to use the sessionid (#"Set-Cookie) created from that login api and pass that through the data api.

AfsarP1
Helper IV
Helper IV

Its been quite some time and I'm still trying to get information on this. I know we would go out of vacation soon or some would already be on vacation. I would appreciate any inputs before we all head out to our vacation. 

 

Wishing you all happy holidays. 

AfsarP1
Helper IV
Helper IV

Does anyone have any inputs on this. I would appreciate any response. 

AfsarP1
Helper IV
Helper IV

Did any of you get through the cookies process? I'm having a hard time working with cookies in power query. There is no information online about it and no doc that can be referred to, making it even more difficult. I see one more post where it was mentioned that the cookies were not allowed due to security reasons in past:

 

https://community.powerbi.com/t5/Developer/How-to-get-set-Cookies-inside-a-visual/m-p/347843

Hello Team

 

I'm still chasing for the information on cookies. I would appreciate any response.

how can i solve this? I also find myself in the same situation.

PQ does work with cookies. All you have to do is create a custom connector with VS.

 

Check this article from microsoft and follow their TripPin walkthrough.

TripPin tutorial sequence - Power Query | Microsoft Docs

@rlemmi This is a good news. Its been a long time since I spent time building an OAuth connector and cookies didn't work back then. Maybe I'll go through that link some time. Thanks

 

@jgarcia_new From what I've understood, Power Query doesn't work with cookies and I stopped chasing it. However, I did hear a couple of them getting through the cookies process using powershell or python inside the power query code. You may want dig more onto this option(currently this is the only option as far as I know). 

 

Thank you for responding, I was reviewing the ability to do it with python, however this script would have to run in 'Power Query Web' because that is where I am creating the 'dataset', however I could not does not exist in the data source options.
. That is why I am trying to solve it only with M Language.


jgarcia_new_0-1653326967748.png

I really don't know what else to do to get the data from that API safely.

koeppelsens
New Member

Same problem with the onpremise Conector via Logic App Custom Connector. Its not possible to pass the cookie Header Paramter to the api. 

 

#NoCookieParameterPassThroughAtCustomConnector

 

cookie never arrives at the api...

 

2019-08-20_18-50-10.jpg

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.