/// <summary> /// Updates a ticket by using the Patch method. /// </summary> /// <param name="appId">The Application ID that the ticket is in.</param> /// <param name="id">The id of the ticket to Patch.</param> /// <param name="content">The content to patch in the ticket. See https://api.teamdynamix.com/TDWebApi/Home/AboutPatching for more details.</param> /// <param name="notify">Whether to notify the person responsible.</param> /// <returns>The updated Ticket.</returns> public TeamDynamix.Api.Tickets.Ticket PatchTicketSync(int appId, int id, TeamDynamix.Api.JsonPatchOperation[] content, bool notify = false) { // declare the method var method = new HttpMethod("PATCH"); // convert to JSON var json = JsonConvert.SerializeObject(content); // format it into an HttpContent var iContent = new StringContent(json, Encoding.UTF8, "application/json"); // mix it all together var message = new HttpRequestMessage(method, baseURI + appId + "/tickets/" + id + "?notifyNewResponsible=" + notify) { Content = iContent }; // send it off response = client.SendAsync(message).Result; string sResponse = response.Content.ReadAsStringAsync().Result; if (!response.IsSuccessStatusCode) { Console.WriteLine("ERROR: " + response.ReasonPhrase); return(null); } TeamDynamix.Api.Tickets.Ticket tTicket = JsonConvert.DeserializeObject <TeamDynamix.Api.Tickets.Ticket>(sResponse); // convert response to ticket return(tTicket); }
/// <summary> /// Creates a ticket. /// </summary> /// <param name="appId">The Application ID that the ticket is in.</param> /// <param name="ticket">The ticket to create in TD.</param> /// <param name="options">OPTIONAL: Any options that should be included with the ticket.</param> /// <returns>The created Ticket</returns> public TeamDynamix.Api.Tickets.Ticket CreateTicketSync(int appId, TeamDynamix.Api.Tickets.Ticket ticket, TeamDynamix.Api.Tickets.TicketCreateOptions options = null) { var newOptions = new TeamDynamix.Api.Tickets.TicketCreateOptions { EnableNotifyReviewer = false, NotifyRequestor = false, NotifyResponsible = false, AllowRequestorCreation = false }; options ??= newOptions; // a way to get around complie time constant arguments // convert to JSON var json = JsonConvert.SerializeObject(ticket); // convert to HttpContent, but more specifically StringContent var sTicket = new StringContent(json, Encoding.UTF8, "application/json"); // make the request response = client.PostAsync(appId + "/tickets/?EnableNotifyReviewer=" + options.EnableNotifyReviewer + "&NotifyRequestor=" + options.NotifyRequestor + "&NotifyResponsible=" + options.NotifyResponsible + "&AllowRequestorCreation=" + options.AllowRequestorCreation, sTicket).Result; string sResponse = response.Content.ReadAsStringAsync().Result; if (!response.IsSuccessStatusCode) { Console.WriteLine("ERROR: " + response.ReasonPhrase); return(null); } var tTicket = JsonConvert.DeserializeObject <TeamDynamix.Api.Tickets.Ticket>(sResponse); // convert response to ticket return(tTicket); }
/// <summary> /// Updates a ticket by using the Post method. /// </summary> /// <param name="appId">The Application ID that the ticket is in.</param> /// <param name="ticket">The Ticket to Post.</param> /// <param name="notify">Whether to notify the person responsible.</param> /// <returns>The updated Ticket.</returns> public TeamDynamix.Api.Tickets.Ticket PostTicketSync(int appId, TeamDynamix.Api.Tickets.Ticket ticket, bool notify = false) { // convert to JSON var json = JsonConvert.SerializeObject(ticket); // convert to HttpContent, but more specifically StringContent var sTicket = new StringContent(json, Encoding.UTF8, "application/json"); // make the request response = client.PostAsync(appId + "/tickets/" + ticket.ID + "?notifyNewResponsible=" + notify, sTicket).Result; string sResponse = response.Content.ReadAsStringAsync().Result; if (!response.IsSuccessStatusCode) { Console.WriteLine("ERROR: " + response.ReasonPhrase); return(null); } var tTicket = JsonConvert.DeserializeObject <TeamDynamix.Api.Tickets.Ticket>(sResponse); // convert response to ticket return(tTicket); }