You can use the Profiles API in Zendesk apps to retrieve profiles associated with users. The Profiles API accepts a Zendesk user id in GET requests to identify the user:
GET /api/v2/users/{user_id}/profiles
In the Zendesk Apps framework, you can get a Zendesk user id from the User object. The User object is available in all app locations in Support. The User object can also be a property of other objects in the framework. For example, the ticket.requester property of the Ticket object is a User object.
This article provides a sample function for a Zendesk app that gets the profiles associated with the ticket requester.
Example
Details
-
App location in Support: Ticket sidebar
-
Zendesk user id: The ticket requester
JavaScript function for app
(function(){
// create ZAF client
const client = ZAFClient.init();
// get the Zendesk user id of the ticket's requester
client.get('ticket.requester.id')
.then(function (data) {
user_id = data['ticket.requester.id'];
return user_id;
})
// make the API request
.then(function (user_id) {
const settings = {
type: 'GET',
url: '/api/v2/users/' + user_id + '/profiles'
};
client.request(settings)
.then(function (data) {
for (let profile of data['profiles']) {
console.log(profile);
}
})
})
.catch(function () {
console.error('Error');
});
})();
Response
The function displays the profiles in the browser console:
How it works
Because framework requests are asynchronous and some requests must follow others, the function consists of a promise chain.
Preliminaries
The function starts by creating a ZAF client to work with the framework APIs:
const client = ZAFClient.init();
Get the Zendesk user id
Next, the function gets the Zendesk user id of the person requesting support in the ticket, then returns the id to the next function in the chain:
client.get('ticket.requester.id')
.then(function (data) {
user_id = data['ticket.requester.id'];
return user_id;
})
The function uses the client.get(path)
framework method to call the framework API. See Working with framework APIs.
Get the profiles
Finally, the function makes a request to the Profiles API and displays the profiles in the browser console. The function uses the client.request()
framework method to call the API. See Working with requests.
.then(function (user_id) {
const settings = {
type: 'GET',
url: '/api/v2/users/' + user_id + '/profiles'
};
client.request(settings)
.then(function (data) {
for (let profile of data['profiles']) {
console.log(profile);
}
})
})
2 Comments
Hi! @Charles Nadeau! Thanks to this kind guide, I was able to study all of Bulid your first Support app.
We are currently using Profiles and Events of Zendesk Sunshine App.
I wonder if you have any plans to provide an app guide or file to view the contents of Zendesk Sunshine as shown in the image below.
The source of the image is https://github.com/zendesk/events-search
Hi Jongwoo. Are you asking if the custom app's functionality that you referenced will be incorporated into the native product? If that's the question, there will no doubt be refinements with how this information is displayed in the agent interface over time but I can't say if it will appear exactly that way. Please clarify if I'm off base here.
Also, check out Getting started with Sunshine profiles - it might give some additional details around Profiles and Events that you fine useful. Thanks!
Please sign in to leave a comment.