Skip to content
  • Our Product
    • Namazu Elements
      • What is Elements?
      • Why open source?
      • Docs
        • Namazu Elements in Five Minutes or Less
        • RESTful APIs Library
        • Security Model
        • Accessing the Web UI (CMS)

    Our Product

    A logomark with three layered rhombuses adorning the lettermark that says Elements in bold all-caps sans-serif letters.
    • What is Namazu Elements? Discover our easy-to-use backend network solution built for online games. Rapidly enables full-scale multiplayer games or online solo adventures.
    • Why open source? Is there a truly open source server backend for connected games? There is now. Download and run a local copy of Namazu Elements and try it for yourself.
    Download Namazu Elements

    Get started

    • Quick start Read our Elements 5-minute quick start guide
    • Documentation Read our developer docs for learning more about Elements
    • RESTful APIs A full list of core API specs for working with the Elements framework
    • Security An overview of the server-authoritative security model of Elements
    • Accessing the CMS Manage your game with ease via the Namazu Elements CMS.

    Co-development Reimagined

    • Best real-time game backends in 2026 If you're researching an alternative to your current backend solution, we've prepared a report of all of the backend solutions on the market in 2026 and how Namazu Elements compares.
      Co-dev

    Recent Posts

    • The watercolor-styled Namazu Studios logo over a giant namazu lurking in the depth
      Namazu Studios Featured in San Diego Business Journal
      22 Sep 2025 Press
    • Namazu Elements 3.1 Released – Service Layer Fixes, Secure APIs, and Steam Bug Fix
      22 Apr 2025 Release Notes
  • Case Studies
  • About Us
  • News
  • Services
  • Book a call
namazu-studios-logo
Book a call

Getting Started

  • Namazu Elements in Five Minutes or Less
  • Accessing the Web UI (CMS)
  • CMS Feature Overview

Fundamentals

  • Why You Need a Server (and What “Authoritative” Means)
  • Elements as a Game Runtime
  • Where Your Authoritative Code Runs
  • Lifecycles and Flows

General Concepts

  • Overview
  • Custom Elements
  • Data Models
  • Security Model
  • N-Tier Architecture

Namazu Elements Core Features

  • User Authentication / Sign In
    • What is a User?
    • User Authentication in Elements
    • Email Verification
    • Auth Schemes
      • Auth Schemes
      • OAuth2
      • OIDC
  • Features
    • Applications
    • Sessions
    • Users and Profiles
    • Digital Goods
    • Progress and Missions
    • Progress and Missions (3.4+)
    • Leaderboards
    • Matchmaking – Comprehensive Guide
    • Followers
    • Friends
    • Product Bundles and SKUs
    • Receipts
    • Item Ledger
    • Reward Issuances
    • Save Data
    • Metadata
    • Metadata (3.4+)
    • Email Service
    • Queries
    • Web3
      • Wallets
      • Vaults
      • Omni Chain Support
      • Smart Contracts
        • Smart Contracts
  • Queries
    • Advanced Operators
    • Object Graph Navigation
    • Boolean Queries
    • Base Query Syntax
  • Advanced Operators
    • .name
    • .ref

Your Game Code - Adding Custom Elements

  • Custom Code Overview
  • Windows Setup
  • Mac OS Setup
  • Ubuntu Linux Setup
  • Element Anatomy: A Technical Deep Dive
  • Introduction to Guice and Jakarta in Elements
  • Structuring your Element
  • Events
  • Packaging an Element with Maven
  • Deploying an Element
  • Preparing for code generation
  • Properties
  • Websockets
  • RESTful APIs
  • Direct MongoDB Access (3.5+)

Configuration

  • Matchmaking – Comprehensive Guide
  • Direct Database Access and Batch Configuration
  • Batch Samples
    • Mission Upload Bash Script Sample
    • Item Upload Bash Script Sample

RESTful APIs

  • Importing into Postman
  • RESTful APIs Library
  • Swagger and Swagger UI

Add-Ons

  • Crossplay
    • Namazu Crossfire (Multiplayer)
    • Deploying Namazu Crossfire in your game
  • Roblox
    • Roblox Overview
    • Secure Player Authentication & Registration
    • Global Matchmaking
    • Roblox Security Best Practices

