Expand

Purpose

  • The $expand parameter allows you to include embedded collections of a resource in the response.

Key Points

  • By default, embedded collections are not included in the response unless explicitly specified using $expand.
  • Only embedded collections are supported; embedded individual resources are not supported.
  • Helps in retrieving related data in a single request, reducing the need for multiple API calls.

.

Syntax of $select Expression

  • The expression follows the format:
[EMBEDDED_COLLECTION1_NAME, EMBEDDED_COLLECTION2_NAME, ...]  
  • Example of Products with Variants expand
$expand=[Variants]

Supported Properties

  • The list of available properties for the Product resource can be found in the JSON schema returned by the /$metadata endpoints
  • Example: When making a request to /Products/$metadata, you will get a schema detailing all available properties like prod_title, prod_ref, etc.

How to Use $select in a Request

  • When constructing your API request, add the $select parameter to specify the fields you want to retrieve
http://api2.saleslayer.com/rest/Catalog/Products?$select=[prod_ref,prod_title]&$expand=[Variants]

Response Format

  • When using $expand, the response will include the specified embedded collections as part of the resource.
{
    "value": [
        {
            "prod_ref": "MyPer",
            "prod_title": {
                "en": "My Personify"
            },
            "Variants@count": 2
        },
        {
            "prod_ref": "CuMoApp",
            "prod_title": {
                "en": "Custom Mobile Apps"
            },
            "Variants@count": 0
        },
        {
            "prod_ref": "Atrius",
            "prod_title": {
                "en": "Atrius"
            },
            "Variants@count": 0
        },
        {
            "prod_ref": "Builder",
            "prod_title": {
                "en": "Builder"
            },
            "Variants@count": 0
        },
        {
            "prod_ref": "X-pressP",
            "prod_title": {
                "en": "X-press gfx Points"
            },
            "Variants@count": 0
        },
        {
            "prod_ref": "EC-gfx",
            "prod_title": {
                "en": "EC-gfxProgram"
            },
            "Variants@count": 0
        },
        {
            "prod_ref": "PreApp",
            "prod_title": {
                "en": "Preloaded Applications"
            },
            "Variants@count": 3
        },
        {
            "prod_ref": "ProdEnhanT",
            "prod_title": {
                "en": "Productivity Enhancing Tools"
            },
            "Variants@count": 1
        },
        {
            "prod_ref": "ECx-L-4D",
            "prod_title": {
                "en": "ECx-Light-4DALI"
            },
            "Variants@count": 1
        },
        {
            "prod_ref": "ECx-L-S",
            "prod_title": {
                "en": "ECx-Light Series"
            },
            "Variants@count": 0
        },
        {
            "prod_ref": "ECx-B-S",
            "prod_title": {
                "en": "ECx-Blind Series"
            },
            "Variants@count": 0
        }
    ],
    "@count": 11,
    "@readLink": "https://api2.saleslayer.com/rest/Catalog/Products?$select=[prod_ref,prod_title]&$expand=[Variants]"
}

Notes

  • The metadata is a JSON schema document that describes the resources associated with a particular resource and the relationships between them.
  • Example:
    For the Product resource, the metadata may describe associated resources such as Category, and Variant. The metadata also outlines their relationships, helping you understand how to build requests for various API methods.