Ready to get started?

Download a free trial of the Asana Driver to get started:

 Download Now

Learn more:

Asana Icon Asana JDBC Driver

Rapidly create and deploy powerful Java applications that integrate with Asana.

Create a Data Access Object for Asana Data using JDBI



A brief overview of creating a SQL Object API for Asana 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 Asana integrates connectivity to live Asana data in Java applications. By pairing these technologies, you gain simple, programmatic access to Asana data. This article walks through building a basic Data Access Object (DAO) and the accompanying code to read Asana data.

Create a DAO for the Asana projects 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 MyprojectsDAO { //request specific data from Asana (String type is used for simplicity) @SqlQuery("SELECT WorkspaceId FROM projects WHERE Archived = :archived") String findWorkspaceIdByArchived(@Bind("archived") String archived); /* * close with no args is used to close the connection */ void close(); }

Open a Connection to Asana

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

You can optionally set the following to refine the data returned from Asana.

  • WorkspaceId: Set this to the globally unique identifier (gid) associated with your Asana Workspace to only return projects from the specified workspace. To get your workspace id, navigate to https://app.asana.com/api/1.0/workspaces while logged into Asana. This displays a JSON object containing your workspace name and Id.
  • ProjectId: Set this to the globally unique identifier (gid) associated with your Asana Project to only return data mapped under the specified project. Project IDs can be found in the URL of your project's Overview page. This will be the numbers directly after /0/.

Connect Using OAuth Authentication

You must use OAuth to authenticate with Asana. OAuth requires the authenticating user to interact with Asana using the browser. See the "Getting Started" chapter of the help documentation for a guide to using OAuth.

Built-in Connection String Designer

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

java -jar cdata.jdbc.asana.jar

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

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

jdbc:asana:OAuthClientId=YourClientId;OAuthClientSecret=YourClientSecret;CallbackURL='http://localhost:33333';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:asana:OAuthClientId=YourClientId;OAuthClientSecret=YourClientSecret;CallbackURL='http://localhost:33333';InitiateOAuth=GETANDREFRESH"); MyprojectsDAO dao = dbi.open(MyprojectsDAO.class); //do stuff with the DAO dao.close();

Read Asana Data

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

//disply the result of our 'find' method String workspaceId = dao.findWorkspaceIdByArchived("true"); System.out.println(workspaceId);

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