Get the organization_id or user_id from Zendesk Guide
Hello,
We have the following structure: An organization has a set of products. We would like to have a unique drop-down field for the products assigned to each organization.
We have the following need: The goal is to show the list of products to the customer when he/she creates a ticket based on the organization he/she is belonging to.
What we tried so far:
- Creating the list of products for each organization as tags (Which answer the uniqueness of the field) - DONE
- Creating a custom drop-down field with all the products of all the organizations - DONE
- Creating a script to compare the custom drop down field (All products) with the tags of the organization the customer is affiliated to - BLOCKED
To be able to solve the third step, we need to make a REST API call to get the list of tags of an organization based on the organization_id or the user_id. However, we have no idea how to fetch this from the Guide.
Any ideas? Or maybe any other solutions to our problem?
-
Hi Nadine!
-
Hello Dave,
Any suggestions ? -
Hi again Nadine -- my apologies! My previous response was... incomplete.
Here's the REST API endpoint you'd want to use to get the organization tags, using the organization ID:
https://developer.zendesk.com/api-reference/ticketing/organizations/organizations/#show-organization
If you haven't used the API before, here's some introductory information: https://developer.zendesk.com/api-reference/ticketing/introduction/
-
Hello Dave,
Thank you for your answer. I am aware of the REST API endpoint. It will be exactly the one that I will use for this scenario. My main problem is how to get either the organization_id or user_id from the Guide. -
Hi Nadine,
In the Help Center, you can get the user ID via the User object: https://developer.zendesk.com/documentation/help_center/help-center-templates/objects/#user-object
-
Hello Dave,
I am not able to retrieve the user_id as I want to use it in the script in the new request page (Not an available property). The user_id will be used to get the organization_id with the REST API (GET/api/v2/end_users/{user_id}). Then, I will user the organization_id to fetch the tags (GET /api/v2/organizations/{organization_id}). -
Hello Nadine,
I had the same issue. It used to be that you could access the HelpCenter object on any of the templates, but now it is only accessible via the script.js file. That object has a user field which lists organizations and tags - you can see it in the JS console window by typing HelpCenter. The problem is I haven't found a way to pass data from the .js file to any of the templates, but you can mask certain fields in the templates. In my case I blocked the ability to submit a ticket if the end user is not part of company, meaning I can have internal users submit tickets through Guide without being agents. In the future when we open the helpcenter to everyone I blocked specific ticket forms for internal and external users. This comments in this document provided the best help for me get this to work, and in one of the examples they searched Organization tags (I assume you'd need to div where the product is selected): https://support.zendesk.com/hc/en-us/articles/4408886229146-How-can-I-hide-ticket-forms-based-on-a-user-s-organization-?page=1#comments.
My code, where xxx is the Organization name:
document.addEventListener('DOMContentLoaded', function() {// This line of code ensures it's only in the ticketing template, otherwise it will fail to obtain the parameters below and block MyProfile from working.
if(document.querySelector("a.nesty-input")){
//This code currently blocks non-xxx users from submitting tickets
if (HelpCenter.user.organizations[0].name !== "xxx"){
document.querySelector('.nav-wrapper-desktop').style.display = "block";
document.querySelector('.nav-wrapper-desktop').style.visibility = "hidden";
// Once end users are allowed to view the HelpCenter, we should block internal forms (code already here).
// If additional forms are added and external, they should be added here.
document.querySelector('#request_issue_type_select option[value="6037656308123"]').remove();
document.querySelector('.nesty-panel').addEventListener('DOMNodeInserted', function(event) {
event.target.querySelector('li[id="6037656308123"]').remove();})
} else {
// This code blocks the client facing form for xxx employees.
document.querySelector('#request_issue_type_select option[value="6037733904923"]').remove();
document.querySelector('.nesty-panel').addEventListener('DOMNodeInserted', function(event) {
event.target.querySelector('li[id="6037733904923"]').remove();})
}
} -
Thanks for sharing your solution, John!
-
Thank you for your answer John! I will try the same logic on my side :)
-
@... The {{user}} object is not available on most pages. I'm in the same position as Nadine, where I need to located the current user ID in order to look up their organizations, and more. I'm a bit surprised that the User ID is not available in the {{HelpCenter.user}} object.
Is there an easy way to locate the ID for the current user, or even the organization ID(s)?
-
I mentioned this in my ticket that I raised. It used to be that they made the HelpCenter object available in all templates, but now it's only available in the script.js. If you view-source you can see the code at the bottom of each page where they update the HelpCenter object and mention not to use that object as it can always be removed. The userid is available in the HelpCenter object as well as the user's organization id, but you can only access it in the script.js file.
@... An easy solution, assuming not memory/CPU intensive, is to ensure the user object is available in all templates.
Please sign in to leave a comment.
11 Comments