Create a Data Access Object for Zendesk Data using JDBI

Ready to get started?

Download for a free trial:

Download Now

Learn more:

Zendesk JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Zendesk including Tickets, Groups, Users, Schedules, and more!



A brief overview of creating a SQL Object API for Zendesk data in JDBI.

JDBI is a SQL convenience library for Java that exposes two different style APIs, a fluent style and a SQL object style. The CData JDBC Driver for Zendesk integrates connectivity to live Zendesk data in Java applications. By pairing these technologies, you gain simple, programmatic access to Zendesk data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read and write Zendesk data.

Create a DAO for the Zendesk Tickets Entity

The interface below declares the desired behavior for the SQL object to create a single method for each SQL statement to be implemented.

public interface MyTicketsDAO { //insert new data into Zendesk @SqlUpdate("INSERT INTO Tickets (Industry, Subject) values (:industry, :subject)") void insert(@Bind("industry") String industry, @Bind("subject") String subject); //request specific data from Zendesk (String type is used for simplicity) @SqlQuery("SELECT Subject FROM Tickets WHERE Industry = :industry") String findSubjectByIndustry(@Bind("industry") String industry); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Zendesk

Collect the necessary connection properties and construct the appropriate JDBC URL for connecting to Zendesk.

Connecting to Zendesk

To connect, set the URL and provide authentication. The URL is your Zendesk Support URL: https://{subdomain}.zendesk.com.

Authenticating to Zendesk

You can authenticate using the Basic or OAuth methods.

Using Basic Authentication

To use Basic authentication, specify your email address and password or your email address and an API token. Set User to your email address and follow the steps below to provide the Password or ApiToken.

  • Enable password access in the Zendesk Support admin interface at Admin > Channels > API.
  • Manage API tokens in the Zendesk Support Admin interface at Admin > Channels > API. More than one token can be active at the same time. Deleting a token deactivates it permanently.

Using OAuth Authentication

See the Getting Started guide in the CData driver documentation for an authentication guide.

Built-in Connection String Designer

For assistance in constructing the JDBC URL, use the connection string designer built into the Zendesk JDBC Driver. Either double-click the JAR file or execute the jar file from the command-line.

java -jar cdata.jdbc.zendesk.jar

Fill in the connection properties and copy the connection string to the clipboard.

A connection string for Zendesk will typically look like the following:

jdbc:zendesk:URL=https://subdomain.zendesk.com;User=my@email.com;Password=test123;InitiateOAuth=GETANDREFRESH

Use the configured JDBC URL to obtain an instance of the DAO interface. The particular method shown below will open a handle bound to the instance, so the instance needs to be closed explicitly to release the handle and the bound JDBC connection.

DBI dbi = new DBI("jdbc:zendesk:URL=https://subdomain.zendesk.com;User=my@email.com;Password=test123;InitiateOAuth=GETANDREFRESH"); MyTicketsDAO dao = dbi.open(MyTicketsDAO.class); //do stuff with the DAO dao.close();

Read Zendesk Data

With the connection open to Zendesk, simply call the previously defined method to retrieve data from the Tickets entity in Zendesk.

//disply the result of our 'find' method String subject = dao.findSubjectByIndustry("Floppy Disks"); System.out.println(subject);

Write Zendesk Data

It is also simple to write data to Zendesk, using the previously defined method.

//add a new entry to the Tickets entity dao.insert(newIndustry, newSubject);

Since the JDBI library is able to work with JDBC connections, you can easily produce a SQL Object API for Zendesk by integrating with the CData JDBC Driver for Zendesk. Download a free trial and work with live Zendesk data in custom Java applications today.