OCAPI Expansions 23.1

To minimize network traffic and server CPU usage, the Open Commerce API sometimes uses a technique called expansion. This technique intentionally omits parts of a selected resource, reducing the size of the overall response. However, if you want to include the parts that are omitted by default, you can explicitly request the omitted parts by using the expand query parameter. This parameter specifies a comma-separated list of entities that you want expanded, identifying each of them by name.

The products and product_search resources support the expansion technique. A resource type that enables expansions is structured into a base resource and one or more subresources. For the *products* resource, the base resource is */products/{id}*, and two of its subresources are */products/{id}/prices* and */products/{id}/variations*.

By default, the base resource returns only a basic subset of properties. A subresource returns not only the base properties but also subresource specific properties (for example, price properties). The name of the subresource is used as the expand query parameter value.

The examples below show how expansion works.

Request to base resource without expand parameter specified. Response document contains only some basic properties.

Two requests to separate subresources. A subresource response document contains the basic properties plus subresource specific properties.

Single request with expand parameter. The response document contains the basic properties plus the specific properties of each subresource named in expand parameter values.