Home > Blogs > VMware Developer Blog

API Tutorial – Getting Started with the Content Library APIs

This blog post is a part of the blog series published by the Content Library team. Please find all the blog posts by the team at this link.

This tutorial will go through the steps required to setup a development environment that uses the Content Library APIs.  At the end of this post you should be able to:

  • quickly run a Content Library API sample
  • setup a development environment to facilitate development and exploration using the Content Library APIs


Following instructions are for the Mac OS X, but are applicable to other platforms as well (with minimal platform specific changes).


  • VMware vCenter Server 6.0 installed.
  • VMware vCloud Suite SDK 6.0 for Java downloaded and extracted to a local directory. eg:
    $ cd ~/Downloads  $ unzip VMware-vCloud-Suite-SDK-Java-6.0.0-2561089.zip

    These samples are based on the following version of the SDK.

    VMware-vCloud-Suite-SDK-Java-6.0.0-2561089.zip  File size:55 MB  File type:zip  Release Date:2015-03-12  Build Number:2561089
  • a JDK (>=1.7).
  • The environment variable JAVA_HOME must be defined.
    $ export JAVA_HOME="/Library/Java/JavaVirtualMachines/jdk1.7.0_76.jdk/Contents/Home"


  • git – good to have, but even otherwise you can download the source-code directly.

Getting the API Samples and Executing Your First Content Library API Sample

  • You can get the sample code by cloning the content-library-api-samples git repository .
  • The sample code depends on the client libraries in the vCloud Suite SDK 6.0 for Java to be copied to the content-library-api-samples/lib directory.
  • The code samples use gradle for its build system. You don’t need gradle to be installed since gradlew does it for you.
    $ mkdir ~/my-projects  $ cd ~/my-projects  $ git clone https://github.com/vmware/content-library-api-samples.git  $ cd content-library-api-samples    $ cp -r ~/Downloads/VMware-vCloud-Suite-SDK-Java/client/lib .   $ ./gradlew installApp    $ ./build/install/content-library-api-samples/bin/content-library-api-samples  Enter vCenter Server hostname/IP: vcenter.example.com  Enter username: Administrator@vsphere.local  Enter password:   The number of libraries in this system is: 0  $

Setting up Your Development Environment

We will use Eclipse as the main IDE. gradle comes with a task to generate an Eclipse project file so we will use that to speed up the import. You could also use the Eclipse Gradle plugin.

./gradlew eclipse

Launch your Eclipse and import the content-library-api-samples directory as an Eclipse project.

Once imported, you will end up with something like this (click to zoom):



What you see here is a very simple API sample which uses Content Library APIs. It shows you how many libraries you have in your system.

/**   * A very simple API client which,   * <ul>   *     <li> logs in to the Content Library API </li>   *     <li> makes a Content Library API call to list the libraries   *          in the provided vCenter Server instance </li>   *     <li> prints the number of libraries from the result of the list call </li>   *     <li> logs out from the Content Library API </li>   * </ul>   */  public class LibraryCount {      public static void main(String[] args) throws Exception {          String vCenterSsoServer =                  IOUtil.read("Enter the hostname/IP for the vCenter SSO Server: ");          String username = IOUtil.read("Enter SSO username: ");          String password = IOUtil.readPassword("Enter SSO password: ");            ClsApiClient client =                  new ClsApiClient(vCenterSsoServer, username, password);          client.login();          try {              System.out.println("The number of libraries in this system is: " +                      client.library().list().size());          } finally {              client.logout();          }      }  }

Building Blocks

The ClsApiClient is a simplified wrapper around the Content Library core APIs that takes care of most of the boilerplate code required for establishing connections and getting authentication.

The Content Library core APIs expose four different categories of services:

Library Life Cycle

  • library (com.vmware.content.Library) : operations applicable to both subscribed and local libraries.
  • local library (com.vmware.content.LocalLibrary) : CRUD operations on local libraries.
  • subscribed library (com.vmware.content.SubscribedLibrary) : CRUD operations on subscribed libraries.

Library Item Life Cycle

  • item (com.vmware.content.library.Item) : CRUD operations on items.
  • storage (com.vmware.content.library.item.Storage) : listing storage properties of files associated with a library item.
  • download session (com.vmware.content.library.item.DownloadSession) : managing sessions to download content.
  • download session file (com.vmware.content.library.item.downloadsession.File) : managing files within a download session.
  • update session (com.vmware.content.library.item.UpdateSession) : managing sessions to update content.
  • update session file (com.vmware.content.library.item.updatesession.File) : managing files within an update session.

Configuration of the Content Library Service

  • configuration (com.vmware.content.Configuration) : system configuration of the Content Library (global configuration).

Available Content Library Extensions

  • type (com.vmware.content.Type) : returns all types currently supported natively by the Content Library. In the 6.0 release, the only supported extension is OVF. There is no mechanism to add third-party extensions in this release.

In the following blog posts, we will go through typical as well as advanced use cases of the Content Library APIs. This should be a good starting point for better understanding the API and for building much more sophisticated functionality on top of the Content Library core APIs.

More in This Series