Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

422 error when creating a ticket in Zendesk

Tags:

zendesk

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.

like image 363
user3405456 Avatar asked Apr 04 '14 15:04

user3405456


People also ask

What is an error 422?

The HyperText Transfer Protocol (HTTP) 422 Unprocessable Entity response status code indicates that the server understands the content type of the request entity, and the syntax of the request entity is correct, but it was unable to process the contained instructions.

How do I update a ticket in Zendesk?

The Submit button applies any updates you make to a ticket (status changes, public or internal comments, and the like), and allows you to select the ticket status. Click the Submit button.

Can you edit Zendesk tickets?

Answer. No, it is not possible to edit ticket comments after they are posted to the ticket. If there is sensitive information that needs to be removed from a ticket, an administrator can install the Ticket Redaction app from our Marketplace and use it to remove text from the ticket comments.


4 Answers

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.

like image 163
Ken Verb Avatar answered Nov 09 '22 07:11

Ken Verb


This telling you that you have not formed a request that it can handle; the destination script exists (otherwise you'd see a 404), the request is being handled (otherwise you'd get a 400 error) and it's been encoded correctly (or you'd get a 415 error) but the actual instruction can't be carried out.

take a look on this for more info. Error List

like image 29
Illaya Avatar answered Nov 09 '22 07:11

Illaya


just to add to the solution if anyone encounters the same problem.

requester_id is mandatory while posting the ticket json.

A sample ticket json -

{
  "ticket": {   
    "subject": "My printer is on fire!",
    "requester_id": 123,
    "assignee_id": 456,
    "type": "incident",
    "subject": "Help, my printer is on fire!",
    "description": "The fire is very colorful.",
    "priority": "High",
    "status": "open",
    "custom_fields": [
      {
        "id":    111, // custom field ID
        "value": "500.23"
      }
    ]
  }
}

Thanks

like image 29
Harsheet Avatar answered Nov 09 '22 07:11

Harsheet


Yeah I run today to the same problem and solved it. The problem is that you need a comment and body part inside the ticket structure.

So this is how it could look like (in PHP):

$ticket = [
    'group_id'       => '35135',
    'title'          => 'Title',
    'subject'        => 'Subject',
    'type'           => 'ticket',
    'comment'        => ['body' => 'Comment text.'],
    'priority'       => 'normal',
    'ticket_form_id' => '454524',
    'custom_fields'  => [
        '51325351' => 'test',
    ],
];

Take a look on here: https://developer.zendesk.com/rest_api/docs/core/tickets

like image 1
Kingalione Avatar answered Nov 09 '22 07:11

Kingalione