Skip to main content
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.

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) =>

        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.

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:

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.

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. 

Helper IV
Helper IV

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

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:

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.


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

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. 




cookie never arrives at the api...




Helpful resources

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


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.