Forums/Product news and updates/API updates

Comment as the customer with the new Requests API

Steven Yan
posted this on September 05, 2012 14:48

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.

 

Comments

User photo
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.

September 06, 2012 19:51
User photo
Steven Yan
Product Manager

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?

September 06, 2012 20:09
User photo
Vaishnavie Srinivasan

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

September 06, 2012 20:20
User photo
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 - "

September 06, 2012 21:04
User photo
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 .

September 06, 2012 21:18
User photo
Steven Yan
Product Manager

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.

September 08, 2012 08:32
User photo
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.

September 10, 2012 03:26
User photo
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).

September 10, 2012 03:30
User photo
Steven Yan
Product Manager

Thanks Andrey, updated the example.

September 13, 2012 23:16
User photo
Peter
juniper

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)

October 24, 2012 14:54
User photo
yogi
Rackspace

@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? 

November 29, 2012 15:54
User photo
Chirag Desai
amaeya

@Yogi,

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

CD

December 02, 2012 00:50
User photo
yogi
Rackspace

@Chirag, 

Thank you for clarifying this.

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

December 03, 2012 19:40
User photo
Chirag Desai
amaeya

@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

December 04, 2012 00:20
User photo
yogi
Rackspace

@Chirag 

Thank you ! it worked ! 

December 04, 2012 11:25
User photo
Chirag Desai
amaeya

@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

December 09, 2012 00:26
User photo
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

December 27, 2012 00:22
User photo
Steven Yan
Product Manager

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.

January 01, 2013 21:39
User photo
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.

January 04, 2013 13:48
User photo
yogi
Rackspace

@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}}}'
January 04, 2013 13:58
User photo
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#c...)

January 04, 2013 14:10
User photo
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.

January 04, 2013 14:28
User photo
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.

January 04, 2013 15:46
User photo
DeVaris Brown
Zendesk

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

January 04, 2013 19:40
User photo
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.

January 07, 2013 09:59
User photo
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.

January 15, 2013 04:57
User photo
Chirag Desai
amaeya

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

January 15, 2013 05:03
User photo
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.

January 15, 2013 05:19
User photo
Chirag Desai
amaeya

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

January 16, 2013 09:18
User photo
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.

January 17, 2013 11:33
User photo
Mutwin Kraus

Hi,

I'm currently building tools on the Zendesk API and have tried using the requests endpoint for responding to tickets. Unfortunately whenever I use requests to create a response the response becomes private in Zendesk (see attachment for a screenshot).

I tried setting "public": true in the request but that didn't help. Is there any way I can update requests with a publicly visible response?

Thanks,

Mutwin

February 08, 2013 04:07
User photo
KK
lesarion

i also like to set the submitter and the requester id.

when i create a ticket with my api zendek token and the users email i receive the following:

{"error":{"title":"Forbidden","message":"You do not have access to this page. Please contact the account owner of this help desk for further help."}}

 

api - documentation of creating ticket: only agents can create tickets. but this posting descripes that an ticket should be passed by the enduser.

 

the current implementation is realy complicated and there are still lots of question. why can i not set the submitter and the requester with the admin account and token?

February 09, 2013 11:28
User photo
DeVaris Brown
Zendesk

KK I'd need to see the call you're trying to make. Please email api@zendesk.com with the curl call and URL you're trying to send the request to.

February 11, 2013 14:11
User photo
DeVaris Brown
Zendesk

Mutwin; what happens when you use the tickets endpoint? Can you email me, api@zendesk.com, the call you're making so I can see what you're trying to do?

February 11, 2013 14:51
User photo
DeVaris Brown
Zendesk

There is a bug in the new agent interface that won't show the proper submitter even if you pass in the proper author_id for the comment. We are aware of this and will be fixing this in an upcoming release.

February 11, 2013 14:57
User photo
Colin Piper
Telappliant

@Fox Diller. I feel your pain as I too cannot get custom fields working in a request. I was hoping that one of the Zendesk reps would acknowledge this as a bug. 

February 27, 2013 03:25
User photo
DeVaris Brown
Zendesk

