422 error when creating a ticket in Zendesk - 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 = "gbalasel#easynext.be";
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.
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:
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.
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.
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
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
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
I had an issue with the Zendesk API throwing a 422 when I was attempting to create a ticket. All parameters were correct, the problem was that the assignee for which the ticket was created for did not belong to the group.
I found this error by looking at the request response by using FIDDLER.
Adding this here in case someone else runs into this issue. For me the ticket formatting was correct, but the requester was suspended:
Error Result:
{
"error": "RecordInvalid",
"description": "Record validation errors",
"details": {
"requester": [{
"description": "Requester: jkraft is suspended."
}]
}
}
Follow these instructions to unsuspend a user: https://support.zendesk.com/hc/en-us/articles/4408835668634-How-do-I-unsuspend-access-for-a-user-
I hope this is helpful to tell whether or not you are receiving the HTTP 422 because the ticket was already closed or if its because you were trying to do something like edit a field with invald params:
If you log the response object from zendesk for the failed http 422, you can look at the response object and check its configs. In my example it was:
response: {
status: 422,
statusText: 'Unprocessable Entity',
headers: {
date: 'Wed, 01 Feb 2023 17:48:00 GMT',
'content-type': 'application/json; charset=utf-8',
'content-length': '145',
connection: 'close',
'x-zendesk-api-version': 'v2',
'x-zendesk-application-version': 'v15375',
'x-frame-options': 'SAMEORIGIN',
'zendesk-rate-limit-tickets-update': 'total=100; remaining=99; resets=60',
'x-rate-limit': '700',
'rate-limit': '700',
'x-rate-limit-remaining': '699',
'rate-limit-remaining': '699',
'rate-limit-reset': '60',
'strict-transport-security': 'max-age=31536000;',
'cache-control': 'no-cache',
'x-zendesk-origin-server': 'classic-app-server-5b7bb5f96b-2bngr',
'set-cookie': [Array],
'x-request-id': '792c83f6384a5f9a-SMF, 792c83f6384a5f9a-SMF',
'x-runtime': '0.086818',
'x-zendesk-zorg': 'yes',
'cf-cache-status': 'DYNAMIC',
'report-to': '{"endpoints":[{"url":"https:\\/\\/a.nel.cloudflare.com\\/report\\/v3?s=mwQlS2H5vr2L4HJeTbyCvhjJbRJIwwhO%2FjJFw1z5cpIkak9Oke5GtqcaWsrzIF9gnYxTnkiPAFpkBgprHoXcr2yi%2FvA7grLEoQvXeHhsSmzOnu2LslqRDbzYeeMhRRtQwIrE0uLhrZJxTzlo%2FIfcKZ4%3D"}],"group":"cf-nel","max_age":604800}',
nel: '{"success_fraction":0.01,"report_to":"cf-nel","max_age":604800}',
server: 'cloudflare',
'cf-ray': '792c83f6384a5f9a-SMF'
},
config: {
transitional: [Object],
adapter: [Function: httpAdapter],
transformRequest: [Array],
transformResponse: [Array],
timeout: 10000,
xsrfCookieName: 'XSRF-TOKEN',
xsrfHeaderName: 'X-XSRF-TOKEN',
maxContentLength: -1,
maxBodyLength: -1,
validateStatus: [Function: validateStatus],
headers: [Object],
baseURL: 'https://***.zendesk.com/',
method: 'put',
url: '/api/v2/tickets/69519.json',
data: '{"ticket":{"status":"open","comment":{"html_body":"Follow-up Notes: \\n<p><br></p>","public":false}}}'
},
If you will notice, the 'url' and 'data' properties of the config object in my case proved I was hitting the correct api endpoint and I was also providing the correctly formatted payload. This led me to pull the tickets status and confirm it was closed, which was the source reason for the 422 response.
Related
I need help understanding determining Youtube username/channel name when you only have the channel ID
So according to https://developers.google.com/youtube/v3/guides/working_with_channel_ids, every account contains a unique channel ID which is independent to what used to be a username. That's all fine and dandy, as channel ID is the way to identify unique accounts. Sure, I'm all for that. Where I am confused, is when I am given a unique channel ID, how can I use this to obtain the channels preferred "username", whether it be some online alias or "real-life" name? Specifically, I am using this API (https://developers.google.com/youtube/v3/live/docs/liveChatMessages/list?hl=en) to periodically watch as new messages are placed into my broadcast. It works, and provides data which looks like the following: { kind: 'youtube#liveChatMessage', etag: 'zPV9PwBFYCiNZH_4PpspXF0ZrSs', id: 'LCC.CikqJwoYVUNMcnBlSWl1aVF1WHphcldCZVFuc3dBEgtOaHI4d2NSUHIyQRI5ChpDTC0ybDQzcC12TUNGVVFCZlFvZDVBQUhiQRIbQ09YRjdfM2stdk1DRmZRYmZRb2QzT0FCUUEw', snippet: { type: 'textMessageEvent', liveChatId: 'KicKGFVDTHJwZUlpdWlRdVh6YXJXQmVRbnN3QRILTmhyOHdjUlByMkE', authorChannelId: 'UCLrpeIiuiQuXzarWBeQnswA', publishedAt: '2021-11-02T23:22:37.070185+00:00', hasDisplayContent: true, displayMessage: 'testing once again 😀', textMessageDetails: [Object] } } As you can see, there is an authorChannelId here, which is great... Except for the fact that I can't reasonably read this as a human. My use case is that I specifically want to have a periodically updating local app which can update me with a console message similarly formatted like so: Bob Frank: foo bar :D Even though I technically can have something like the following, it doesn't help me know which of my 5 friends I'm expecting in my live broadcast: UCLrpeIiuiQuXzarWBeQnswA: foo bar :D Ah yes... Who are you again? Can you remind me again UCLrpeIiuiQuXzarWBeQnswA? I have also tried the following API (https://developers.google.com/youtube/v3/docs/channels/list), but it doesn't appear to give the right information either. With part: "snippet" and id: "UCLrpeIiuiQuXzarWBeQnswA" I get the following output: { config: { url: 'https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=UCLrpeIiuiQuXzarWBeQnswA', method: 'GET', userAgentDirectives: [ [Object] ], paramsSerializer: [Function (anonymous)], headers: { 'x-goog-api-client': 'gdcl/5.0.5 gl-node/17.0.1 auth/7.10.1', 'Accept-Encoding': 'gzip', 'User-Agent': 'google-api-nodejs-client/5.0.5 (gzip)', Authorization: 'Bearer', Accept: 'application/json' }, params: { part: 'snippet', id: 'UCLrpeIiuiQuXzarWBeQnswA' }, validateStatus: [Function (anonymous)], retry: true, responseType: 'json' }, data: { kind: 'youtube#channelListResponse', etag: 'wjX6CX2hdUPFAc4y6OCUDDjXT6o', pageInfo: { totalResults: 1, resultsPerPage: 5 }, items: [ [Object] ] }, headers: { 'alt-svc': 'h3=":443"; ma=2592000,h3-29=":443"; ma=2592000,h3-Q050=":443"; ma=2592000,h3-Q046=":443"; ma=2592000,h3-Q043=":443"; ma=2592000,quic=":443"; ma=2592000; v="46,43"', 'cache-control': 'private', connection: 'close', 'content-encoding': 'gzip', 'content-type': 'application/json; charset=UTF-8', date: 'Wed, 03 Nov 2021 01:30:32 GMT', server: 'scaffolding on HTTPServer2', 'transfer-encoding': 'chunked', vary: 'Origin, X-Origin, Referer', 'x-content-type-options': 'nosniff', 'x-frame-options': 'SAMEORIGIN', 'x-xss-protection': '0' }, status: 200, statusText: 'OK', request: { responseURL: 'https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=UCLrpeIiuiQuXzarWBeQnswA' } } So, any help would be greatly appreciated! Thanks! Edit: removed access token. Whoops. Edit2: Answer was in the question, but helped by the accepted answer below. Thank you Benjamin! The real answer is to go further into the final response above.... response.data.items[0].snippet.title. nodejs console.log() in this case did not expand each item and I totally missed this detail. My bad, I'm a novice in node and javascript. You can also use the API key as Benjamin points out, but at this point I've already got access to Oauth2 so I'll keep using the same auth.
Indeed Channels: list is the way to go. Just by accessing and parsing the JSON at this URL https://youtube.googleapis.com/youtube/v3/channels?part=snippet&id=A_CHANNEL_ID&key=YOUR_API_KEY. It has a field "title" in its "snippet" which seems to be exactly what you want. Of course you have to change A_CHANNEL_ID with, an authorChannelId, UCLrpeIiuiQuXzarWBeQnswA for instance.
Using an API with Zapier but getting "The app returned ""rest_data" param is incorrect. JSON data expected"."
So i grab data from an Airtable and then have a custom PUT as the second action using Samba Lives API, specifically Sessions -> PUT Session https://documenter.getpostman.com/view/2014682/samba-live-rest-api/6YzutHM#c87c1db7-2b5c-9b2b-7d63-6b531793cfe2 This is the data in the custom PUT: Method: PUT URL: https://samba.live/api/2/ourusername/session Data Pass-Through? No Data: input_type=json&rest_data={ "topic": "Crazy Topic", "duration": 30, "start_time": "2025-09-10 12:00:00", "invited_participants":[ { "email":"flast#company.com", "first_name":"First", "last_name":"Last", "role":2, "send_email_invitation":true }, { "email": "first.last#gmail.com", "first_name": "First", "last_name": "Last", "role": 1, "send_email_invitation": true } ], } Unflatten- yes Basic Auth- ourusername|ourpassword Headers- none But the test fails and says "App returned "rest_data" param is incorrect. JSON is expected." I'm not really sure what to try and Zapier just said we don't help with that. Only thing i could think to try was to delete the input_type section, and that returned with an error saying "Topic is required." Same thing when i left most of it and just deleted the rest_data part. Any ideas?
Fixed - apparently the comma after the ] threw everything off.
ZendeskApi.Tickets.CreateTicket throws 401 despite "Anybody can submit tickets" is enabled
I have a Trial subscription and I'm using ZendeskApi.Tickets.CreateTicket(ticket) to create a new ticket; Anybody can submit tickets is Enabled. It works when I create a ticket with requester.email that is a registered user, but I'm getting the below error when I try to create a ticket with a Requester who is not a user. Tips on what I'm doing wrong? The remote server returned an error: (401) Unauthorized.Error content: {"error":"Couldn't authenticate you"} Resource String: tickets.json + Body: { "ticket": { "subject": "Subject", "comment": { "body": "Message test body", "public": false }, "requester": { "email": "wendellj#gmail.com" }, "is_public": false }
For anonymous user you should use this api end point: https://developer.zendesk.com/rest_api/docs/core/requests#create-request This is used to create requests in zendesk when user is not registered with user and it doesn't need authentication header as well. See To make anonymous requests: Omit the authorization header. Include a requester object in the request object.
Creating tickets in Zendesk
I am new to Zendesk, but what I want is for my app to be able to create tickets in Zendesk. Basically, when a user does something in my web application, my backend application creates a ticket for a Support to look at the issue and resolve it. Looking at the Zendesk API for creating tickets, it seems that it asks for agent username and password, but there is no agent, just a machine that is creating those tickets. So my question here is, should I use some different approach to this problem, or should I work around by creating a user for the machine with imaginary email address so that I can authenticate?
In this case, you should use the "request" endpoint, instead of the "ticket". Here is an example that may help: fetch('https://SUBDOMAIN.zendesk.com/api/v2/requests.json', { method: 'post',headers: { 'Accept': 'application/json, text/plain, */*', 'Content-Type': 'application/json' }, body: JSON.stringify({"request": {"requester": {"name": "Anonymous customer"}, "subject": "Vlad test", "comment": {"body": "Here goes a ticket body" }}}) }).then(res=>res.json()).then(res => console.log(res));
parse-server session gets deleted
Our app (parseSDK 1.13) has a parse-server (2.2.15) backend and sometimes (reproduceable) the user's session gets destroyed. After loading some custom objects from parse-server, the app (or more precise: parse-SDK) sends a strange request to parse-server to set the user password while i'm not doing any register/login/pw-reset related action: Request: POST /parse/batch {"requests": [{ "path": "\/parse\/classes\/_User\/abcu45BFAd", "method": "PUT", "body": { "password": "xyz" } }]} Response: [{ "success": { "updatedAt": "2016-07-05T23:04:51.041Z" } }] After that request, the server completely destroys the Session entry in the database without any notice. All following requests fail with error 209 (invalid session token). I do not intent to set/update the pssword and i cannot find, where this request comes from. Any hints are highly appreciated, thanks.
Should be fixed with upcoming 2.2.17