Skip to main content

Java SDK

We now present a high-level Java API as a type-safe and gentle wrapper for the OpenMetadata backend. The open-source OpenMetadata SDK for Java simplifies provisioning, managing, and using OpenMetadata resources from the Java application code.
The OpenMetadata SDK for Java libraries build on top of the underlying OpenMetadata REST API, allows you to use those APIs through familiar Java paradigms. However, you can always use the REST API directly from Java code, if you prefer to do so.
You can find the source code for the OpenMetadata libraries in the GitHub repository. As an open-source project, contributions are always welcome! You can add the below Maven Dependency for the OpenMetadata Java SDK.

Connect to the OpenMetadata Server

To connect to your OpenMetadata server, you need:
  • Server URL: The URL where your OpenMetadata instance is running, ending in /api. For example, http://localhost:8585/api.
  • Access token: A JSON Web Token (JWT) for a user or bot. See Authentication to learn how to get one.
Tune the connection with these options. Timeouts are in milliseconds, and header adds a custom header to every request:

Authenticate with a JWT Token

The Java SDK authenticates with a JWT access token that you pass to accessToken(...). This is the same for every sign-in method on your OpenMetadata server, including Google, Okta, Auth0, Azure, and custom OpenID Connect (OIDC). Generate a bot token or a personal access token in OpenMetadata and use it here. If your server doesn’t require authentication, leave out accessToken(...).

Use the Fluent API

The fluent classes, such as Tables, Users, and Teams, work with a default client. Register your client once with OM.init, and the fluent classes use it:

Use the Service Clients

Every entity type has a service on the client, such as client.tables(), client.users(), and client.dashboards(). These services offer methods such as create, get, getByName, list, update, delete, and restore. Below are some examples:
The following examples show how to call an API:
  • Create a table
  • Get a table by fully qualified name
  • Search
The search call returns the raw JSON response from the server as a string.

Handle Errors

When the server returns an error, the SDK throws an OpenMetadataException. Use getStatusCode() to see which error it was:

Bulk Create with Conflict Outcomes

TestCases and GlossaryTerms in org.openmetadata.sdk.fluent can create several entities in one request and return a typed BulkCreateResult with an outcome for every input.
Conflict policies:
  • SKIP: The default. Inputs whose fully qualified name already exists, or that repeat inside the request, are reported as skipped. All other valid inputs are created.
  • FAIL: Conflicting inputs are reported as failed. All other valid inputs are still created. This is not an all-or-nothing request.
Existing and soft-deleted entities are never overwritten or restored. Result:
  • getCreatedCount(), getSkippedCount(), and getFailedCount(): Totals for the request.
  • getResults(): One outcome per input, in request order. Each has an index, a status, and the fully qualified name. Created entities also have an ID. Skipped and failed inputs have a reason (ALREADY_EXISTS, DUPLICATE_IN_REQUEST, or VALIDATION_ERROR) and a message.
Request-level errors still throw OpenMetadataException. Bulk create requires a server that supports the onConflict parameter. The service overload client.testCases().createMany(requests) is unchanged and still returns the list of created entities.

More examples

Review the OpenMetadata Java SDK examples for more usage patterns.