422 error when creating a ticket in Zendesk

user3405456 picture user3405456 · Apr 4, 2014 · Viewed 8k times · Source

I am developping an app in ASP.NET MVC5 using Zendesk_v2 (uploaded using a nuget package). I have admin rights for subdomain easynext.zendesk.com.

Here is my code for creating a ticket:

private static string requestUri = "https://easynext.zendesk.com/api/v2/tickets.json"; 
private static string _username = "[email protected]"; 
private static string _password = "MYPASSWORD"; 
private static ZendeskApi apiZendesk = new ZendeskApi(requestUri, _username, _password, "");

private void CréerTicketZendesk() { 
  var myTicket = apiZendesk.Tickets.CreateTicket(new Ticket() 
  { 
    Subject = "test ticket", 
    Priority = TicketPriorities.Low 
  });
}

This code sends me a 422 Unprocessable Entity error.

I have also made a test account for a client in Zendesk and the method works fine, the ticket is created in Zendesk and I also receive it in my email account.

Answer

Ken Verb picture Ken Verb · Dec 31, 2014

Status 422 is most likely caused by a semantic error on your part. In my experience, ZD can return 422 most often in two situations:

  1. When trying to PUT an update to a ticket whose status is closed. In that case, you need to create a new ticket or a follow-up ticket, if possible.
  2. Setting an invalid value on some attribute of the ticket object or sub-object of the ticket. This can be particularly tedious to debug, as the ZD response doesn't usually tell you which attribute has an invalid value. You should check all the integer values that you are setting on the ticket. E.g., I've been burned by using the Group IDs from my production Zendesk while developing on the Sandbox System (they most likely have entirely different IDs for everything, including custom fields, groups, users, etc.).

If you are creating new tickets via POST, be sure to check all the values you are setting, as per my second bullet point above.