internal server error (500) on using API

  • 22 November 2016
  • 0 replies
  • 61 views


Hi , my code in c# is :




string fdDomain = "mycompany";


string apiKey = "x0x0x0x0x0x0x0x0x0";


string apiPath = "/helpdesk/tickets.json";


string json = "{\"status\": 2, \"priority\": 1, \"email\":\"test@test.com\",\"subject\":\"test\",\"description\":\"confirm whether received\"}";


HttpWebRequest request = (HttpWebRequest)WebRequest.Create("http://" + fdDomain + ".freshservice.com" + apiPath);


request.ContentType = "application/json";


request.Method = "POST";


byte[] byteArray = Encoding.UTF8.GetBytes(json);


request.ContentLength = byteArray.Length;


string authInfo = apiKey + ":X"; // It could be your username:password also.


authInfo = Convert.ToBase64String(Encoding.Default.GetBytes(authInfo));


request.Headers["Authorization"] = "Basic " + authInfo;



//ServicePointManager.ServerCertificateValidationCallback = new RemoteCertificateValidationCallback(ValidateServerCertificate);



Stream dataStream = request.GetRequestStream();




dataStream.Write(byteArray, 0, byteArray.Length);




dataStream.Close();


try


{


WebResponse response = request.GetResponse();




dataStream = response.GetResponseStream();




StreamReader reader = new StreamReader(dataStream);




string Response = reader.ReadToEnd();




return Json(Response);






The message erro is "Server internal erro (500)",




Thanks



This topic has been closed for comments