Woodshop
Search…
Bonus: Direct link to Zendesk + change priority of a ticket

Create a Direct Link to Zendesk

The next step is to build a direct link to the Zendesk Ticket using a URL. We are going to implement a smart field for this. To build the URL, we simply use Zendesk's convention: ZENDESK_URL_PREFIX/agent/tickets/ticketId
forest/zendesk_tickets.js
1
const ZENDESK_URL_PREFIX = `https://${process.env.ZENDESK_SUBDOMAIN}.zendesk.com`;
2
3
collection('zendesk_tickets', {
4
actions: [],
5
fields: [{
6
field: 'direct_url',
7
type: 'String',
8
get: (ticket) => {
9
return `${ZENDESK_URL_PREFIX}/agent/tickets/${ticket.id}`;
10
},
11
},
12
...
13
],
14
segments: [],
15
});
Copied!
Once the smart field is added, just set up the Display Widget in Forest UI to allow the display of the URL as a Link:

Change the priority of a ticket

Let's say your operations team wants to change the priority of Zendesk tickets directly from Forest Admin.
For doing so, let's create a simple Smart Action like this:
forest/zendesk_tickets.js
1
const { collection } = require('forest-express-sequelize');
2
3
const ZENDESK_URL_PREFIX = `https://${process.env.ZENDESK_SUBDOMAIN}.zendesk.com`;
4
5
// Search on tickets => https://support.zendesk.com/hc/en-us/articles/203663206-Searching-tickets
6
collection('zendesk_tickets', {
7
actions: [{
8
name: 'Change Priority',
9
type: 'single',
10
endpoint: '/forest/actions/zendesk-ticket-change-priority',
11
fields: [
12
{
13
field: 'New Ticket Priority',
14
description: 'What is the new priority?',
15
type: 'Enum',
16
enums: ['urgent', 'high', 'normal', 'low'],
17
isRequired: true
18
},
19
],
20
}],
21
fields: [
22
...
23
],
24
segments:[]
25
}
Copied!
Implement the updateTicket service according to the Zendesk API:
services/zendesk-tickets-service.js
1
async function udpateTicket(ticketId, newValues) {
2
const body = {
3
ticket: newValues
4
};
5
return axios.put(`${ZENDESK_URL_PREFIX}/api/v2/tickets/${ticketId}`,
6
body,
7
{
8
headers: {
9
'Authorization': `Basic ${getToken()}`
10
},
11
}
12
)
13
.then( async (resp) => {
14
let record = resp.data.ticket;
15
return record;
16
})
17
}
Copied!
And now, we need to implement the route to handle this Smart Action:
routes/zendesk_tickets.js
1
const {getTickets, getTicket, udpateTicket} = require('../services/zendesk-tickets-service');
2
3
router.post('/actions/zendesk-ticket-change-priority', permissionMiddlewareCreator.smartAction(), (request, response, next) => {
4
const ticketId = request.body.data.attributes.ids[0];
5
const newValues = {
6
priority: request.body.data.attributes.values['New Ticket Priority'],
7
};
8
9
udpateTicket(ticketId, newValues)
10
// eslint-disable-next-line no-unused-vars
11
.then(async function (recordUpdated) {
12
response.send({
13
success: 'Ticket Priority changed!',
14
});
15
})
16
.catch(next);
17
});
Copied!
You now have full integration with Zendesk! To go further, please check our Github repository and explore how to:
  • Get the Assignee, Submitter & Requester users for a Zendek Ticket
  • Get the Zendesk User for a User
  • Get the requested tickets for a Zendesk User
  • and more...
Last modified 8mo ago