GX Technology : Zendesk Scripts

All of the Zendesk Scripts are to be used to move content from one Zendesk instance to another – a lot of this data that is moved over is in the form of Help Centre content such as categories, sections, and articles. But we are also able to move over Dynamic Content and other Zendesk instance-specific data.


The Git repository for all of these scripts is: https://github.wdig.com/GXHelpSite/zd-motunui-theme and found in the deployment/ directory.


Within these scripts, you will need to receive an OAuth token from either the source Zendesk instance or from both the source and destination Zendesk instance. See below for instructions.


How to Receive an OAuth Token:

Steps to get a Token:

  1. In order to receive an OAuth token, you are required to be an Admin on the Zendesk instance, you will need to follow the documentation here:
    1. https://develop.zendesk.com/hc/en-us/articles/360001074348-Creating-and-using-OAuth-tokens-with-the-API
  2. Once you have a token available, you can add it to the "token" variable in the script you wish to use.
  3. Copy the entire script, with your token and all other required fields that Script might required filled in.
  4. Login to Zendesk, and Preview a theme in Guide. This is required as a lot of the themes require an instance of jQuery to be available.
  5. Right click the page you're on, and open Developer tools
  6. Paste the script into the developer console and run the script

***When you are done using this token, you need to delete it, go into your User on the Zendesk Instance and go into Security Settings and delete the token from there.


Master Update (master_update.js)

Description

This script initially looks at a Category ID from the source domain provided. It will loop through all of the categories in the destination domain and check to see if that category already exists. (It checks this by comparing the title of the category as that is the only attribute that can be consistent across Help Centres).


If there is not a category found in the destination domain with that same title, it will create a new one with all of the sections and articles in the source domain and clone it in it's entirety.


If there is a category found in the destination domain with that same title, it will move into the sections and check to see if all of the sections are in the destination domain compared to the source domain.

If there is a section in the source domain that is not in the destination domain, it will clone this and all of it's articles in it's entirety.


If there is a section found with that same title, it will move into the articles and check to see if all of the articles are in the destination domain compared to the source domain.

If there is an article in the source domain that is not in the destination domain, it will clone this exactly with all of the correct Manifest and Translation settings.


If you want to only look in certain sections for updates, you can set those configuration settings below and provide the section IDs that are of concern. The script will only look for updates within those sections and act accordingly.


Furthermore, if you wish to overwrite articles, you can set the configuration settings below to do that and provide the article ID from the source domain to overwrite. When this article is found, it will overwrite all of the Manifest and Translation settings for that article and overwrite the current article on the destination domain.

Initial Set-Up

When you initially run this script, you will have to get a couple of variables from the 'Support' section in both the Zendesk source domain and destination domain, you can do this by running this script on each instance that you are using. (Note: It has to be run from the 'Support' section of the Zendesk Instance)

$.ajax({
 method: "GET",
 url: domain + '/api/v2/guide/permission_groups.json',
 dataType: 'json',
 async: false,
 success: function (userSegmentData){
 console.log(userSegmentData);
 }
});


In the console, you will have to grab the permission group ID's that you are interested in and paste them below in the configuration. We are mainly concerned with the Manager permission ID and Manager and Agent permission ID in both the source and destination Zendesk instance. These ID's vary from instance to instance, which is why it is so important that we grab them, or the script will set the articles to the wrong permission settings.


Within this file, there are a few variables that you have to fill in for this script to operate properly, they are listed under 'CONFIGURATION SETTINGS'


var manager_only_permission_source = ''; ---- This variable is found from running the above script
var manageragent_permission_source = ''; ---- This variable is found from running the above script


var manager_only_permission_destination = ''; ---- This variable is found from running the above script
var manageragent_permission_destination = ''; ---- This variable is found from running the above script

//Configuration Settings / Variables
var sourceCategoryId = ''; ---- This variable is the category ID from the source Help Centre that you wish to use
var token = ''; ---- This is the OAuth token that you need to generate from https://developer.zendesk.com/requests/new on the source Help Centre


