Tutorials
Getting Started with Apache Unomi 4.0
From zero to a running CDP with multi-tenancy and API keys. Pick the path that suits you.
In this guide
- Quick Start with Docker Recommended
- Create a Tenant 4.0
- Your First API Calls
Alternative to Step 1: Manual Installation
Quick Start with Docker
The fastest way to get Unomi 4.0 running. You only need Docker. Full compose options (including OpenSearch) are on the Getting Started page.
Export the admin passwords
Unomi 4 ships no default password and refuses to start if these are unset. The compose file and the curl commands below read the same variables.
export UNOMI_ROOT_PASSWORD='choose-a-strong-password'
export UNOMI_HEALTHCHECK_PASSWORD='choose-a-strong-health-password'
Create docker-compose.yml (Elasticsearch)
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:9.4.3
environment:
- discovery.type=single-node
- xpack.security.enabled=false
ports:
- 9200:9200
unomi:
image: apache/unomi:4.0.0
environment:
- UNOMI_ELASTICSEARCH_ADDRESSES=elasticsearch:9200
- UNOMI_THIRDPARTY_PROVIDER1_IPADDRESSES=0.0.0.0/0,::1,127.0.0.1
- UNOMI_ROOT_PASSWORD=${UNOMI_ROOT_PASSWORD}
- UNOMI_HEALTHCHECK_PASSWORD=${UNOMI_HEALTHCHECK_PASSWORD}
ports:
- 8181:8181
- 9443:9443
- 8102:8102
depends_on:
- elasticsearch
Start the environment
docker compose up
Verify Unomi is up
curl -u "karaf:${UNOMI_ROOT_PASSWORD}" http://localhost:8181/cxs/tenants
This returns [] on a fresh install: no tenant exists yet, and most other endpoints answer 400 until you create one in Step 2. System admin credentials: karaf / your UNOMI_ROOT_PASSWORD (there is no default password in 4.0).
Create a Tenant
In Unomi 4.0, data lives under a tenant. Create one with the system admin user, then regenerate API keys to obtain the one-time plaintext values.
curl -X POST http://localhost:8181/cxs/tenants \
--user "karaf:${UNOMI_ROOT_PASSWORD}" \
-H "Content-Type: application/json" \
-d '{
"requestedId": "default",
"properties": {
"name": "Default Tenant",
"description": "Tutorial tenant"
}
}'
# Tenant create only returns maskedKey. Regenerate to get plainTextKey (shown once):
curl -X POST 'http://localhost:8181/cxs/tenants/default/apikeys?type=PUBLIC' \
--user "karaf:${UNOMI_ROOT_PASSWORD}"
curl -X POST 'http://localhost:8181/cxs/tenants/default/apikeys?type=PRIVATE' \
--user "karaf:${UNOMI_ROOT_PASSWORD}"
With a tenant in place, the cluster check works (accept the self-signed certificate warning in development):
curl -k https://localhost:9443/cxs/cluster -u "karaf:${UNOMI_ROOT_PASSWORD}"
From each apikeys response, copy plainTextKey:
YOUR_PUBLIC_API_KEY— headerX-Unomi-Api-Keyfor/cxs/context.jsonand/cxs/eventcollectorYOUR_PRIVATE_API_KEY— basic authdefault:YOUR_PRIVATE_API_KEYfor scopes, rules, schemas, searches
karaf system admin credentials for context or event collector calls in native 4.0 mode.
Manual Installation
Prefer running Unomi 4.0 itself on your machine? Run the search engine with Docker Compose and Unomi from the binary distribution.
Prerequisites
- Java 17 or later — set
JAVA_HOME. OpenJDK works fine. - Docker with Compose, for Elasticsearch 9.4.3 or OpenSearch 3.7.0
1. Start the search engine
Run only the search engine in Docker: save one of the files below as docker-compose.yml, then run docker compose up -d.
Elasticsearch (development setup, security off; Unomi connects to localhost:9200 over plain HTTP without credentials by default):
services:
elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:9.4.3
environment:
- cluster.name=contextElasticSearch
- discovery.type=single-node
- xpack.security.enabled=false
ports:
- 9200:9200
OpenSearch (export a strong OPENSEARCH_INITIAL_ADMIN_PASSWORD first; OpenSearch rejects weak ones such as admin):
services:
opensearch:
image: opensearchproject/opensearch:3.7.0
environment:
- cluster.name=opensearch-cluster
- discovery.type=single-node
- OPENSEARCH_INITIAL_ADMIN_PASSWORD=${OPENSEARCH_INITIAL_ADMIN_PASSWORD}
ports:
- 9200:9200
Before starting Karaf, export the same value as UNOMI_OPENSEARCH_PASSWORD (Unomi connects as admin over TLS by default).
2. Download & start Apache Unomi
Download the Unomi 4.0.0 binary from the download page, extract it, export the required passwords (Unomi refuses to start without them), then:
export UNOMI_ROOT_PASSWORD='choose-a-strong-password'
export UNOMI_HEALTHCHECK_PASSWORD='choose-a-strong-health-password'
./bin/karaf
# OpenSearch only, before unomi:start:
karaf@root()> unomi:setup -d=unomi-distribution-opensearch -f=true
karaf@root()> unomi:start
3. Tenant + context
Create a tenant as in Step 2, then call context with X-Unomi-Api-Key. Cluster check, once the tenant exists: https://localhost:9443/cxs/cluster (karaf / your UNOMI_ROOT_PASSWORD).
ssh -p 8102 karaf@localhost — run unomi:tenant-set default first (the shell starts in the system context and would list nothing), then unomi:crud list profile, unomi:event-tail, unomi:crud list rule. Full detail: shell commands post · manual quick start.
Your First API Calls
With Unomi 4.0 running and a tenant created, explore the REST API. Replace YOUR_PUBLIC_API_KEY / YOUR_PRIVATE_API_KEY with values from Step 2.
Create a scope
Events must use a scope that already exists for the tenant: schema validation silently drops
events with an unknown scope (Unknown scope value in the logs). Create it first:
curl -X POST http://localhost:8181/cxs/scopes \
-u "default:YOUR_PRIVATE_API_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"itemId": "my-website",
"itemType": "scope",
"metadata": {
"id": "my-website",
"name": "My Website Scope"
}
}'
Read the current context
The /cxs/context.json endpoint is the primary public endpoint. In 4.0 it requires a public API key.
The visitor's profile is carried by the context-profile-id cookie, so keep a cookie jar (-c / -b) across the public calls; without it each call creates a new profile. The response contains the profileId:
curl -c cookies.txt -b cookies.txt -X POST "http://localhost:8181/cxs/context.json?sessionId=1234" \
-H "Content-Type: application/json" \
-H "X-Unomi-Api-Key: YOUR_PUBLIC_API_KEY" \
--data-raw '{
"source": {
"itemId": "homepage",
"itemType": "page",
"scope": "my-website"
},
"requiredProfileProperties": ["*"],
"requiredSessionProperties": ["*"],
"requireSegments": true,
"requireScores": true
}'
Send a custom event
Before sending a custom event, register a JSON Schema to validate it (required since Unomi 2.0):
curl -X POST http://localhost:8181/cxs/jsonSchema \
-u "default:YOUR_PRIVATE_API_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"$id": "https://unomi.apache.org/schemas/json/events/contactInfoSubmitted/1-0-0",
"$schema": "https://json-schema.org/draft/2019-09/schema",
"self": {
"vendor": "org.apache.unomi",
"name": "contactInfoSubmitted",
"format": "jsonschema",
"target": "events",
"version": "1-0-0"
},
"title": "contactInfoSubmittedEvent",
"type": "object",
"allOf": [{ "$ref": "https://unomi.apache.org/schemas/json/event/1-0-0" }],
"properties": {
"source": { "$ref": "https://unomi.apache.org/schemas/json/item/1-0-0" },
"target": { "$ref": "https://unomi.apache.org/schemas/json/item/1-0-0" },
"properties": {
"type": "object",
"properties": {
"firstName": { "type": ["null", "string"] },
"lastName": { "type": ["null", "string"] },
"email": { "type": ["null", "string"] }
}
}
},
"unevaluatedProperties": false
}'
Now send the event via the event collector (the public endpoint for submitting events):
curl -c cookies.txt -b cookies.txt -X POST http://localhost:8181/cxs/eventcollector \
-H "Content-Type: application/json" \
-H "X-Unomi-Api-Key: YOUR_PUBLIC_API_KEY" \
--data-raw '{
"sessionId": "1234",
"events": [{
"eventType": "contactInfoSubmitted",
"scope": "my-website",
"source": {
"itemType": "site",
"scope": "my-website",
"itemId": "mysite"
},
"target": {
"itemType": "form",
"scope": "my-website",
"itemId": "contactForm"
},
"properties": {
"firstName": "Jane",
"lastName": "Doe",
"email": "jane.doe@example.com"
}
}]
}'
Search events
Retrieve events matching a condition (new events take a second or two to become searchable):
curl -X POST http://localhost:8181/cxs/events/search \
-u "default:YOUR_PRIVATE_API_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"offset": 0,
"limit": 20,
"sortby": "timeStamp:desc",
"condition": {
"type": "eventPropertyCondition",
"parameterValues": {
"propertyName": "properties.firstName",
"comparisonOperator": "equals",
"propertyValue": "Jane"
}
}
}'
View a profile
Use the profile UUID (the profileId in the /cxs/context.json response, also stored in the context-profile-id cookie) to look up profile details:
curl http://localhost:8181/cxs/profiles/PROFILE_UUID \
-u "default:YOUR_PRIVATE_API_KEY"
unomi:tenant-set default): unomi:event-tail watches events in real time, unomi:crud list event / unomi:crud list profile list recent items, unomi:crud read profile PROFILE_UUID shows profile details.
Web Tracking Tutorial
Collect page views and enable personalization. Unomi 4.0 public endpoints require your tenant public API key on every context / event request.
apiKey in wemInitConfig and sends it in the X-Unomi-Api-Key header. Use the public key only, never the private one (see Configuring the tracker for your Unomi server in the manual).
Add the tracker to your page
Include the tracker script and initialize it (scope must exist under your tenant). This snippet assumes the page is served from the same origin as Unomi; from another origin, use absolute URLs for the script and contextServerUrl, and allow that origin on the tenant (see the manual):
<!-- Load the Unomi web tracker -->
<script src="/tracker/unomi-web-tracker.min.js"></script>
<script>
(function () {
var conf = {
"scope": "my-website",
"site": {
"siteInfo": { "siteID": "my-website" }
},
"page": {
"pageInfo": {
"pageID": "home",
"pageName": document.title,
"pagePath": document.location.pathname,
"destinationURL": document.location.origin + document.location.pathname,
"referringURL": document.referrer || document.location.origin + "/",
"language": "en",
"categories": [],
"tags": []
},
"attributes": {},
"consentTypes": []
},
"events": [],
"wemInitConfig": {
"contextServerUrl": document.location.origin,
"timeoutInMilliseconds": 1500,
"contextServerCookieName": "context-profile-id",
"activateWem": true,
"trackerSessionIdCookieName": "my-website-session-id",
"trackerProfileIdCookieName": "my-website-profile-id",
// Unomi 4.0: tenant public API key, sent as X-Unomi-Api-Key
"apiKey": "YOUR_PUBLIC_API_KEY"
}
};
// Generate a new session if needed
if (unomiWebTracker.getCookie(conf.wemInitConfig.trackerSessionIdCookieName) == null) {
unomiWebTracker.setCookie(conf.wemInitConfig.trackerSessionIdCookieName, unomiWebTracker.generateGuid(), 1);
}
unomiWebTracker.initTracker(conf);
unomiWebTracker._registerCallback(function() {
console.log("Unomi context loaded:", unomiWebTracker.getLoadedContext());
}, 'My callback');
unomiWebTracker.startTracker();
})();
</script>
Using the tracker as an NPM package
For JavaScript/TypeScript projects, install the tracker from npm:
npm install apache-unomi-tracker@2
# or
yarn add apache-unomi-tracker@2
Version 2.0.0 or later is required for apiKey; 1.x does not send the key.
Then import and use it:
import { useTracker } from "apache-unomi-tracker";
const unomiWebTracker = useTracker();
// ... configure and start as shown above
Rules & Personalization
Rules let Unomi react to events in real time — updating profiles, triggering actions, or integrating with external systems.
Create a rule that counts page views
This rule increments a pageViewCount property on the visitor’s profile every time a view event is received:
curl -X POST http://localhost:8181/cxs/rules \
-u "default:YOUR_PRIVATE_API_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"metadata": {
"id": "viewEventRule",
"name": "View event rule",
"description": "Increments pageViewCount on each page view"
},
"condition": {
"type": "eventTypeCondition",
"parameterValues": {
"eventTypeId": "view"
}
},
"actions": [{
"type": "incrementPropertyAction",
"parameterValues": {
"propertyName": "pageViewCount"
}
}]
}'
After creating this rule, reload your tracked page a few times, or send a view event with curl (same cookie jar as in Step 3):
curl -c cookies.txt -b cookies.txt -X POST http://localhost:8181/cxs/eventcollector \
-H "Content-Type: application/json" \
-H "X-Unomi-Api-Key: YOUR_PUBLIC_API_KEY" \
--data-raw '{
"sessionId": "1234",
"events": [{
"eventType": "view",
"scope": "my-website",
"source": {
"itemType": "site",
"scope": "my-website",
"itemId": "mysite"
},
"target": {
"itemType": "page",
"scope": "my-website",
"itemId": "homepage",
"properties": {
"pageInfo": {
"pageID": "homepage",
"pageName": "Home",
"pagePath": "/",
"destinationURL": "http://localhost/",
"language": "en"
}
}
}
}]
}'
Then read the profile again (curl http://localhost:8181/cxs/profiles/PROFILE_UUID -u "default:YOUR_PRIVATE_API_KEY", or unomi:crud read profile PROFILE_UUID in the SSH console after unomi:tenant-set default) to see pageViewCount increase.
Map event data to a profile
This rule listens for the contactInfoSubmitted event (from Step 3) and copies its properties to the profile. Rules only apply to events received after they are created, so send the Step 3 event again to see the effect:
curl -X POST http://localhost:8181/cxs/rules \
-u "default:YOUR_PRIVATE_API_KEY" \
-H "Content-Type: application/json" \
--data-raw '{
"metadata": {
"id": "setContactInfo",
"name": "Copy contact info to profile",
"description": "Maps firstName, lastName, email from event to profile"
},
"condition": {
"type": "eventTypeCondition",
"parameterValues": {
"eventTypeId": "contactInfoSubmitted"
}
},
"actions": [
{
"type": "setPropertyAction",
"parameterValues": {
"setPropertyName": "properties(firstName)",
"setPropertyValue": "eventProperty::properties(firstName)",
"setPropertyStrategy": "alwaysSet"
}
},
{
"type": "setPropertyAction",
"parameterValues": {
"setPropertyName": "properties(lastName)",
"setPropertyValue": "eventProperty::properties(lastName)",
"setPropertyStrategy": "alwaysSet"
}
},
{
"type": "setPropertyAction",
"parameterValues": {
"setPropertyName": "properties(email)",
"setPropertyValue": "eventProperty::properties(email)",
"setPropertyStrategy": "alwaysSet"
}
}
]
}'
Personalize content based on a profile property
Using the web tracker, you can register personalization rules that show different content based on profile data. For example, show a special message after 5 page views:
<div id="variant1" style="display:none">
Welcome back! You've visited this page over 5 times.
</div>
<div id="variant2" style="display:none">
Welcome! Keep exploring to unlock personalized content.
</div>
<script>
var variants = {
"var1": { content: "variant1" },
"var2": { content: "variant2" }
};
unomiWebTracker.registerPersonalizationObject({
"id": "pageViewPersonalization",
"strategy": "matching-first",
"strategyOptions": { "fallback": "var2" },
"contents": [{
"id": "var1",
"filters": [{
"condition": {
"type": "profilePropertyCondition",
"parameterValues": {
"propertyName": "properties.pageViewCount",
"comparisonOperator": "greaterThan",
"propertyValueInteger": 5
}
}
}]
}, {
"id": "var2"
}]
}, variants, false, function (successfulFilters, selectedFilter) {
if (selectedFilter) {
document.getElementById(selectedFilter.content).style.display = '';
}
});
</script>
The personalization engine evaluates conditions server-side against the visitor’s profile and returns which variant to display, keeping your business logic private.
Next Steps
You now have a working Unomi 4.0 environment with a tenant, event tracking, profile management, rules, and personalization. Here’s where to go next.
Full Documentation
Dive deeper into segmentation, scoring, conditions, and actions in the comprehensive manual.
Read the manualREST API Reference
Explore every endpoint for profiles, events, segments, rules, and more.
Browse the APIGetting Started
Docker + OpenSearch paths, auth cheat sheet, and production notes.
Open Getting StartedIntegrations
See how organizations use Unomi with CMS, CRM, e-commerce, and other platforms.
View integrationsGet Help
Stuck? The community is friendly and responsive on the mailing list and Slack.
Join the communityDebugging Tip
Enable debug logging via the Karaf SSH console to see detailed event validation and rule execution logs:
# Connect to Karaf SSH console
ssh -p 8102 karaf@localhost
# Enable schema validation debug logs
karaf@root()> log:set DEBUG org.apache.unomi.schema.impl.SchemaServiceImpl
# Watch logs in real-time
karaf@root()> log:tail
Useful commands (set the tenant first with unomi:tenant-set default): unomi:event-tail, unomi:rule-tail, unomi:crud list event|rule|profile, unomi:crud read profile <ID>