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

10 Comments

  • Calum Ochkas

    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
  • Bryan Flynn

    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
  • Calum Ochkas

    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
  • Bryan Flynn

    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
  • Calum Ochkas

    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
  • Rahul Maurya

    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
  • Devan - Community Manager
    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
  • Austin Vieth

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

     

    I will be opening a private ticket.

    0
  • karan sharma

    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
  • 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.

Powered by Zendesk