Recent searches
No recent searches
User Segment API not working for end user
Answered
Posted Jan 06, 2023
I am trying to pull which user segment the current logged in end user belongs to. I am currently using the "GET /api/v2/users/me" to retrieve the current users ID and using that ID to try to pull the user segments. (Code below, it's working for admins but not for end users, I also masked the email and tokenID for this forum purposes)
$.getJSON('/api/v2/users/me', function(data) {
console.log("got data", data);
getUserSegment(data.user.id);
});
function getUserSegment(userID){
// fetch UserSegment API.
$.ajax
({
url: '/api/v2/help_center/users/'+userID+'/user_segments.json',
headers: {
"Authorization": "Basic email-address/token:tokenID"
},
beforeSend: function (xhr){
xhr.setRequestHeader('Authorization', "Basic "+ btoa("email-address/token:tokenID"));
},
secure: true,
type: 'GET',
contentType: "application/json",
dateType: 'json',
success: function(data){
data.user_segments.forEach(function(element, index) {
alert(element.name);
});
}
});
}
Please help, not sure why it's not working.
0
5
5 comments
Gaby Bitar
Ahmed Zaid is there no way to determine what User Segments an end-user belongs to?
0
Gaby Bitar
Ahmed Zaid Thank you, it worked!
0
Raphaël Péguet - Officers.fr
Hi Gaby Bitar!
Did you find out how to do specific things depending on the user segment please?
I am looking for the same thing, :)
Best regards!
Raphaël
0
Gaby Bitar
Hi Raphaël Péguet - Officers.fr,
Yes I did, I used the Users/me api to grab the current users ID number and add that to a variable - https://developer.zendesk.com/api-reference/ticketing/users/users/#show-self
Then I used that userID to call the user segments api and list the current users User Segments.
/api/v2/help_center/users/{user_id}/user_segments.json
(https://developer.zendesk.com/api-reference/help_center/help-center-api/user_segments/#list-user-segments)
I hope this helps!
0
Raphaël Péguet - Officers.fr
Hi Gaby Bitar !
Thank you very much, it helps I will try after some rest 😛
Best regards,
Raphaël
0