Building a custom ticket form with the Zendesk API

Have more questions? Submit a request

18 Comments

  • Nate Legakis
    Comment actions Permalink

    I have another question.  This describes how to create tickets for agents and users that are registered already.  Is there a way to create custom web form for users that are not already registered?  

    0
  • Charles Nadeau
    Comment actions Permalink

    Yes, you can use the Requests API instead of the Tickets API. The Create Requests endpoint lets anonymous users create tickets. See https://developer.zendesk.com/rest_api/docs/core/requests#create-request.

    0
  • Nate Legakis
    Comment actions Permalink

    Can you add custom ticket fields to the form?  Or, can you only use a subject and description field?

    0
  • Charles Nadeau
    Comment actions Permalink

    With some tweaks to your code, you can add form fields for any writeable property of a ticket or request. For example, see the properties of a request at https://developer.zendesk.com/rest_api/docs/core/requests#json-format.

    0
  • Pete Robertshaw
    Comment actions Permalink

    Hi Charles,

    Great article - we're working through this now and noticed your comment above about being able to add form fields for any writable property of a ticket or request. We have a custom drop down ticket field on our support account where we select why a customer wants to return a product to us. 

    Are you saying it is possible to include this drop down field on our own custom form? If so, how do we pass the value the customer selects so it marries up with the pre-set values we have in our account?

    Finally, is it also possible to capture uploaded files on our own form and pass them over with the ticket?

    Thanks in advance!

    0
  • Charles Nadeau
    Comment actions Permalink

    Hi Pete,

    You can add a dropdown to your custom form and assign the value to the request object's custom_fields property. Example:

    ...
    reason = request.forms.get('reason')    # dropdown is named 'reason'
    data = {
    'request': {
    'subject': subject,
    'comment': {'body': description},
    'custom_fields': [{ 'id': 34, 'value': reason }]
    } }

    See Setting ticket fields. The "id" is the id of the custom field that was created in the Support admin interface. You can find the id using the List Ticket Fields endpoint.

    Attachments are trickier because they're an attribute of a ticket comment, not the ticket itself. See the attachments property in the ticket comment object. I've never actually done it so I'm not sure what's the best way to do it. Upload the user's file to your server first, then use the Upload Files endpoint to upload the file to the Zendesk infrastructure, then include the attachment's id from the response in the ticket comment object? Just spitballing here...

    0
  • Nate Legakis
    Comment actions Permalink

    Can someone post some instructions on how you might create a custom ticket form in Wordpress?  I'm guessing that you wouldn't use bottle and python, and instead use something else that is already installed by Wordpress to handle the request and route.  Any information that you can give me would be very much appreciated.

    0
  • Joey
    Comment actions Permalink

    Hey there Nate-

    You are correct, you probably wouldn't want to use bottle & python with WordPress! We have our own WordPress plugin which can be found here. If you were looking for something more robust, I found this plugin, 'Zendesk Request Form.' Even if this isn't quite what you want, the package can be unzipped for your review.

    0
  • Chris Apgar
    Comment actions Permalink

    Hi - thanks to everyone who has contributed to this tutorial and discussion, it's all been really helpful to me.

    What other options are there to do this without a standalone app (Python or otherwise) needing to run on a server? Hosting a new external app, even this simple one, would introduce a huge number of challenges in our environment - security/compliance, responsibility for maintenance, etc. I would guess that lots of other customers are in the same boat.

    I built the app and it runs great locally, but now I'm trying to reverse engineer the solution and build it in a way that doesn't need an app. Pure javascript would be wonderful but seems impossible for security reasons. My next guess would be PHP? If anyone has suggestions or documentation they can point me to, I would really appreciate it!

    1
  • Hector
    Comment actions Permalink

    We are attempting to have the tickets created by the API assigned to a specific group within our portal. But tickets continue coming in without being assigned to our group. This is the syntax we are using for our JSON string:

    data = {'request':{'group_id': ############, 'subject': subject, 'comment': {'body': description}}}

    The Group ID was acquired by using a curl request as indicated by the following article.

    https://developer.zendesk.com/rest_api/docs/support/groups  

    Any idea what we could be doing wrong?

    0
  • Estelle Bardo
    Comment actions Permalink

    Hello. Thank you for this pretty detailed tutorial. However, I have three questions. (1): Is there a detailed tutorial for form creation for unauthenticated users? (2) If I add a drop-down list to create several categories of topics, how do I configure the API to get tickets by category? (3) Does anyone already add a google recaptcha to this type of form?

    0
  • Bryan - Community Manager
    Comment actions Permalink

    @Hector --

    You're running into the difference between the /api/v2/tickets.json endpoint and the /api/v2/requests.json endpoint. The /requests.json endpoint is for end-users, who can't set the Group ID value of a ticket. Group ID can only be set by an agent or an automation (trigger or such) within a Zendesk instance.

    @Estelle --

    1) This is the most detailed tutorial. If you want to submit tickets for an unauthenticated user directly, you'll need to use the /api/v2/requests.json API and have Admin > Settings/Customers > Anybody can submit a ticket checked.

    2) Help Center Community topics and posts do not equate to tickets. They are separate items. Help Center does have it's own API documented here, however. Perhaps this will help.

    3) Versus creating your own, you can modify a Help Center's Submit a Ticket form, which is CAPTCHA capable. See this article for more details: Where is the submit a request ticket form in Help Center? 

    0
  • Jeremy Fair
    Comment actions Permalink

    I worked through this tutorial successfully and as a follow-up attempted to edit it to allow anonymous users to submit but have been unable to do so. I used the suggested resource, https://developer.zendesk.com/rest_api/docs/support/requests#create-request, and also attempted submitting the request via the Zendesk API Console, https://developer.zendesk.com/requests/new, using the format described for anonymous users but even in the Developer Console. I continue to get something akin to 'Invalid authenticity token' in the JSON reply or 'Could not authenticate you. Check your email address or register.' via the form. 

    Am I reading the Developer Portal correctly here, https://developer.zendesk.com/rest_api/docs/support/requests#authentication, where it says "You must use an API token or an OAuth token with this API."

    In order for an anonymous request to go through does a Global OAuth need to be used as authentication?

    0
  • Bryan - Community Manager
    Comment actions Permalink

    Hi Jeremy. There are a few ways to authenticate into Zendesk Support -- check out How can I authenticate API requests?

    The approach used in the above sample is "API Token", which is something different than an OAuth access token.

    Since this sample solution is a server-side app, you can use an API token and authenticate in under the given user's email address using the <email>/token:<token> syntax.

    So to answer the question, a global OAuth token is not needed. My guess is either a different kind of token is being used (say an "OAuth token" versus an "API token") or the syntax is incorrect (say <email>:<token> versus <email>/token:<token>). Hope this is enough to get to get things working!

    0
  • Pete Kemp
    Comment actions Permalink

    Hi, we have this functioning however we were wondering if there is a way to not specify the port (as 8080) in the URL, and just have site.com/create_ticket, and also if it's possible to use SSL? I can't see anything in the tutorial about using SSL but it would be a welcome feature.

    0
  • Greg - Community Manager
    Comment actions Permalink

    Hi Pete Kemp! The tutorial that is provided here is essentially a framework of how to accomplish creating a ticket form. The portion of this that you're looking for is deploying and securing your pages, which would be outside the scope of what we would provide information about here at Zendesk. If you bring this to a backend/full-stack dev, they'll be able to get this going for you!

    0
  • Azhar
    Comment actions Permalink

    Hi,

    I implemented the above example for my custom ticket field and noticed that it is updating fine for a single word value but not working for multiple word value.

    E.g. :

    data = {'request': {'custom_fields': [{ "id": 360042537054, "value": ticket_type}] }}

    if 'ticket_type' value fetched = "Careers" --> Working Fine

    if 'ticket_type' value fetched = "Product Feedback or Questions" --> Not working fine

    0
  • Charles Nadeau
    Comment actions Permalink

    Hi Azhar,

    If your custom field is a dropdown list, then the value property of the custom_fields object should specify the tag name of the custom field option in Support. For example, if the option's display text in the agent interface is "HD 3000 color printer" and its tag is "hd_3000", you would set the custom field's value as follows:

      "custom_fields": [{"id": 21938362, "value": "hd_3000"}]

    See https://developer.zendesk.com/rest_api/docs/support/tickets#setting-custom-field-values.

    So the value attribute of each option in the HTML form should be the tag name of the corresponding custom field option in the agent interface. You can also get the tag names from the custom_field_options property of the ticket field object using the Ticket Fields API - https://developer.zendesk.com/rest_api/docs/support/ticket_fields.

    0

Please sign in to leave a comment.

Powered by Zendesk