Woodshop
Search…
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:
forest/zendesk-tickets.js
1
const { collection } = require('forest-express-sequelize');
2
3
// Search on tickets => https://support.zendesk.com/hc/en-us/articles/203663206-Searching-tickets
4
collection('zendesk_tickets', {
5
actions: [],
6
fields: [{
7
field: 'id',
8
type: 'Number',
9
isFilterable: true,
10
}, {
11
field: 'created_at',
12
type: 'Date',
13
isSortable: true,
14
}, {
15
field: 'updated_at',
16
type: 'Date',
17
isSortable: true,
18
}, {
19
field: 'type',
20
type: 'Enum',
21
enums: ['problem', 'incident', 'question', 'task'],
22
isFilterable: true,
23
isSortable: true,
24
}, {
25
field: 'priority',
26
type: 'Enum',
27
enums: ['urgent', 'high', 'normal', 'low'],
28
isFilterable: true,
29
isSortable: true,
30
}, {
31
field: 'status',
32
type: 'Enum',
33
enums: ['new', 'open', 'pending', 'hold', 'solved', 'closed'],
34
isFilterable: true,
35
isSortable: true,
36
}, {
37
field: 'subject',
38
type: 'String',
39
isFilterable: true,
40
}, {
41
field: 'description',
42
type: 'String',
43
isFilterable: true,
44
}, {
45
field: 'comment_count',
46
type: 'Number',
47
}, {
48
field: 'is_public',
49
type: 'Boolean',
50
}, {
51
field: 'satisfaction_rating',
52
type: 'Json',
53
}, {
54
field: 'tags',
55
type: ['String'],
56
isFilterable: true, // not => filtering on array is not yet possible
57
}, ],
58
segments: [],
59
});
60
Copied!
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.
routes/zendesk-tickets.js
1
const express = require('express');
2
const { PermissionMiddlewareCreator } = require('forest-express-sequelize');
3
4
const router = express.Router();
5
const permissionMiddlewareCreator = new PermissionMiddlewareCreator('zendesk_tickets');
6
7
8
const {getTickets} = require('../services/zendesk-tickets-service');
9
10
// Get a list of Zendesk Tickets
11
router.get('/zendesk_tickets', permissionMiddlewareCreator.list(), (request, response, next) => {
12
getTickets(request, response, next);
13
});
Copied!

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
1
async function getTicket(request, response, next) {
2
return axios.get(`${ZENDESK_URL_PREFIX}/api/v2/tickets/${request.params.ticketId}?include=comment_count`, {
3
headers: {
4
'Authorization': `Basic ${getToken()}`
5
},
6
})
7
.then( async (resp) => {
8
let record = resp.data.ticket;
9
// Serialize the result using the Forest Admin format
10
const recordSerializer = new RecordSerializer({ name: 'zendesk_tickets' });
11
const recordSerialized = await recordSerializer.serialize(record);
12
response.send(recordSerialized);
13
})
14
.catch(next);
15
16
}
Copied!
routes/zendesk-tickets.js
1
const {getTickets, getTicket} = require('../services/zendesk-tickets-service');
2
3
// Get a Zendesk Ticket
4
router.get('/zendesk_tickets/:ticketId', permissionMiddlewareCreator.details(), (request, response, next) => {
5
getTicket(request, response, next);
6
});
Copied!