Game Engine & Client Support

  • Unity
    • Elements Unity Plugin
    • Unity Crossfire Plugin

Troubleshooting

  • Common Issues with Docker
  • Local SDK
    • Unable to deploy application : dev.getelements.elements.sdk.exception.SdkElementNotFoundException
    • Could not load class : java.lang.NoClassDefFoundError
  • Namazu Elements Community Edition
    • Common Issues with Docker
    • Unable to deploy application : dev.getelements.elements.sdk.exception.SdkElementNotFoundException
    • Running in the IDE
      • Exception in monitor thread while connecting to server localhost:27017
      • Could not deployAvailableApplications Jetty server Failed to bind to /0.0.0.0:8080 Address already in use

Releases

  • 3.6 Release Notes
  • 3.5 Release Notes
  • 3.4 Release Notes
  • 3.3 Release Notes
  • 3.2 Release Notes
  • 3.1 Release Notes
View Categories
  • Home
  • Docs
  • Namazu Elements Core Features
  • Features
  • Item Ledger

Item Ledger

Est. read time: 6 min read

Elements Version 3.8+

Overview #

The Item Ledger is an append-only audit trail that records every inventory and item-catalog lifecycle event in the system. It answers the question: “when did this user acquire, modify, or lose this item, and who made the change?”

Every time an inventory item or item-catalog record is created, modified, or deleted, the responsible service writes an immutable ItemLedgerEntry to the item_ledger MongoDB collection. Records are never updated or deleted – the collection grows monotonically and serves as a permanent history.

Reads are superuser-only. Regular users and unauthenticated callers receive a ForbiddenException.


What is recorded #

TriggerEvent type
Fungible inventory item createdCREATED
Fungible inventory quantity adjusted by deltaQUANTITY_ADJUSTED
Fungible inventory quantity set to absolute valueQUANTITY_SET
Fungible inventory item deletedDELETED
Distinct inventory item createdCREATED
Distinct inventory item metadata updatedMETADATA_UPDATED
Distinct inventory item deletedDELETED
Item catalog entry createdITEM_CREATED
Item catalog entry updatedITEM_UPDATED
Item catalog entry deletedITEM_DELETED

Model #

Class: dev.getelements.elements.sdk.model.inventory.ItemLedgerEntry

FieldTypeDescription
idStringDatabase id. Assigned on creation; null on write.
inventoryItemIdStringId of the affected inventory item. Null for item-catalog events (ITEM_CREATED, ITEM_UPDATED, ITEM_DELETED).
itemCategoryItemCategoryFUNGIBLE or DISTINCT. Null for item-catalog events.
itemIdStringId of the item definition (the Item catalog record).
userIdStringId of the user who owns the inventory item. For item-catalog events this is set to the actorId.
actorIdStringId of the user who performed the action. Null when triggered by a system process or plugin without an active user session.
eventTypeItemLedgerEventTypeClassifies the event. See event types below.
timestamplongEpoch milliseconds when the event was recorded.
quantityBeforeIntegerQuantity before the change. Populated only for QUANTITY_ADJUSTED.
quantityAfterIntegerQuantity after the change. Populated for CREATED, QUANTITY_ADJUSTED, and QUANTITY_SET.
metadataBeforeMap<String, Object>Metadata snapshot before the change. Populated only for METADATA_UPDATED.
metadataAfterMap<String, Object>Metadata snapshot after the change. Populated only for METADATA_UPDATED.

Event types #

Class: dev.getelements.elements.sdk.model.inventory.ItemLedgerEventType

ValueApplies toDescription
CREATEDFungible and distinct itemsItem was added to a user’s inventory.
QUANTITY_ADJUSTEDFungible itemsQuantity changed by a signed delta.
QUANTITY_SETFungible itemsQuantity replaced with an absolute value.
DELETEDFungible and distinct itemsItem was removed from inventory.
METADATA_UPDATEDDistinct itemsPer-item metadata was updated.
ITEM_CREATEDItem catalogAn Item definition was created.
ITEM_UPDATEDItem catalogAn Item definition was updated.
ITEM_DELETEDItem catalogAn Item definition was deleted.

