A set of Python scripts have been created to facilitate the bulk updating of organization properties and fields in Zendesk based on data from a CSV file.
The format of the CSV file that needs to be used for the Bulk Update script needs to contain three comma-delimited fields with the following data fields:
In order to use the Python scripts, your computer must have an appropriate version of Python installed, along with the required libraries and packages. The scripts were developed and tested with ActiveState’s ActivePython 3.4 for Windows, which can be downloaded and installed from http://www.activestate.com/activepython/downloads.
Once ActivePython has been installed, verify that the path to the Python executables have been added to the PATH system environment variable. To do so, press WIN + PAUSE/BREAK to bring up the System information window and click on “Advanced system settings”.
In the System Properties window that opens, click on the “Environment Variables…” button towards the bottom of the window:
Under the “Systems variables” section of the “Environment Variables” window, select the “Path” variable and click “Edit…” and verify that the path to the ActiveState Python directories have been added. By default, ActivePython 3.4 will be installed under C:\Python34 and you should see both C:\Python34 and C:\Python34\Scripts as shown below:
Once ActivePython 3.4 has been installed and the PATH system environment variable has been verified, open up a Command Prompt window in Administrator mode and run the following commands to install the required Python libraries:
pip install httplib2 pip install simplejson pip install zdesk
The first and second libraries are required for installing the Zendesk API Wrapper library for Python, zdesk. More information about the zdesk library can be found at: http://github.org/fprimex/zdesk.
Once all three of the libraries have been installed, copy the two Python scripts and the “_zendesk.cfg” configuration file template from \\corp-file-01\software$\Zendesk\Organization Bulk Update Tool to a directory on your local computer.
Before running the scripts, edit the “_zendesk.cfg” file and replace the three placeholder values in the “[zendesk]” section of the file with the appropriate values provided to you in the Zendesk Admin > Channels > API page of the Zendesk instance you will be running the scripts against.
Also in the “_zendesk.cfg” file, you will see two variables under the “[zdorgfields]” section called “properties” and “fields”. Both variables contain a space-delimited list of supported organization properties and fields that are available for each organization in the Zendesk instance. The organization properties are a set of default fields that every organization has in Zendesk while the organization fields are created when setting up a Zendesk instance. Please note that the name of the properties and fields are Zendesk property and field key names, not the title or displayed names.
If a new organization field has been created in the Zendesk instance, the new field also needs to be added to the list in order for the Bulk Update script to process data destined for the new field. If the field is not added to the configuration file, the Bulk Update script will return an error when trying to import data.
One last step that is required to use the Bulk Update script is to pull down organization data from the Zendesk instance to create a local cache file. The local cache file contains a table that stores the Customer ID value that has been used to reference customers in SalesLogix and the Zendesk ID assigned for all organizations in Zendesk. The Zendesk ID is required to work with organization objects in which the “external_id” has not been set to match the organization’s Customer ID. The cache file is also used to dramatically reduce the number of Zendesk API calls.
To create the local cache file, open up a Command Prompt window, change the current directory to the directory with the Python scripts and run:
By default, the script will read in the “_zendesk.cfg” file in the current directory and create a file called “zdorg.sqlite” in the same directory. If the script runs successfully, it should finish pulling down the data within 10-15 seconds. If you don’t frequently use the Bulk Update script or know there has been a lot of organization data changes in Zendesk, it is highly recommended to run the cache file creation script before running the Bulk Update script.
Once the “zdorg.sqlite” cache file has been created, you can now run the script against an appropriately formatted CSV file by running the following command:
python zdorgbulkupdate.py -f <CSV File Name>
Replace “<CSV File Name>” with the name of the CSV file to import. The script reads in each record from the file, converts it into dictionary data type that is then passed to the Zendesk API Wrapper, which converts it into JSON and posted to the Zendesk API. The Bulk Update script will report any errors recording organization records that could not be found in the cache file, property or field key names that are not valid or any other problems with the CSV file or with the Zendesk API calls.