I've gotten the request to work with custom fields. Your JSON is probably wrong. I had to run mine through a JSON linter before it would actually work. Try the following and see if it works for you.

curl https://{yoursubdomain}.zendesk.com/api/v2/requests.json -d '{"request": {"subject": "Help!", "comment": {"body": "My printer is on fire!"}, "custom_fields": [{"CUSTOM_FIELD_ID": "VAL1"}, {"CUSTOM_FIELD_ID": "VAL2"},{"CUSTOM_FIELD_ID":"VAL3"}]}}' -v -u requester@email.com/token:youragentAPItoken -X POST -H "Content-Type: application/json"

March 01, 2013 10:27
User photo
John Grouginio

I'm confused about the process of updating a ticket as an end user. The post instructs to first authenticate as the end user, then to identify the ticket in the requests URL and finally to pass a comment body in the requests update. I am able to identify the ticket in the requests URL and to pass a comment body to the update, but doing so without authenticating as the end-user results in a comment with the author ID set to the ID of the API user. Could I get an explanation on how to authenticate as the end user in a Rails app using the Zendesk API Ruby client? I'm relatively new to developing Rails apps, and even newer to developing apps with an API, so a clear explanation would be fantastic.

August 13, 2013 17:51
User photo
Danyel Meyer
sycat

Preparing for migration from a different system, I´m trying to add a comment via API v2 / C#-wrapper as end user. I use the end users email address and my ZenDesk auth token, but I keep getting the error:

You do not have access to this page. Please contact the account owner of this help desk for further help

I found this thread saying it should work, but also comments with the same problem. Is there any solution to add comments as end user via API calls?

October 21, 2013 05:32
User photo
Pierre Nespo
Zendesk

Danyel,

 

You need to use your own email/token (Administrator/Agent) to access the API. In order to create a comment on behalf of an end-user you need to set his id as the author_id key (as explained here: http://developer.zendesk.com/documentation/rest_api/ticket_comments...). If the end-user doesn't exist, you'll need to create it in order to obtain an id.

 

Hope it helps,

Cheers,

Pierre.

 

October 21, 2013 05:39
User photo
Danyel Meyer
sycat

Hi Pierre,

thank you for your quick response! I tried to add the comment using this, I got the link from the API documentations´ introduction page: https://github.com/eneifert/ZendeskApi_v2

This wrapper is missing the "author_id" field for comments... :(

October 21, 2013 05:43
User photo
Pierre Nespo
Zendesk

Danyel,

Since it's an open source project hosted on Github, you could try to make a pull request that will remove the "private" scope for AuthorId(https://github.com/eneifert/ZendeskApi_v2/blob/master/ZendeskApi_v2...) :)

Cheers.

October 21, 2013 05:49
User photo
Danyel Meyer
sycat

Pierre,

thank you again! After your first hint to the "author_id" field I was able to add this to the comments model. Works fine! I think I have to take a closer look at the API documentation to find out if there are more important fields not implemented in teh wrapper classes ;)

October 21, 2013 06:00
User photo
Emre Hakan

Hi,

I want to update ticket as an end-user, but comment's public property is not working. Although i set the property to false, but it becomes true.

November 26, 2013 03:33
User photo
Chirag Desai
amaeya

Emre - don't think there is public property in the requests API, because end-user comments are always public?

Cd

November 26, 2013 04:29
User photo
Steven Yan
Product Manager

Emre, Chirag is right here -- end-user comments are always public. If you want to set a private comment on a ticket, you need to use the /api/v2/tickets endpoint.

November 26, 2013 08:01
User photo
João Pimentel

Hi,

Is this information still up-to-date? I'm trying to perform a similar request to the "Creating tickets as an end-user" example. I'm using a non-zendesk user email and an agent's API token, but I get a {"error":"Couldn't authenticate you"} as a response.

Is there some other token I should be using?

February 20, 2014 04:48
User photo
João Pimentel

Ok, I was able to open a ticket as an end-user using the agent's email and token, and setting

    "requester": {"name": "Some Name", "email": "enduser@somedomain.com"}

in the "ticket" dictionary, using the Tickets API.

February 20, 2014 08:39