Need to develop a C# application to create new RT tickets, but the example code for c# on REST - Request Tracker Wiki is not working.
I have found information from different places but none of them really have example on how to create a new rt ticket by using C# HttpClient.
Here is my attempt:
private static async void HTTP_Create()
{
HttpClient client = new HttpClient();
client.BaseAddress = new Uri(baseURL);
string ticketUri = string.Format("REST/1.0/ticket/new?user={0}&pass={1}", testUser.UserName, testUser.Password);
// Doesn't work
var TicketDataContent = new List<KeyValuePair<string, string>>();
TicketDataContent.Add(new KeyValuePair<string, string>("id", "ticket/new"));
TicketDataContent.Add(new KeyValuePair<string, string>("Queue", "queue name"));
TicketDataContent.Add(new KeyValuePair<string, string>("Requestor", "name@email.com"));
TicketDataContent.Add(new KeyValuePair<string, string>("Owner", "owner@email.com)"));
TicketDataContent.Add(new KeyValuePair<string, string>("Subject", "Created by C#"));
TicketDataContent.Add(new KeyValuePair<string, string>("Text", "Ticket body with messages related to this ticket"));
var ticketContent = new MultipartFormDataContent();
ticketContent.Add(new FormUrlEncodedContent(TicketDataContent), "content");
var response = await client.PostAsync(baseURL + ticketUri, ticketContent);
Console.WriteLine("Response StatusCode: " + response.StatusCode.ToString());
var retContent = response.Content;
var retMsg = await response.Content.ReadAsStringAsync();
Console.WriteLine(retMsg);
}
I got the following response:
Response StatusCode: OK
RT/4.4.2 200 Ok
# Required: id, Queue
Any help is appreciated. Thanks!