public void CreateDeleteTicketAttachment() { DepartmentCollection depts = TestSetup.KayakoApiService.Departments.GetDepartments(); StaffUserCollection staff = TestSetup.KayakoApiService.Staff.GetStaffUsers(); StaffUser randomStaffUser = staff[new Random().Next(staff.Count)]; TicketCollection tickets = TestSetup.KayakoApiService.Tickets.GetTickets(depts.Select(d => d.Id).ToArray()); Ticket randomTicket = tickets[new Random().Next(tickets.Count)]; TicketPostCollection ticketPosts = TestSetup.KayakoApiService.Tickets.GetTicketPosts(randomTicket.Id); TicketPost randomPost = ticketPosts[new Random().Next(ticketPosts.Count)]; string contents = Convert.ToBase64String(Encoding.UTF8.GetBytes("This is the file contents")); TicketAttachmentRequest request = new TicketAttachmentRequest() { TicketId = randomTicket.Id, TicketPostId = randomPost.Id, FileName = "TheFilename.txt", Contents = contents }; TicketAttachment createdAttachment = TestSetup.KayakoApiService.Tickets.AddTicketAttachment(request); Assert.AreEqual(createdAttachment.TicketId, randomTicket.Id); Assert.AreEqual(createdAttachment.TicketPostId, randomPost.Id); Assert.AreEqual(createdAttachment.FileName, "TheFilename.txt"); //Assert.AreEqual(createdAttachment.Contents, contents); bool success = TestSetup.KayakoApiService.Tickets.DeleteTicketAttachment(randomTicket.Id, createdAttachment.Id); Assert.IsTrue(success); }
/// <summary> /// Retrieve a list of all the ticket posts that belong to a ticket given ticket's id. /// </summary> /// <param name="ticketId">The unique numeric identifier of the ticket.</param> /// <returns>TicketPosts</returns> public TicketPostCollection GetTicketPosts(int ticketId) { string apiMethod = String.Format("/Tickets/TicketPost/ListAll/{0}", ticketId); TicketPostCollection posts = Connector.ExecuteGet <TicketPostCollection>(apiMethod); return(posts); }
public void GetAllTicketPosts() { DepartmentCollection depts = TestSetup.KayakoApiService.Departments.GetDepartments(); TicketCollection tickets = TestSetup.KayakoApiService.Tickets.GetTickets(depts.Select(d => d.Id).ToArray()); Ticket randomTicket = tickets[new Random().Next(tickets.Count)]; TicketPostCollection ticketPosts = TestSetup.KayakoApiService.Tickets.GetTicketPosts(randomTicket.Id); Assert.IsNotNull(ticketPosts, "No ticket posts were returned for ticket id " + randomTicket.Id); Assert.IsNotEmpty(ticketPosts, "No ticket posts were returned for ticket id " + randomTicket.Id); }
/// <summary> /// Retrieve the post identified by <paramref name="postId"/> that belong to the ticket identified by <paramref name="ticketId"/>. /// </summary> /// <param name="ticketId">The unique numeric identifier of the ticket.</param> /// <param name="postId">The unique numeric identifier of the ticket post.</param> /// <returns>The ticket post</returns> public TicketPost GetTicketPost(int ticketId, int postId) { string apiMethod = String.Format("/Tickets/TicketPost/{0}/{1}", ticketId, postId); TicketPostCollection posts = Connector.ExecuteGet <TicketPostCollection>(apiMethod); if (posts.Count > 0) { return(posts[0]); } return(null); }
/// <summary> /// Add a new post to an existing ticket.. Only <paramref name="userid"/> or <paramref name="staffid"/> should be set. /// <remarks> /// See - http://wiki.kayako.com/display/DEV/REST+-+TicketPost#REST-TicketPost-POST%2FTickets%2FTicketPost /// </remarks> /// </summary> /// <param name="ticketid">The unique numeric identifier of the ticket</param> /// <param name="subject">The ticket post subject.</param> /// <param name="contents">The ticket post contents</param> /// <param name="userid">The User Id, if the ticket post is to be created as a user</param> /// <param name="staffid">The Staff Id, if the ticket post is to be created as a staff.</param> /// <returns></returns> public TicketPost AddTicketPost(TicketPostRequest request) { string apiMethod = "/Tickets/TicketPost"; request.EnsureValidData(RequestTypes.Create); RequestBodyBuilder parameters = new RequestBodyBuilder(); parameters.AppendRequestData("ticketid", request.TicketId); parameters.AppendRequestData("subject", request.Subject); parameters.AppendRequestData("contents", request.Contents); if (request.UserId == null && request.StaffId == null) { throw new ArgumentException("Neither UserId nor StaffId are set, one of these fields are required field and cannot be null."); } if (request.UserId != null && request.StaffId != null) { throw new ArgumentException("UserId are StaffId are both set, only one of these fields must be set."); } if (request.UserId != null) { parameters.AppendRequestData("userid", request.UserId.Value); } if (request.StaffId != null) { parameters.AppendRequestData("staffid", request.StaffId.Value); if (request.IsPrivate != null) { parameters.AppendRequestDataBool("isprivate", request.IsPrivate.Value); } } TicketPostCollection posts = Connector.ExecutePost <TicketPostCollection>(apiMethod, parameters.ToString()); if (posts.Count > 0) { return(posts[0]); } return(null); }
public void GetTicketPost() { DepartmentCollection depts = TestSetup.KayakoApiService.Departments.GetDepartments(); TicketCollection tickets = TestSetup.KayakoApiService.Tickets.GetTickets(depts.Select(d => d.Id).ToArray()); Ticket randomTicket = tickets[new Random().Next(tickets.Count)]; TicketPostCollection ticketPosts = TestSetup.KayakoApiService.Tickets.GetTicketPosts(randomTicket.Id); Assert.IsNotNull(ticketPosts, "No ticket posts were returned for ticket id " + randomTicket.Id); Assert.IsNotEmpty(ticketPosts, "No ticket posts were returned for ticket id " + randomTicket.Id); TicketPost randomTicketPostToGet = ticketPosts[new Random().Next(ticketPosts.Count)]; Trace.WriteLine("GetTicketPost using ticket post id: " + randomTicketPostToGet.Id); TicketPost ticketPriority = TestSetup.KayakoApiService.Tickets.GetTicketPost(randomTicket.Id, randomTicketPostToGet.Id); CompareTicketPost(ticketPriority, randomTicketPostToGet); }