REST API #

Base path: /api/rest/inventory/ledger

Get ledger entries #

GET /api/rest/inventory/ledger

Returns paginated ItemLedgerEntry objects sorted most recent first. Exactly one of inventoryItemId or userId is required.

Query parameters

ParameterRequiredDescription
inventoryItemIdOne of these two is requiredFilter entries for a specific inventory item.
userIdOne of these two is requiredFilter entries for a specific user (across all their inventory items).
eventTypeNoFilter by event type. Omit to return all event types.
offsetNo (default 0)Zero-based page offset.
countNo (default 20)Number of results per page.

Responses

StatusDescription
200 OKPagination<ItemLedgerEntry> – paginated results.
400 Bad RequestNeither inventoryItemId nor userId was supplied, or a numeric parameter is negative.
403 ForbiddenCaller is not a superuser.

Example – full history for an inventory item

GET /api/rest/inventory/ledger?inventoryItemId=6630f1a2b4e3c70012345678
Authorization: Bearer <superuser-token>
{
  "total": 3,
  "objects": [
    {
      "id": "6630f1a2b4e3c70099999993",
      "inventoryItemId": "6630f1a2b4e3c70012345678",
      "itemCategory": "FUNGIBLE",
      "itemId": "6630f1a2b4e3c70011111111",
      "userId": "6630f1a2b4e3c70022222222",
      "actorId": "6630f1a2b4e3c70033333333",
      "eventType": "QUANTITY_ADJUSTED",
      "timestamp": 1714000800000,
      "quantityBefore": 10,
      "quantityAfter": 15
    },
    {
      "id": "6630f1a2b4e3c70099999992",
      "inventoryItemId": "6630f1a2b4e3c70012345678",
      "itemCategory": "FUNGIBLE",
      "itemId": "6630f1a2b4e3c70011111111",
      "userId": "6630f1a2b4e3c70022222222",
      "actorId": "6630f1a2b4e3c70033333333",
      "eventType": "QUANTITY_SET",
      "timestamp": 1714000700000,
      "quantityAfter": 10
    },
    {
      "id": "6630f1a2b4e3c70099999991",
      "inventoryItemId": "6630f1a2b4e3c70012345678",
      "itemCategory": "FUNGIBLE",
      "itemId": "6630f1a2b4e3c70011111111",
      "userId": "6630f1a2b4e3c70022222222",
      "actorId": "6630f1a2b4e3c70033333333",
      "eventType": "CREATED",
      "timestamp": 1714000600000,
      "quantityBefore": 0,
      "quantityAfter": 5
    }
  ]
}

Example – user history filtered to creation events

GET /api/rest/inventory/ledger?userId=6630f1a2b4e3c70022222222&eventType=CREATED
Authorization: Bearer <superuser-token>

Example – entries within a timestamp range

GET /api/rest/inventory/ledger?inventoryItemId=6630f1a2b4e3c70012345678&from=1714000000000&to=1714001000000
Authorization: Bearer <superuser-token>

DAO interface #

Interface: dev.getelements.elements.sdk.dao.ItemLedgerDao Annotation: @ElementServiceExport

/** Appends an immutable audit record. */
ItemLedgerEntry createLedgerEntry(ItemLedgerEntry entry);

/** Entries for a specific inventory item, most recent first. eventType/from/to may be null. */
Pagination<ItemLedgerEntry> getLedgerEntries(
        String inventoryItemId, int offset, int count,
        ItemLedgerEventType eventType, Long from, Long to);

/** All entries for a specific user across all inventory items, most recent first. eventType/from/to may be null. */
Pagination<ItemLedgerEntry> getLedgerEntriesForUser(
        String userId, int offset, int count,
        ItemLedgerEventType eventType, Long from, Long to);

There are intentionally no update or delete methods – the interface enforces immutability.


Service interface #

Interface: dev.getelements.elements.sdk.service.inventory.ItemLedgerService Annotations: @ElementPublic, @ElementServiceExport, @ElementServiceExport(name = UNSCOPED)

The service is read-only and exposes the same two query methods as the DAO.

Access levelBehaviour
SUPERUSERFull read access.
Any other levelThrows ForbiddenException.

