Skip to content
For the complete documentation index, see llms.txt. This page is also available as Markdown.

Schema Tutorial

With the Schema Service you can easily create and manage customized/industry-specific fields for different types in Management Dashboard. The new fields appear in a separate tab when you create an instance of the extended type.

Supported entity types for schema creation

When creating a mixin schema through the Schema Service API, you can select from the following entity types: availability, cart, cart_item, category, company, coupon, customer, customer_address, custom_entity, location, media, order, order_entry, price_list, product, quote, return, site, vendor, and vendor_location.

Important distinction: The list above shows which entity types support mixin schema creation through the Schema Service API. APIs that support mixins but are not listed there still require you to create mixin schemas manually (as JSON schemas) and reference them when using those APIs. See the Mixins standard practices page for a complete list of APIs that support mixins.

How to add custom fields for an entity

This tutorial explains how to add custom fields for a product entity.

Create a schema

To extend the product entity in Management Dashboard with some industry-specific fields, create a schema that defines the required fields and generates JSON file representation by sending a request to the Creating a schema endpoint.

API Reference
curl -L 
  --request POST 
  --url 'https://api.emporix.io/schema/{tenant}/schemas' 
  --header 'Authorization: Bearer {{OAUTH2_ACCESS_TOKEN}}' 
  --header 'Content-Type: application/json' 
  --data '{
    "name": {
      "en": "Product Custom Attributes"
    },
    "types": [
      "PRODUCT"
    ],
    "attributes": [
      {
        "key": "weight",
        "name": {
          "en": "Weight of a product"
        },
        "description": {
          "en": "The exact weight of a product in grams."
        },
        "type": "TEXT",
        "metadata": {
          "readOnly": true,
          "required": true
        }
      },
      {
        "key": "size",
        "name": {
          "en": "Size of a product"
        },
        "description": {
          "en": "The exact size of a product. Possible values are S, M, L."
        },
        "type": "ENUM",
        "metadata": {
          "readOnly": true,
          "required": true
        },
        "values": [
          {
            "value": "S"
          },
          {
            "value": "M"
          },
          {
            "value": "L"
          }
        ]
      },
      {
        "key": "advertisement",
        "name": {
          "en": "Advertisement of a product"
        },
        "description": {
          "en": "A localized advertisement of a product."
        },
        "type": "TEXT",
        "metadata": {
          "localized": true,
          "required": true
        }
      }
    ]
  }'

Request result is the new schema ID - "id": "6915ec3c047dc4456d86a26f".

Retrieve a schema

Retrieve the created schema to get the schema URL by calling the Retrieving a schema endpoint.

API Reference

In the response, you can see the URL link to cloudinary repository, where the schema for the product type has been uploaded.

Create a product

Now, create a product that contains additional fields by sending a request to Creating a new product endpoint.

The product should contain "metadata.mixins.{{id}}: {{cloudinaryUrl}}", where id is the schema URL you retrieved with GET operation in the previous step.

For example, you created a schema with size attribute and it got assigned a schema id: 6915ec3c047dc4456d86a26f. When creating or editing a product, provide the schema id and URL details in the payload of the POST request:

The product you created has already the custom fields added in the separate Product Custom Attributes tab.

How to create a site-aware mixin schema

Set siteAware to true when you create or update a mixin schema so products and custom instances can store per-site overlays for that schema. After the schema exists, attach it to a product or custom instance as usual: declare only the base mixin name in metadata.mixins, and store overlays under keys in the form {mixinName}__{siteCode}.

For the product workflow after the schema exists, see How to use site-aware mixins on products. For an overview of overlay and merge behavior, see Site-aware mixins.

Create a site-aware schema

Send a request to the Creating a schema endpoint and include "siteAware": true.

Retrieve the schema with the Retrieving a schema endpoint. The response includes siteAware: true and the schema URL to reference from products or custom instances.

Enable site awareness on an existing schema

To mark an existing mixin schema as site-aware, send a request to the Updating a schema endpoint. Include the current schema attributes, set "siteAware": true, and send the current metadata.version. The siteAware flag is stored with that attributes version.

How to use localized OBJECT mixin attributes

When your tenant's languageSchemaVersion configuration is v2, you can mark an OBJECT attribute as localized. Schema Service then generates a language-keyed map of nested objects. Array items of localized TEXT or OBJECT also use v2 language maps.

Under v1, localized mixin TEXT values are often stored as arrays such as [{ "language": "en", "value": "Organic" }]. Under v2, the same kind of value is a language map such as { "en": "Organic", "de": "Bio" }. Localized TEXT attributes work with either version. Localized OBJECT attributes require v2.

