How to get the JSESSION cookie in ASP.net,C#,MVC

Hi,

I’m trying to add a user into the group using the rest-sharp API but I’m not able to get the JSESSION cookie which I need to post the data. From postman it is getting added automatically but how to get it in code behind in ASP.net .

Thanks in advance

Are you using our .NET management SDK or are you making API calls to the /groups/{{groupId}}/users/{{userId}} to add them to the group? You should only need an SSWS or OAuth token (issued to an admin with adequate permissions) to make this API call

Hi,

Actually I’m trying to add a user to a group using the RestSharp API but to add a user I need JSESSIONID the following code I’m using from POSTMAN and it was working fine in localhost but in server I’m not getting the JSESSIONID, Below is the code what I’m using.

var client = new RestClient(“https://mydomain.com/api/v1/users?activate=false”)
{
Timeout = -1
};

            var request = new RestRequest(Method.POST);
            request.AddHeader("Accept", "application/json");
            request.AddHeader("Content-Type", "application/json");
            request.AddHeader("Authorization", "mytoken");
          

            ArrayList lst = new ArrayList
            {
                "groupid"
            };

            tst r = new tst
            {
                groupIds = lst,

                profile = new tst.profile1
                {
                    firstName = "test",
                    lastName = "test",
                    email = "test@user.com",
                    login = "test@user.com"
                }
            };

            var str = JsonConvert.SerializeObject(r);

            request.AddParameter("application/json", str, ParameterType.RequestBody);

            var response = client.Execute(request);

client.CookieContainer = new System.Net.CookieContainer();
var authCookie = response.Cookies.First(a => a.Name == “JSESSIONID”);

            request.AddHeader("Cookie", "JSESSIONID=" + authCookie.Value);

Thanks,

Hi,

Can you please show me a POST example if possible in c#

Thanks

Hi @andreaskouras ,

Thanks for your time but I have solved it by adding a proxy.

Thanks,

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.