How writes work #

Ledger entries are written automatically by the inventory and item-catalog service implementations immediately after each successful mutation. No explicit calls are needed by callers of those services.

SuperUserSimpleInventoryItemService   ─|
SuperUserAdvancedInventoryItemService ─|
SuperUserDistinctInventoryItemService ─|
SuperuserItemService (catalog)        ─|----> ItemLedgerDao.createLedgerEntry(...)

The actorId is set to the id of the currently authenticated user. If the call originates from a plugin or system process without an active user session, actorId is null.

Item-catalog events (ITEM_CREATED, ITEM_UPDATED, ITEM_DELETED) set inventoryItemId, itemCategory, and userId to null; actorId holds the id of the superuser who made the change.


Reading the ledger from a plugin #

@Inject
private ItemLedgerService itemLedgerService;

// Full history for one inventory item
Pagination<ItemLedgerEntry> history = itemLedgerService
        .getLedgerEntries(inventoryItemId, 0, 20, null, null, null);

// Creation events for a user
Pagination<ItemLedgerEntry> created = itemLedgerService
        .getLedgerEntriesForUser(userId, 0, 20, ItemLedgerEventType.CREATED, null, null);

// Entries within a timestamp range
long from = Instant.parse("2024-04-25T00:00:00Z").toEpochMilli();
long to   = Instant.parse("2024-04-26T00:00:00Z").toEpochMilli();
Pagination<ItemLedgerEntry> ranged = itemLedgerService
        .getLedgerEntries(inventoryItemId, 0, 20, null, from, to);

The service must be injected from a superuser-scoped or UNSCOPED context.


Best practices #

  • The ledger is append-only and grows indefinitely. Add a TTL index to item_ledger.timestamp if unbounded growth is a concern for your deployment.
  • Use the eventType filter to narrow queries – scanning all event types for a high-traffic user can be expensive at scale.
  • For QUANTITY_ADJUSTED events, quantityBefore + delta = quantityAfter. For QUANTITY_SET events, only quantityAfter is recorded to avoid an extra DAO read.
  • METADATA_UPDATED entries include full metadataBefore and metadataAfter snapshots. For items with large metadata objects this doubles the storage cost per update.
  • Item-catalog events cannot be retrieved via the inventoryItemId or userId REST filters. Query MongoDB directly or use ItemLedgerDao in a plugin for catalog-only audit needs.

FAQ #

Q: Why is the ledger superuser-only? A: Inventory histories can reveal sensitive activity information about other users. Only privileged callers (administrators, backend services) should be able to read them.

Q: Does deleting an inventory item also delete its ledger entries? A: No. Ledger entries are immutable and are never removed. After deletion a DELETED entry is appended; the prior history remains intact.

Q: Can I query entries for a specific event type across all users? A: Not directly via the REST API. For cross-user analytics, query MongoDB directly or build a custom aggregation in a plugin using ItemLedgerDao.

Q: Are entries written inside a transaction with the inventory mutation? A: Not currently. The ledger write happens immediately after the DAO call returns. If the ledger write fails the inventory mutation has already been committed – this is an acceptable trade-off for an audit trail where eventual consistency is sufficient.

What are your Feelings
Still stuck? How can we help?

How can we help?

Updated on April 16, 2026
ReceiptsReward Issuances
Table of Contents
  • Overview
  • What is recorded
  • Model
  • Event types
  • REST API
    • Get ledger entries
  • DAO interface
  • Service interface
  • How writes work
  • Reading the ledger from a plugin
  • Best practices
  • FAQ
  • Documentation
  • Terms of Service
  • Privacy Policy
  • Contact us
  • Linkedin
  • Join our Discord

Namazu Studios LLC is powered by Namazu Elements, an open source modular backend framework for connected games.

Namazu Elements
  • Download
  • About Elements
  • Open source
  • Documentation
  • Support
Namazu Studios
  • Case Studies
  • About Us
  • News
Best realtime game backends 2026
Get in Touch
  • info@namazustudios.com
  • Book a call
  • (619) 862-2890
  • Linkedin
  • Discord

©2008-2026 Namazu Studios. All Rights Reserved.