var sourceDomain = ''; ---- This is the source Help Centre domain
var destinationDomain = ''; ---- This is the destination Help Centre domain

//Cherrypick a section
var overwriteAllSections = true; ---- This boolean determines whether or not you want to only look at certain sections (cherrypick sections) when you run the script. Set this to false if that is the case
var overwriteSectionId = []; ---- If the above is false, add all of the section IDs from the source Help Centre in this array. ex: [123455, 1244331, 123414]. This will only look at those three sections

//Overwrite an article with id (destinationId)
var overwriteArticles = false; ---- This boolean determines whether or not you want to overwrite specific articles with new content from the source.
var overwriteArticleId = []; ---- If the above is true, you will have to add the article ID's from the source in here, and the script will overwrite all of the Manifest / Translation settings into the destination Help Centre.


Clone Help Centre (clone-helpcenter.js)

Description

This script is designed to clone an entire Help Centre, it will take all of the categories, all of the sections, and all of the articles from a source domain and copy it into a destination domain. It is fairly similar to the above script, but without all of the update functionality. This script also clones all categories as well while the above one cherrypicks a category and functions based off of that Category ID.

Initial Set-Up

When you initially run this script, you will have to get a couple of variables from the 'Support' section, you can do this by running this script on each Help Centre that you are using. (Note: It has to be run from the 'Support' section of the Help Centre:

$.ajax({
 method: "GET",
 url: domain + '/api/v2/guide/permission_groups.json',
 dataType: 'json',
 async: false,
 success: function (userSegmentData){
 console.log(userSegmentData);
 }
});


In the console, you will have to grab the permission group ID's that you are interested in and paste them below in the configuration. We are mainly concerned with the Manager permission ID and Manager and Agent permission ID in both the source and destination Zendesk instance. These ID's vary from instance to instance, which is why it is so important that we grab them, or the script will set the articles to the wrong permission settings.


Within this file, there are a few variables that you have to fill in for this script to operate properly: 


var manager_only_permission_source = ''; ---- This variable is found from running the above script
var manageragent_permission_source = ''; ---- This variable is found from running the above script


var manager_only_permission_destination = ''; ---- This variable is found from running the above script
var manageragent_permission_destination = ''; ---- This variable is found from running the above script


You will also have to generate an OAuth token as well as know the source domain and destination domain that you will be cloning.


Clone Dynamic Content (dynamic_content.js)

Description

This script is designed to clone (or cherrypick) Dynamic Content from one Zendesk Instance to another.


Since Dynamic Content is instance-wide, we are unable to create it for individual brands. All brands on a Zendesk instance will have access to the Dynamic Content created.

Initial Set-Up

Configuration Settings:

var sourceToken = "";
var destinationToken = "";



var sourceDomain = "";
var destinationDomain = "";


For this script, you are required to have authentication tokens generated from https://developer.zendesk.com/requests/new for both the source domain and the destination domain.


There is an additional configuration setting that is here: var targetDynamicContent = [];

This is used to cherrypick Dynamic Content from a source Zendesk Instance. If you wish to cherrypick Dynamic Content from the source Zendesk instance, just place the names/titles of the Dynamic Content into this array. ex:  ['hc_this_dynamic_content']


At the bottom of the script is a script to delete all Dynamic Content from a domain for testing purposes, it is commented out. Remove the comments and add the domain you wish to use to delete the Dynamic Content from.


There are three attributes that are required when creating Dynamic Content. You must provide the name, the default_locale_id, and the variants for the Dynamic Content.


For this script to work correctly, the default_locale_id in the source domain must be the same as the default_locale_id in the destination domain, as well as all of the variants, the destination domain must include all of the locales as the source domain.


Other Scripts

There are a number of other scripts in this repository – you will likely only need to use the above ones for the most part. A lot of the user scripts were quickly written just to achieve a single task and only ran once.

Attachments: