I am trying to create a C# function which will allow a user to reply to a ticket but i gt a 401 Unauthorised error. Could anyopne help please. the code I have is:
public static void ReplyToTicket(long ticketId)
{
string json = "{\"priority\" : 1,\"status\" : 2, \"body_text\" : \"ABCDEFGHI\" }";
byteb] byteArray = Encoding.UTF8.GetBytes(json);
HttpWebRequest request = HttpWebRequest)WebRequest.Create(APIPATH + ticketId.ToString() + "/reply");
request.ContentType = "application/json";
request.Method = Ticket.GetHttpRequestMethod(requestMethod);
request.ContentLength = contentLength;
string credentials = Convert.ToBase64String(Encoding.Default.GetBytes(USERNAME + ":" PASSWORD));
HttpWebRequest request = GetHttpWebRequest(HttpRequestMethod.Post, json.Length, ticketId, true);
request.ContentType = "application/json";
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();
}
catch (WebException ex)
{
//error handling
}
catch (Exception ex)
{
//error handling
}
}