Get the organization_id or user_id from Zendesk Guide

11 Comentários

  • Dave Dyson
    Hi Nadine! 
     
     
    0
  • Nadine RAISS

    Hello Dave, 

    Any suggestions ?

    0
  • Dave Dyson
    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/
     
    0
  • Nadine RAISS

    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. 

    0
  • Dave Dyson
    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
     
    0
  • Nadine RAISS

    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}).

    0
  • John Witt

    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();})
     } 
     }

    0
  • Dave Dyson
    Thanks for sharing your solution, John!
    0
  • Nadine RAISS

    Thank you for your answer John! I will try the same logic on my side :)

    0
  • David Bjorgen

    @... 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)?

    0
  • John Witt

    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.  

    0

Por favor, entrar para comentar.

Powered by Zendesk