Announcement: You can find the guides for Commerce 7.5 and later on the new Elastic Path Documentation site. This Developer Center contains the guides for Commerce 6.13.0 through 7.4.1.Visit new site

This version of Elastic Path Commerce is no longer supported or maintained. To upgrade to the latest version, contact your Elastic Path representative.

API Definition

API Definition

The first step in developing resources for Cortex is to define them using the API definition language. the API definition is an XML file in your project in which you describe the various resources types, their URIs, advisors and the relationships between them. From this XML file, a set of prototype classes is generated for you to implement.

The XML schema can be found here.

For examples of fully implemented APIs and resources for common use cases, see the Helix Pattern Catalog.

Defining an Entity Resource

The most basic type of resource you can define is an Entity resource. The definition of an entity resource consists of an entity, which describes or provides access to data of some sort, a URI-part, which acts as an identifier for the resource, and the resource itself, which links the URI-part to the entity. You must define all three of these things.

Entity Resources support CREATE, READ, UPDATE, and DELETE operations. You must implement one of these operations in your generated prototype.

Defining a URI-part

URI-part is an identifier for a resource's URI, allowing us to never deal directly with the URI string. For more information, see Resource Identifiers.

To define an identifier part, use the <uri-part/> element:

    <description>Identifier for one car</description>

Defining an Entity

Entity resources are used to provide access to some form of data. An entity resource definition consists of and <entity/> definition an a corresponding <resource/> definition.

The definition of an entity itself is as follows:

    <description>A car.</description>
      <description>The brand of the car</description>
      <description>The model of the car</description>
      <description>The year the car was build</description>

An entity must have a <name>, <description>, and at least one <property>. The property must have a data type: in the example above, these are defined by the <string/> and </integer> elements. Cortex provides support for a number of "primitive" property types, including string, integer, long, boolean, and decimal. See the XML schema for the full list of supported types.

Defining an Entity Resource

The resource part of an entity resource links the URI-part to the entity, and provides a name which can be used to access both.

To define the Entity Resource for a given entity:

    <description>A car resource.</description>

Extending Entities

You can extend entities by using <is-a/>. There are two ways of extending an entity: inheritance and composition. You can extend an entity within its same family, or with an outside family.

In the API definition schema, entitles are defined with a <family /> element. Conceptually similar entities. For example different types of cars are defined within the 'cars' family.

Adding properties to an existing Entity

If you want to extend an existing entity by adding fields specific to a subtype, you can use <is-a/> to add properties to an entity:

    <description>car entity with country property</description>
      <description>The country where the car was built</description>

Composing a New Entity out of Existing Entities

If you want an entity that contains multiple entities build an entity out of existing entities:

    <description>An entity with unvalidated properties</description>
      <description>A property that is a reference to another entity</description>
      <description>A list (array) of other entities</description>

Dynamic Entities

A dynamic entity resource is an entity resource which operates on an entity containing dynamic properties. These dynamic properties can be used if the properties to be contained in an entity are not known when modeling the API definition or the entity returned by the entity resource contains different properties depending on the state.

    <description>A truck resource with a dynamic truck entity.</description>

Note: make sure when injecting a dynamic property entity to validate if the property keys you are expecting are actually contained in the dynamic property map.

For more information on dynamic entities, see Dynamic Fields.

Types of Resources

In addition to the basic entity resource, there are a number of specialized resources that provide additional functionality and types of linking between difference resources.

Alias Resources

Alias resources are used to create a redirect to another resource. For example, given the following resource:

    <description>A resource that represents a color</description>

An alias resource can be defined as follows:

    <description>A resource that represents the default color, it is an alias to the color resource</description>

Alias resources only support READ operations.

List Resources

List resources represent collections or sets of other resources.

To define a list resource:

    <description>A list of countries resource.</description>

Where the <list-of/> element is the name of a resource.

List resources support READ and CREATE operations.

Paginated List Resources

List resources always return all elements of a collection of other resources. Sometimes collections can contain a lot of elements and returning the whole collection might lead to poor performance. A paginated list resource returns a subset of the elements of a collection, with a defined number of items of the collection. To achieve this, a paginated list resource divides the collection into even sized buckets of elements. Each bucket can be accessed individually by accessing the paginated list resource parametrized.

To define a paginated list resource:

    <description>A list of countries resource.</description>

Where the <paginates/> element is the name of the collected resource.

Paginated list resources support the READ operation.

When creating an element that should be added to the collection, use a list resource and perform a CREATE operation on it (you don't necessarily have to implement the READ operation of the list resource for this).

Selector Resource

Selector Resources are used when a state of a resource is modifiable by selection of choices.

The different selection choices are either in the state choice or chosen. Choice reflects that a selection could be chosen and chosen reflects that a selection is chosen.

A selector resource definition consists of two resources. First, a selector resource to declare which resource it will act as a selector for, using the <selector-for/> element:

    <description>Selects the billing address to use for an order.</description>

Second, a choice resource to declare what type of resources can be chosen from, using the <choices-for/> element:

    <description>A choice for the billing address selector.></description>

In the example, a choice between different addresses is modeled. This is defined by the URI identifier-part {address}, which points to the address resource. By convention, the choice resource also to declare which selector resource it is associated with. The <choices-for> tag serves this purpose.

Form Resource

A form resource combines an entity, action-rel and result into a single resource. This provides the following functionality:

  • A READ form prototype to retrieve form data
  • An action link which links a POST operation from the READ operation,
  • A POST form prototype which processes the form's posted data.
    <description>Create order form resource</description>


An advisor is used to give advice on a resource operation.

There are two types of advises with different semantics: Non-blocking Advisors and Blocking Advisors. For more information, see Advisors.

Non-blocking Advisor

A non-blocking advisor provides additional information when a READ operation is performed on a resource, but does not affect the HTTP status code emitted by the READ operation.

To define a non-blocking advisor:

    <description>Terms and Conditions NeedInfo</description>

In the provided example the <advises/> element references the resource on which the advisor should provide additional information on. In cases the advise operation provides information about an issue that can be resolved, like a warning that indicates a validation issue, the optional <linked-to/> element points to another resource which can resolve the issue.

Blocking Advisor

A blocking advisor may enrich the HTTP response of a HTTP GET request on a form in the same manner as an advisor on Read. In addition, the blocking advisor may hide the submit-action link as well as block an actual HTTP POST to the form. If a POST request is performed against a blocked form resource, the form prototype for handling the POST operation is never executed. Instead, a structured error message is returned with the HTTP status code 409.

    <description>Terms and Conditions NeedInfo</description>

Resource Relationships

Relationships (links) between resources are defined as follows:

    <description>User Profile from root</description>

Here, we've defined a link from the root resource (base.root) to the user-profile resource, with a rel of "profile".

Out of Family Resources

You may have noticed in the previous example, we referenced the root resource as base.root. This is a fully-qualified reference to a resource, which is required for referencing resources that are not in the same family as the resource you're defining.

In order to reference resources in other families, a Maven dependency needs to be added to bring in the API for the resource:


This would bring in the Cortex "profiles" API, which would then allow you to define additional relationships from the profiles resource:

    <description>Link from the profile to the list of bookings for a given user</description>

Notice that the profile resource in the <from/> element is referred to in its fully-qualified form (profiles.profile).