Recent searches


No recent searches

Error (422 Response) when posting a request using the requests.json API as an End-User

Answered


Posted Jun 25, 2019

I'm attempting to create ZenDesk tickets using an OAuth Token from the Google Scripts API.

When creating the ZenDesk ticket using an token provided for an Agent, it works fine. However, when running it as an end user, it obtains a token fine, then fails to create the request throwing the error:
---
{"error":"RecordInvalid","description":"Record validation errors","details":{"base":[{"description":"Subject: cannot be blank","error":"BlankValue","field_key":"subject"},{"description":"Type: cannot...)
---

The token is correct as the same token works when listing requests using the GET method.

The JSON payload and options must be correct as the same code works correctly when initiating the request from an Agent, it's only when initiating it from an end user that it fails.

Payload:
---
"request" : {
"subject": "Test Ticket Subject",
"comment": { "body": "Test Ticket Body" }
}
---

Body:
---
'method': 'post',
'payload' : JSON.stringify(formData),
'contentType' : 'application/json',
'headers' : {"Authorization" : "Bearer " + token}
---

Doing a GET on the requests.json works correctly and enumerates the requests as expected. It's only POST that's failing


Are there specific permissions that are required for an end-user to post a request with their own token?


0

10

10 comments

Found the issue. For others: creating ticket requests as the end user you must pass basic auth and the emailaddress\token.

Eg.
---
'method': 'post',
'payload' : JSON.stringify(formData),
'contentType' : 'application/json',
'headers' : {"Authorization" : "Basic " oauthemail + "/" + token}
---

0


Hi Calum -- just to clarify, a new request/ticket created by an end user using an OAuth/Bearer token should work.

To simplify the above and using the cURL command line tool, the request would look something like:

curl -v -H "Content-Type: application/json" -H "Authorization: Bearer d482cccebdd482cccebdd482cccebdd482cccebdd482cccebdd482cccebd" https://yourownsubdomain.zendesk.com/api/v2/requests.json -X POST -d '{"request":{"subject":"Test Ticket Subject","comment":{"body":"Test Ticket Body"}}}'

You can quickly generate an OAuth token for the above example using your own account and end-user by:

1. In an incognito browser window, go to https://developer.zendesk.com/requests/new

2. Enter your Zendesk instance's subodomain

3. Click Authorize (then select 'Allow' in the popup window that's displayed if needed)

4. Then copy the entire returned OAuth token

I would not recommend using the "API Token"/Basic authorization approach from a client-side solution -- it exposes your account to possible abuse. By switching out the email address before the "/token" portion, you can impersonate other users. You should only use an API token within the context of a secure server-side solution (one that will not expose the API token to any client agents).

0


The way you mention is how I've done it when able to encrypt the token somewhere. However, I'm building scripts into the Google Apps Script API. Ideally I don't want to be publishing any API Token plain text on the Apps Script console, hence I'm initiating the OAuth Token request and retrieving the token in a variable - saving any token being published on the script itself

 

0


That sounds reasonable Calum. So I'll just point out again then, an end-user account can generate an OAuth token and use it against the /api/v2/requests.json API. It sounded like this wasn't working for you when I read the original post. If that's still the case, then more details will probably be needed via a private ticket. Let me know and I can create one for you.

0


Thanks Bryan. If you'd like to see the Auth fail without basic auth I'm happy to show you via a private ticket. Let me know, else I'm happy with the workaround for now.

0


I am getting the same error code.


While sending it through a mobile app, I am getting 422 error code without any error message details whereas if I am using the same auth token, request body in postman. It gets succeeded.
Please help

 

{"request":{"subject":"test 1","from_mail":"admin@email.com","comment":{"body":"testy 1"}}}

https://{organisation-name}.zendesk.com/api/v2/requests.json

Content-Type: application/json

Authorization: Basic email+token

 

 

0


image avatar

Devan La Spisa

Zendesk Community Manager

Hello @...,

It looks like you might be experiencing a bug, I've gone ahead and opened a ticket for you so one of our experts can dive deeper into this issue. You should expect a response from one of our skilled Advocates soon, and we appreciate your patience with this issue.

Best regards.

0


I have the exact same issue as Rahul except I'm using the Oauth flow.

 

I will be opening a private ticket.

0


i have issue related to this 

{
"error": "RecordInvalid",
"description": "Record validation errors",
"details": {
"requester": [
{
"description": "Requester: Name: is too short (minimum one character)"
}
]
}
}

we have a webhook created which is creating parent to child ticket via webhook and one of the fields in parent ticket becomes requester for child ticket.can i get any idea over it?

0


image avatar

Christopher Kennedy

Zendesk Developer Advocacy

Hi Karan,
 
When creating a ticket with a new requester, both the requester email and name are required.  Update the JSON body in your trigger to include the requester name as noted in the linked doc. This will resolve that record validation error you're seeing.

0


Please sign in to leave a comment.

Didn't find what you're looking for?

New post