Prerequisites

Before you start, complete the following prerequisites:

  1. Set the tenant configuration key languageSchemaVersion to the string value v2. Use the Creating configurations endpoint, or Updating a configuration if the key already exists. For the broader workflow, see Managing tenant configurations.

  1. Use language codes that exist in your tenant language configuration. See Language Tutorials.

If languageSchemaVersion is missing or set to v1, Schema Service rejects localized OBJECT attributes.

Create a schema with a localized OBJECT

Send a request to the Creating a schema endpoint. For an OBJECT attribute, set "localized": true in that attribute's metadata. For localized array items, set "localized": true on arrayType. Nested attributes inside a localized OBJECT must not set localized to true. Nested localized attributes remain allowed only under a plain (non-localized) OBJECT.

Retrieve the schema with the Retrieving a schema endpoint. Use the returned metadata.url when you attach the mixin to a product or custom instance.

Store localized OBJECT values

Unlike first-class localized fields in Translations, mixin writes are not reshaped by Content-Language. Always send full language maps in the mixin JSON body.

Attach the mixin when you create or update a product or custom instance. Choose a stable mixin key, for example localizedContentAttributes, and put the schema URL under metadata.mixins for that same key. For products, see Create a product or How to update product mixins.

Example product mixin payload:

A nullable localized OBJECT can be null for the whole field, or null for a single language key, for example "en": null.

Read a preferred language with Accept-Language

On product and custom-instance reads, send Accept-Language to filter v2 mixin language maps. Unlike first-class localized fields, which return a string for one language (or a full map when the header is *), a filtered mixin field remains a single-key map, for example { "de": { "city": "Berlin" } }.

Accept-Language filtering for v2 mixin maps follows these rules:

  • A specific language or ordered list returns the first matching non-null translation as a single-key map.

  • A map with no matching non-null translation is omitted. A whole-field null localized OBJECT is preserved.

  • In an array of language maps, an element without a matching translation is omitted.

  • *, an omitted header, or an empty header leaves full v2 mixin maps unchanged.

  • v1 [{language,value}] mixin arrays are not filtered.

For first-class localized fields on the same responses, an omitted or empty header uses the tenant's default language. Only * returns every translation.

For product reads, see Retrieving a product. For custom instances, see Retrieving a custom instance.

Localization rules

Localization for mixin attributes follows these rules:

  • A localized OBJECT cannot contain another localized attribute anywhere in its subtree.

  • A plain (non-localized) OBJECT can contain nested localized TEXT or nested localized OBJECT attributes.

  • Under v2, creating or updating a schema regenerates array-of-localized TEXT and OBJECT fields as language maps.

How to create a more complex schema

In case you need to add a schema for more complex attribute types than those supported by default, instead of creating a schema, you can create a reference. This tutorial shows you how to upload more complex schemas.

Prepare a JSON schema definition

See the example JSON file that defines fields of different types:

Create a reference

To use the schema in Emporix Commerce Engine, send a request to the Creating a reference endpoint. This action creates a reference to your schema so that you use the extended type. The schema reference is used to create or edit product objects.

API Reference

CURL request example:

JSON example:

Create a product

Now, create a product and provide values for the customized fields by sending a request to Creating a new product endpoint.

See the example payload for creating a product basing on the schema from the previous step:

Custom entity authorization and ownership

When you create a custom entity type, the platform provisions type-specific scopes that follow the custom.{lowerCaseType}_* naming pattern.

For a type like DOCUMENT, generated scopes follow this pattern:

  • custom.document_read

  • custom.document_manage

  • custom.document_read_own

  • custom.document_manage_own

Custom instance endpoints accept either tenant-wide Schema scopes or type-scoped scopes:

  • Read operations: schema.custominstance_read or custom.{lowerCaseType}_read or custom.{lowerCaseType}_read_own

  • Manage operations: schema.custominstance_manage or custom.{lowerCaseType}_manage or custom.{lowerCaseType}_manage_own

Custom instance responses include the immutable owner object, which is used for ownership-aware authorization:

  • owner.type: CUSTOMER, EMPLOYEE, or SERVICE

  • owner.userId: creator identifier (for service flows, client identifier)

  • owner.legalEntityId: present for customer-owned instances

For the end-to-end IAM and Schema flow, see Custom scopes for custom entities in the Tokens and Scopes guide.

Last updated

Was this helpful?