Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
7 years ago

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

  • rlemmi's avatar
    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"].

    • Neiners's avatar
      Neiners
      Helper II

      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.

  • 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...

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hello Team

       

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

      • Anonymous's avatar
        Anonymous
        Not applicable

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

  • Anonymous's avatar
    Anonymous
    Not applicable

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

  • Anonymous's avatar
    Anonymous
    Not applicable

    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.