Comment as the customer with the new Requests API

Today we're introducing the Requests API that brings the ability to comment as an end-user to API v2, as well as perform the functions available in our end-user portal such as retrieve an end-user's tickets.

If you are familiar with API v1, you would have used the X-On-Behalf-Of header to impersonate an end-user while authenticating as an agent.  Here are examples of how you would accomplish this equivalently in API v2.

Creating tickets as an end-user

Below is an example curl request that creates a new ticket where enduser@domain.com is the requester.  Note that you the end-user's email address and the Zendesk account's token for authentication.

curl -u enduser@domain.com/token:5BQ2ek3RV5P7KCyWs0x6p5EoM0sIRErmnrgNSXMM https://yourdomain.zendesk.com/api/v2/requests.json -X POST -d '{"request": {"subject": "I need some help", "comment":{"value":"Allow me to elaborate on why I need help"}}}' -H "Content-Type:application/json"

Updating tickets as an end-user

Updating tickets works similarly to creating tickets.  Authenticate as the end-user, identify the ticket in the requests URL and pass a comment body in the requests update.

curl -u enduser@domain.com/token:5BQ2ek3RV5P7KCyWs0x6p5EoM0sIRErmnrgNSXMM https://yourdomain.zendesk.com/api/v2/requests/123.json -X PUT -d '{"request": {"comment":{"value":"This is a new comment update."}}}' -H "Content-Type:application/json"

 

To review full details about the requests API, please see our documentation on developer.zendesk.com.

Have more questions? Submit a request

