Click here to Skip to main content
15,884,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I am using MVC 4, I had given task in Sugar CRM. i am using RestClient to consume SugarCRM service URL.
below is code i am using for login, i excepted it Returns Session Id of user.
but it Returns service Page Text .

C#
string user_name = "xx"; string password = "xx"; /

          string[] user_auth = new string[2];

          user_auth[0] = user_name; user_auth[1] = password;


          var client = new RestClient("https://thinkebiz.us/SugarCRM/service/v2/rest.php/login?user_auth=" + user_auth );
          var req = new RestRequest();
          var response = client.Execute(req);
          var item = response.Content;


Please help me how can i call login method using RestClient ? or any Successful ways

Thank You
Posted

1 solution

Hi all,
I corrected my errors by JsonConvert the rest_data object.
below code is working fine and getting Login Session Id.

C#
string user_name = "xx"; string password = "xx";
                   var paramss = new
                   {
                       user_auth = new
                       {
                           user_name = user_name,
                           password = password,
                           encryption = "PLAIN"
                       },
                       application = "SugarCRM RestAPI Example"
                   };

                   var JsonLoginString = JsonConvert.SerializeObject(paramss);

                   var client = new RestClient("Servie URL");
                   var request = new RestRequest();
                   request.AddParameter("method", "login");
                   request.AddParameter("input_type", "JSON");
                   request.AddParameter("response_type", "JSON");
                   request.AddParameter("rest_data", JsonLoginString);

                   var response = client.Execute(request);
                   var responseData = response.Content;

                   var session = responseData.id;


Thank You
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900