Expand

Modified on Wed, 11 Mar at 12:56 PM

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.
  • This helps retrieve related data in a single request and reduces the need for multiple API calls.


Syntax of $expand Expression


  • The expression follows the format:
EMBEDDED_COLLECTION1_NAME, EMBEDDED_COLLECTION2_NAME
  • Example of expanding variants when retrieving products:
$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 receive a schema detailing all available properties such as prod_title, prod_ref, etc.


How to Use $expand in a Request


  • When constructing your API request, add the $expand parameter to include related collections in the response.
http://api2.saleslayer.com/rest/Catalog/Products?$select=prod_ref,prod_title&$expand=Variants


Response Format


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


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 different API methods.

Was this article helpful?

That’s Great!

Thank you for your feedback

Sorry! We couldn't be helpful

Thank you for your feedback

Let us know how can we improve this article!

Select at least one of the reasons
CAPTCHA verification is required.

Feedback sent

We appreciate your effort and will try to fix the article