Comments

  • Avatar
    Vaishnavie Srinivasan

    I tried running the curl command as given in above but i get an error stating "Protocol https not supported or disabled in libcurl" so i executed the same curl command with http://yourdomain........ and get the error message as "Couldn't connect to host". How to make the curl command run.

  • Avatar
    Steven Yan

    Hi Vaishnavie, this sounds like an issue with your libcurl installation which will be hard to help you with without further information about your environment.  Regarding the URL to use, did you replace "yourdomain" with your Zendesk account subdomain?

  • Avatar
    Vaishnavie Srinivasan

    Hi Yan, i did use my zendesk account subdomain and i still get the error as "Couldn't connect to host".

  • Avatar
    Vaishnavie Srinivasan

    Hi Yan, To add on I tried to post a ticket through tickets.json thorugh my application and it worked fine. However, when i tried to post the ticket through requests.json using the application, I get the following error message "Unprocessable Entity Content - "

  • Avatar
    Vaishnavie Srinivasan

    Hi Yan, this is the request json that i am trying to post for the requests.json from my application {"request": {"subject": "Test", "description":"Test"}} and passing the endusers email address and the token in authetication header and the url as   https://mydomain.zendesk.com/api/v2/ requests.json .

  • Avatar
    Steven Yan

    Hi Vaishnavie, I'm going to open a ticket for you to investigate this further.  I'll need to see some exact API calls you're making.

  • Avatar
    Andrey Chushikin

    How to submit custom fields using your v2 "request" API?

    There was {fields: [FIELD_ID: FIELD_VAL]} version in v1 "request" API, also there is {fields: [{id: FIELD_ID, value: FIELD_VAL}]} version in v2 "ticket" API ( http://developer.zendesk.com/documentation/rest_api/tickets.html#setting-ticket-fields).

    But how can I submit a request from end-user (as described in this topic) using your v2 "request" API with a number of custom fields? Neither first, nor second version has no effects for now.

  • Avatar
    Andrey Chushikin

    Also, there is an error in your example here :)

    For "creating ticket" use-case description text should be sent not using:

     "description":"Allow me to elaborate on why I need help"

    but:

    "comment":{"value":"Allow me to elaborate on why I need help"}

    (as described  http://developer.zendesk.com/documentation/rest_api/requests.html#creating-requests here).

  • Avatar
    Steven Yan

    Thanks Andrey, updated the example.

  • Avatar
    Peter

    Note that emails must be verified for this to work.  Without verification I get: {"error":"Couldn't authenticate you"}

    Creating a new verified user is pretty easy:

    http://developer.zendesk.com/documentation/rest\_api/users.html

    curl -v -u {email_address}:{password} https://{subdomain}.zendesk.com/api/v2/users.json \
    -H "Content-Type: application/json" -X POST -d '{"user":{"name":"Roger Wilco", "email":"roge@example.org", "verified": "true"}}'

     

    Or, in ruby:

    https://github.com/zendesk/zendesk\_api\_client\_rb

    user = $zendesk.users.create(name:"Roger Wilco", email:"roge@example.org", verified: true)

  • Avatar
    yogi

    @steven

    v1 api provided an option to submit a ticket on behalf of user without having to use end-users authetication token . Can we do something similiar in V2 api? If so ; how? 

  • Avatar
    Chirag Desai

    @Yogi,

    The example above uses the Zendesk account token, not the end-users token/password. Have verified this and it works a-okay.

    CD

  • Avatar
    yogi

    @Chirag, 

    Thank you for clarifying this.

    Is there a way to use username and password of zendesk account instead of using the Token ?

  • Avatar
    Chirag Desai

    @Yogi,

    Yes, if you use standard auth with username/password, this did work when we tried it initially. The token just works better for us.

    CD

  • Avatar
    yogi

    @Chirag 

    Thank you ! it worked ! 

  • Avatar
    Chirag Desai

    @Steve,

    There are a couple of inconsistencies (for want of a better word) between the requests API and the actual end-user view Zendesk provides. 

    • (important) There is no comment author information available. So all we're able to load is a series of comments and if people don't sign off their names (or in my case, I use initials since the user would see it over email, where my name would be printed), or in the UI, that's fine. But at the moment, the only thing we have is the comment and the date/time it was submitted. Any plans to correct this?

    • Side loading - assuming the above is coming, it would be good to incorporate side-loading though, as opposed to the multiple API calls to then render userid of a comment to user name.

    • CCs - the requests API doesn't include CC's on a ticket, which is something the end-user should be able to see.

    • (nice to have) - the end user portal shows the assigned agent on the ticket, but the requests API doesn't.

    CD

  • Avatar
    Jitendra Kumar

    @Steve,

    I m getting this error "You do not have access to this page. Please contact the account owner of this help desk for further help." while updating ticket as an end user by API v2.

    Thanks,

    Jitendra

  • Avatar
    Steven Yan

    Jitendra, can you please share an example of the API request you are making? I'll need that to troubleshoot the error you are seeing.

  • Avatar
    Fox Diller

    How to submit custom fields using your v2 "request" API?

    There was {fields: [FIELD_ID: FIELD_VAL]} version in v1 "request" API, also there is {fields: [{id: FIELD_ID, value: FIELD_VAL}]} version in v2 "ticket" API ( http://developer.zendesk.com/documentation/rest_api/tickets.html#setting-ticket-fields).

    But how can I submit a request from end-user (as described in this topic) using your v2 "request" API with a number of custom fields? Neither first, nor second version has no effects for now.

  • Avatar
    yogi

    @Fox Diller ,

    use the author_id of the end-user and that does the trick

    as an example

    curl -u agent@mycomp.org:password https://mycompany.zendesk.com/api/v2/tickets/928151.json -X PUT -H "Content-Type:application/json" -d '{"ticket":{"comment":{"value": "comment yo what’s up","author_id":249787247}}}'

  • Avatar
    Fox Diller

    @yogi That's an incorrect response, my question remains how do you send along custom fields when submitting a new request using the /api/v2/requests.json API endpoint? (http://developer.zendesk.com/documentation/rest\_api/requests.html#creating-requests)

  • Avatar
    Fox Diller

    This is frankly ridiculous, so far:

    • You must use "fields" and not "custom_fields" when submitting a request (no-where is this documented clearly)
    • When using 'fields', the value of the field is ignored.

    Is this a bug with ZenDesk? It's an almost deal-breaker for me.

  • Avatar
    Fox Diller

    How to submit custom fields using your v2 "request" API?

    There was {fields: [FIELD_ID: FIELD_VAL]} version in v1 "request" API, also there is {fields: [{id: FIELD_ID, value: FIELD_VAL}]} version in v2 "ticket" API ( http://developer.zendesk.com/documentation/rest_api/tickets.html#setting-ticket-fields).

    But how can I submit a request from end-user (as described in this topic) using your v2 "request" API with a number of custom fields? Neither first, nor second version has no effects for now.

  • Avatar
    DeVaris Brown

    Are you saying that the value isn't getting set? You have the proper syntax here: {fields: [{id: FIELD_ID, value: FIELD_VAL}]}

  • Avatar
    Fox Diller

    Yeah, the value simply is ignored by the Request API POST endpoint. If the field is required and I omit it, it will complain. However when I do include a value the ticket is created but the value is simply ignored. I triple checked the field type and the exact string length of the value matches what is needed. The value ends up being an empty string, '', everytime.

  • Avatar
    Brian Graham

    Hey guys,

    Is there any way to accomplish this in the V2 API without having access to the auth token of the Zendesk account? Unless I'm mistaken (and I would love to be mistaken on this), there's no way to programmatically get the auth token of a Zendesk account, so we're currently using the ZD account's username and password for our integration.  Does the old X-On-Behalf-Of header still work in the V2 API? The phrasing of this post led me to believe it does not.

  • Avatar
    Chirag Desai

    Hey Brian,

    You may have missed mine & Yogi's comments, but you can still use the user's username/password combination instead of the token as well.

    I don't believe they've incorporated the X-ON-Behalf-of header yet into v2.

    CD

  • Avatar
    Brian Graham

    Chirag,

     

    Perhaps I simply don't understand how the request needs to be structured. Is the example that Peter gave (where the end-user we're requesting on behalf of must be verified) what I should be looking at, or is it something else?

     

    Thanks for being so speedy in your response.

  • Avatar
    Chirag Desai

    Hey Brian,

    Well, if you're trying to submit on behalf of the user, then you would just submit with that user as requester and a) his/her password or b) the company account token, which substitutes for the on-behalf-of as per my understanding.

    The example Peter gabe is to create a verified user, because you can't interact over the API with an unverified user, so you either need to create pre-verified users on the API or manually verify them in the UI. The example Steve gave should do it, but it's almost the same as just creating/updating a ticket with the requests endpoint.

    Does that help?

    Chirag

  • Avatar
    Brian Graham

    Chirag,

     

    Unfortunately, I won't have access to the end-user's Zendesk email/password, nor will I have the Zendesk user's token.  It successfully creates a ticket with the end-user's email, but the picture shows the image of the Zendesk user. This seems to only be the case in the new Lotus UI, so I wasn't certain if this was simply a Lotus bug or if the requester is not being set appropriately.