Within this section you will find some example implementations. We provide examples for the usage of our api and also how to implement the data handling like hashing and encryption.
This is the multi-page printable view of this section. Click here to print.
Examples
- 1: Example Golang
- 2: Example Python
- 3: Example Java
1 - Example Golang
Introduction and project setup
Go (Golang) is a statically typed, compiled programming language developed by Google, known for its simplicity, efficiency, and excellent concurrency support, making it ideal for building scalable web services, APIs, and microservices. To manage project dependencies in Go, you use Go modules. You can initialize a new Go module in your project directory by running the terminal command go mod init <module-name>, where <module-name> is typically your repository URL (e.g., github.com/username/project). This creates a go.mod file that tracks your dependencies. When you import packages and run go mod tidy, Go automatically downloads and manages the required dependencies. Go’s module system ensures reproducible builds and proper version management. You can build your project with go build and run it directly with go run main.go. This approach keeps your projects organized and ensures consistent dependency management across different environments.
Lets go
We highly recommend to use a unix based development environment. This is not only possible by using linux or macOS but also by installing Linux Subsystem for Windows. If you use a plan windows you might need to adapt in certain steps.
Generate API code
For golang we recommend using ogen, to generate client code required to interact with the API.
mkdir omniac-client
cd omniac-client
go mod init github.com/yourusername/omniac-client
Now add the following to your generated go.mod file to add the dependency ogen:
module o4b_client_test
go 1.25.3
tool github.com/ogen-go/ogen/cmd/ogen
require (
[...]
)
Now run go mod tidy and then create a generate.go file with the following content:
package main
//go:generate go tool ogen --target pkg/o4b --package o4b --clean openapi.yaml
If you now place the omniac Business OpenAPI specification as openapi.yaml in your project root, you can generate the API client with the following command:
go generate
Authentication setup
Now create a main.go file and import the generated code to configure the client. You will need the url as well as your api key. This code needs to be executed before any api call.
package main
import (
"context"
omniac "o4b_client_test/pkg/o4b"
)
type APIKeyProvider struct {
ApiKey string
}
func (a APIKeyProvider) ApiKeyAuth(ctx context.Context, operationName omniac.OperationName) (omniac.ApiKeyAuth, error) {
return omniac.ApiKeyAuth{APIKey: a.ApiKey}, nil
}
func main() {
sec := APIKeyProvider{
ApiKey: "your_api_key_here",
}
client, err := omniac.NewClient("https://api.omniac.de", sec)
if err != nil {
panic(err)
}
}
Get tenant info
After initializing the api instance you can use the GetTenant function of your client to get information about your tenant.
[...]
ctx := context.Background()
tenantRes, err := client.GetTenant(ctx)
if err != nil {
panic(err)
}
switch res := tenantRes.(type) {
case *omniac.Tenant:
fmt.Println(res)
case *omniac.GetTenantBadRequest:
fmt.Println("Bad Request:", res)
case *omniac.GetTenantUnauthorized:
fmt.Println("Unauthorized:", res)
case *omniac.GetTenantInternalServerError:
fmt.Println("Internal Server Error:", res)
default:
fmt.Println("Unexpected response type")
}
Add profile to tenant
In order to start the monitoring of attributes and to receive alerts you need to configure a user for your tenant. After successfully creating the profile, you can start adding attributes.
[...]
profileRes, err := client.CreateProfile(ctx, &omniac.ProfileCreateRequest{
UserLanguage: omniac.NewOptString("de"),
Name: "test",
})
if err != nil {
panic(err)
}
var profile *omniac.Profile
switch res := profileRes.(type) {
case *omniac.Profile:
profile = res
fmt.Println(res)
case *omniac.CreateProfileBadRequest:
fmt.Println("Bad Request:", res)
case *omniac.CreateProfileUnauthorized:
fmt.Println("Unauthorized:", res)
case *omniac.CreateProfileInternalServerError:
fmt.Println("Internal Server Error:", res)
default:
fmt.Println("Unexpected response type")
}
attributeRes, err := client.ReplaceAttributes(ctx, []omniac.AttributeCreateRequest{
{
Type: "email",
Value: "test@example.com",
}},
omniac.ReplaceAttributesParams{
ProfileID: profile.ID,
})
if err != nil {
panic(err)
}
switch res := attributeRes.(type) {
case *omniac.ReplaceAttributesOK:
fmt.Println(res)
case *omniac.ReplaceAttributesBadRequest:
fmt.Println("Bad Request:", res)
case *omniac.ReplaceAttributesUnauthorized:
fmt.Println("Unauthorized:", res)
case *omniac.ReplaceAttributesInternalServerError:
fmt.Println("Internal Server Error:", res)
default:
fmt.Println("Unexpected response type")
}
Create multiple profiles as a batch
In addition to the option of creating individual profiles, omniac Business also offers the ability to create up to 500 profiles with attributes at the same time.
batchProfileRes, err := client.CreateProfiles(ctx, []omniac.ProfileCreateBatchRequest{
{
UserLanguage: omniac.NewOptString("de"),
Name: "batch_test_1",
Attributes: []omniac.AttributeCreateRequest{
{
Type: "email",
Value: "test@example.com",
},
},
},
{
UserLanguage: omniac.NewOptString("en"),
Name: "batch_test_2",
Attributes: []omniac.AttributeCreateRequest{
{
Type: "email",
Value: "test2@example.com",
},
},
},
})
if err != nil {
panic(err)
}
switch res := batchProfileRes.(type) {
case *omniac.CreateProfilesCreated:
fmt.Println(res)
case *omniac.CreateProfilesBadRequest:
fmt.Println("Bad Request:", res)
case *omniac.CreateProfilesUnauthorized:
fmt.Println("Unauthorized:", res)
case *omniac.CreateProfilesInternalServerError:
fmt.Println("Internal Server Error:", res)
default:
fmt.Println("Unexpected response type")
}
Get alerts
After waiting some minutes alerts will appear, if there are any leaks found. You can pull them by using the getprofile function with your profile.id. The two parameters after the profileID let you also return the users attributes (hashed and encrypted) as well as the alerts.
[...]
alertRes, err := client.GetAlerts(ctx, omniac.GetAlertsParams{
ProfileID: omniac.NewOptString(profile.ID),
})
if err != nil {
panic(err)
}
switch res := alertRes.(type) {
case *omniac.GetAlertsOK:
fmt.Println(res.Data)
case *omniac.GetAlertsBadRequest:
fmt.Println("Bad Request:", res)
case *omniac.GetAlertsUnauthorized:
fmt.Println("Unauthorized:", res)
case *omniac.GetAlertsInternalServerError:
fmt.Println("Internal Server Error:", res)
default:
fmt.Println("Unexpected response type")
}
Provide a push alert endpoint
To get notified even faster, we provide a push api for new alerts. As soon as something is found, we will publish the alert into your system. This is done over a HTTP-call. The delivery will be marked as done on our side as soon as your api returns a 2xx http status code.
To use this feature, you need to contact us, so we can enable the feature for your tenant.
2 - Example Python
Introduction and project setup
Python is a versatile, high-level programming language praised for its readability and extensive libraries, making it ideal for web development, data analysis, and automation. To manage project-specific dependencies and avoid conflicts, it’s best practice to use a virtual environment. You can create one in your project directory by running the terminal command python -m venv .venv, where .venv is the name of your environment folder. Once created, you must activate it. On Windows, use .venv\Scripts\activate, and on macOS or Linux, use source .venv/bin/activate. After activation, your command prompt will change to show the environment’s name, and any packages you install with pip will be isolated to that specific project. When you’re finished, simply type deactivate to return to your global Python context. This process keeps your projects tidy and reproducible.
Recommendation: codium for development
VSCodium, the open-source build of VS Code, is an excellent choice for Python development. After installing it, the first step is to add the official Python extension from the marketplace, which unlocks powerful features like IntelliSense (code completion), linting (error checking), and debugging. Open your project folder in Codium (File > Open Folder...). The editor will often automatically detect your virtual environment, but you can always manually select it by opening the Command Palette (Ctrl+Shift+P), searching for “Python: Select Interpreter”, and choosing the Python executable located inside your myenv folder. This correctly configures Codium to use your project’s isolated packages. You can then use the integrated terminal (Ctrl+ ) to run your scripts, install new packages with pip`, and manage version control with Git, all without leaving the editor. With the ability to set breakpoints and step through your code using the ‘Run and Debug’ panel, Codium provides a comprehensive and streamlined environment for building and testing your Python tool from start to finish.
Lets go
We highly recommend to use a unix based development environment. This is not only possible by using linux or macOS but also by installing Linux Subsystem for Windows. If you use a plan windows you might need to adapt in certain steps.
Generate venv
As shown above, we will use a venv. To do so we just execute the following commands.
python3 -m venv .venv
source .venv/bin/activate
Generate API code
As recommended in our documentation we use openapi-generator to generate the necessary code to interact with the API. This ensures safety and will break on critical errors as soon as possible.
mkdir api
openapi-generator-cli generate -i openapi.yaml -g python -o /api
cd api
pip install .
touch client.py
With your newly created client.py file you can now import the generated code and configure the client. You need the URL as well as your API-Key. This code has to be executed before issuing any api call.
import openapi_client as omniac
configuration = omniac.Configuration(
host = "https://api.omniac.de"
)
configuration.api_key["ApiKeyAuth"] = "YOUR_API_KEY_GOES_HERE"
Get tenant info
Now you can initialize a api instance of the TenantAPI. Use the gettenant function of your api_client to get information about your tenant.
import openapi_client as omniac
[...]
with omniac.ApiClient(configuration) as api_client:
api_instance = omniac.TenantApi(api_client)
api_instance = omniac.TenantApi(api_client)
try:
tenant = api_instance.get_tenant()
print(tenant)
except Exception as e:
print(f"Error: {e}")
Add profile to tenant
In order to start the monitoring of attributes and to receive alerts you need to configure a user for your tenant. After successfully creating the profile, you can start adding attributes.
import openapi_client as omniac
[...]
with omniac.ApiClient(configuration) as api_client:
api_instance = omniac.ProfileApi(api_client)
newProfile = omniac.ProfileCreateRequest(
name="test",
user_language="de",
)
try:
profile = api_instance.create_profile(newProfile)
print(profile.id)
api_response = api_instance.replace_attributes(profile.id, [
omniac.AttributeCreateRequest(
type="email",
value="test@example.com"
)
])
print(api_response)
except Exception as e:
print(f"Error: {e}")
Create multiple profiles as a batch
In addition to the option of creating individual profiles, omniac Business also offers the ability to create up to 500 profiles with attributes at the same time.
import openapi_client as omniac
[...]
with omniac.ApiClient(configuration) as api_client:
api_instance = omniac.ProfileApi(api_client)
profile_create_batch_request = [omniac.ProfileCreateBatchRequest(
name="Test1",
user_language="de",
attributes=[
omniac.AttributeCreateRequest(
type="email",
value="test@example.com"
)
]
)]
try:
profiles = api_instance.create_profiles(profile_create_batch_request)
print(profiles)
except Exception as e:
print(f"Error: {e}")
Get alerts
After waiting some minutes alerts will appear, if there are any leaks found. You can pull them by using the getprofile function with your profile.id. The two parameters after the profileID let you also return the users attributes (hashed and encrypted) as well as the alerts.
import openapi_client as omniac
[...]
with omniac.ApiClient(configuration) as api_client:
api_instance = omniac.ProfileApi(api_client)
try:
profile = api_instance.get_profile("profileID", True, True)
print(profile)
except Exception as e:
print(f"Error: {e}")
Provide a push alert endpoint
To get notified even faster, we provide a push api for new alerts. As soon as something is found, we will publish the alert into your system. This is done over a HTTP-call. The delivery will be marked as done on our side as soon as your api returns a 2xx http status code.
To use this feature, you need to contact us, so we can enable the feature for your tenant.
3 - Example Java
Introduction and project setup
Java is a robust, object-oriented programming language known for its platform independence and strong type system, making it ideal for enterprise applications, web services, and large-scale systems. To manage project dependencies and build processes effectively, it’s best practice to use a build tool like Maven or Gradle. For this guide, we’ll use Maven. You can create a new Maven project by running mvn archetype:generate -DgroupId=com.example.omniac -DartifactId=omniac-client -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false in your terminal. This creates a standard project structure with a pom.xml file for dependency management. Navigate to your project directory with cd omniac-client. The Maven structure keeps your source code in src/main/java and tests in src/test/java, providing a clean and organized development environment that’s easily understood by IDEs and other developers.
Recommendation: IntelliJ IDEA for development
IntelliJ IDEA is an excellent choice for Java development, offering powerful features out of the box. After installing it, open your Maven project by selecting File > Open and choosing your project’s root directory (where the pom.xml file is located). IntelliJ will automatically detect the Maven project structure and download dependencies. The IDE provides excellent IntelliSense (code completion), built-in refactoring tools, and comprehensive debugging capabilities. You can run your application directly from the IDE using the green play button, or use the integrated terminal (Alt+F12) to execute Maven commands like mvn compile, mvn test, or mvn package. The built-in version control integration makes it easy to manage your Git repository. With features like automatic imports, code formatting, and intelligent error detection, IntelliJ IDEA provides a comprehensive development environment for building and testing your Java application efficiently.
Lets go
We highly recommend to use a unix based development environment. This is not only possible by using linux or macOS but also by installing Linux Subsystem for Windows. If you use a plain windows you might need to adapt in certain steps.
Setup Maven project
As shown above, we will use Maven for dependency management. If you haven’t created the project yet, execute the following commands:
mvn archetype:generate -DgroupId=com.example.omniac -DartifactId=omniac-client -DarchetypeArtifactId=maven-archetype-quickstart -DinteractiveMode=false
cd omniac-client
Generate API code
As recommended in our documentation we use openapi-generator to generate the necessary code to interact with the API. This ensures safety and will break on critical errors as soon as possible.
First, add the OpenAPI Generator Maven plugin to your pom.xml:
<project>
<!-- ... existing configuration ... -->
<properties>
<maven.compiler.source>11</maven.compiler.source>
<maven.compiler.target>11</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.swagger</groupId>
<artifactId>swagger-annotations</artifactId>
<version>1.6.8</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.10.1</version>
</dependency>
<!-- Additional dependencies required by generated code -->
<dependency>
<groupId>javax.annotation</groupId>
<artifactId>javax.annotation-api</artifactId>
<version>1.3.2</version>
</dependency>
<dependency>
<groupId>com.google.code.findbugs</groupId>
<artifactId>jsr305</artifactId>
<version>3.0.2</version>
</dependency>
<dependency>
<groupId>javax.ws.rs</groupId>
<artifactId>javax.ws.rs-api</artifactId>
<version>2.1.1</version>
</dependency>
<dependency>
<groupId>com.squareup.okhttp3</groupId>
<artifactId>logging-interceptor</artifactId>
<version>4.10.0</version>
</dependency>
<dependency>
<groupId>io.gsonfire</groupId>
<artifactId>gson-fire</artifactId>
<version>1.7.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.openapitools</groupId>
<artifactId>openapi-generator-maven-plugin</artifactId>
<version>6.6.0</version>
<executions>
<execution>
<goals>
<goal>generate</goal>
</goals>
<configuration>
<inputSpec>${project.basedir}/openapi.yaml</inputSpec>
<generatorName>java</generatorName>
<output>${project.basedir}/target/generated-sources</output>
<apiPackage>com.example.omniac.api</apiPackage>
<modelPackage>com.example.omniac.model</modelPackage>
<generateSupportingFiles>true</generateSupportingFiles>
<invokerPackage>com.example.omniac.client</invokerPackage>
<configOptions>
<library>okhttp-gson</library>
</configOptions>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Then copy your openapi.yaml file to the project root and generate the client:
mvn clean generate-sources
Now create a main class to configure the API client. Create src/main/java/com/example/omniac/OmniacClient.java:
package com.example.omniac;
import com.example.omniac.client.ApiClient;
import com.example.omniac.client.Configuration;
public class OmniacClient {
private static ApiClient apiClient;
public static void initializeClient(String apiKey) {
apiClient = Configuration.getDefaultApiClient();
apiClient.setBasePath("https://api.omniac.de");
apiClient.setApiKey(apiKey);
}
public static ApiClient getApiClient() {
return apiClient;
}
}
Get tenant info
Now you can initialize an API instance of the TenantAPI. Use the getTenant function of your API client to get information about your tenant.
package com.example.omniac;
import com.example.omniac.api.TenantApi;
import com.example.omniac.model.Tenant;
public class TenantExample {
public static void main(String[] args) {
// Initialize the client with your API key
OmniacClient.initializeClient("YOUR_API_KEY_GOES_HERE");
TenantApi tenantApi = new TenantApi(OmniacClient.getApiClient());
try {
Tenant tenant = tenantApi.getTenant();
System.out.println(tenant);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
}
Add profile to tenant
In order to start the monitoring of attributes and to receive alerts you need to configure a user for your tenant. After successfully creating the profile, you can start adding attributes.
package com.example.omniac;
import com.example.omniac.api.ProfileApi;
import com.example.omniac.model.Profile;
import com.example.omniac.model.ProfileCreateRequest;
import com.example.omniac.model.AttributeCreateRequest;
import com.example.omniac.model.AttributeType;
import java.util.Arrays;
import java.util.List;
public class ProfileExample {
public static void main(String[] args) {
// Initialize the client with your API key
OmniacClient.initializeClient("YOUR_API_KEY_GOES_HERE");
ProfileApi profileApi = new ProfileApi(OmniacClient.getApiClient());
// Create a new profile
ProfileCreateRequest newProfile = new ProfileCreateRequest()
.name("test")
.userLanguage("de");
try {
Profile profile = profileApi.createProfile(newProfile);
System.out.println("Created profile with ID: " + profile.getId());
// Add attributes to the profile
AttributeCreateRequest emailAttribute = new AttributeCreateRequest()
.type("email")
.value("test@example.com");
List<AttributeCreateRequest> attributes = Arrays.asList(emailAttribute);
Object apiResponse = profileApi.replaceAttributes(profile.getId(), attributes);
System.out.println("Attributes added: " + apiResponse);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
}
Create multiple profiles as a batch
In addition to the option of creating individual profiles, omniac Business also offers the ability to create up to 500 profiles with attributes at the same time.
package com.example.omniac;
import java.util.ArrayList;
import java.util.List;
import com.example.omniac.api.ProfileApi;
import com.example.omniac.model.AttributeCreateRequest;
import com.example.omniac.model.CreateProfiles201Response;
import com.example.omniac.model.ProfileCreateBatchRequest;
public static void main(String[] args) {
// Replace with a real API key or load from environment
OmniacClient.initializeClient("YOUR_API_KEY_GOES_HERE");
ProfileApi profileApi = new ProfileApi(OmniacClient.getApiClient());
List<ProfileCreateBatchRequest> batch = new ArrayList<>();
ProfileCreateBatchRequest req = new ProfileCreateBatchRequest()
.name("Test1")
.userLanguage("de");
// add attribute
req.addAttributesItem(new AttributeCreateRequest()
.type("email")
.value("test@example.com")
);
batch.add(req);
try {
CreateProfiles201Response resp = profileApi.createProfiles(batch);
System.out.println("CreateProfiles response: " + resp);
} catch (com.example.omniac.client.ApiException e) {
System.err.println("Error calling createProfiles: " + e.getMessage());
e.printStackTrace();
}
}
Get alerts
After waiting some minutes alerts will appear, if there are any leaks found. You can pull them by using the getProfile function with your profile ID. The two parameters after the profileID let you also return the users attributes (hashed and encrypted) as well as the alerts.
package com.example.omniac;
import com.example.omniac.api.ProfileApi;
import com.example.omniac.model.Profile;
public class AlertsExample {
public static void main(String[] args) {
// Initialize the client with your API key
OmniacClient.initializeClient("YOUR_API_KEY_GOES_HERE");
ProfileApi profileApi = new ProfileApi(OmniacClient.getApiClient());
try {
// Replace "profileID" with your actual profile ID
Profile profile = profileApi.getProfile("profileID", true, true);
System.out.println("Profile with alerts: " + profile);
} catch (Exception e) {
System.err.println("Error: " + e.getMessage());
e.printStackTrace();
}
}
}
Provide a push alert endpoint
To get notified even faster, we provide a push API for new alerts. As soon as something is found, we will publish the alert into your system. This is done over an HTTP call. The delivery will be marked as done on our side as soon as your API returns a 2xx HTTP status code.
To use this feature, you need to contact us, so we can enable the feature for your tenant.