Please check your agent type and version and read on or switch to the right documentation.
Display Zendesk tickets
This section shows you how to create a smart collection to list the tickets of your Zendesk account.
Declare the Smart Collection Zendesk Tickets
First, we need to declare the smart collection in your project based on the API documentation. As an example, here the smart collection definition for Users:
Some fields are available for filtering or sorting using the Zendesk API. To allow this on the Forest UI, simply add the keywords isFilterable and isSortable in your field definition.
Implement the Smart Collection route
In the file routes/zendesk-tickets.js, we’ve created a new route to implement the API behind the Smart Collection.
The logic here is to list all the users of your Zendesk account.
Find more information about getTickets variable definition in the Github repository.
routes/zendesk-tickets.js
constexpress=require('express');const { PermissionMiddlewareCreator } =require('forest-express-sequelize');constrouter=express.Router();constpermissionMiddlewareCreator=newPermissionMiddlewareCreator('zendesk_tickets');const { getTickets } =require('../services/zendesk-tickets-service');// Get a list of Zendesk Ticketsrouter.get('/zendesk_tickets',permissionMiddlewareCreator.list(), (request, response, next) => {getTickets(request, response, next); });
Implement the get Route
The section above help you display the list of all Zendesk tickets. But you'll need to implement also the logic to display the information of a specific ticket.
This is going to be very similar. We just need to implement a new endpoint to get an individual ticket from the Zendesk API.
services/zendesk-tickets-services.js
asyncfunctiongetTicket(request, response, next) {return axios.get(`${ZENDESK_URL_PREFIX}/api/v2/tickets/${request.params.ticketId}?include=comment_count`, { headers: { Authorization:`Basic ${getToken()}`, }, } ).then(async (resp) => {let record =resp.data.ticket;// Serialize the result using the Forest Admin formatconstrecordSerializer=newRecordSerializer({ name:'zendesk_tickets', });constrecordSerialized=awaitrecordSerializer.serialize(record);response.send(recordSerialized); }).catch(next);}
routes/zendesk-tickets.js
const {getTickets,getTicket,} =require('../services/zendesk-tickets-service');// Get a Zendesk Ticketrouter.get('/zendesk_tickets/:ticketId',permissionMiddlewareCreator.details(), (request, response, next) => {getTicket(request, response, next); });