Skip to content

Pages using the REST API

The REST API can be used to load pages. You can either fetch the page contents as JSON or rendered as HTML.

Request

The endpoint is available at https://core.helloretail.com/serve/pages/{key}. And fetches a page identified by key. The key for a page can be found on My Hello Retail.

You use it by sending a HTTP POST request with a JSON body. The content type must be application/json or text/plain 1.

Example of the structure the JSON body must have when loading:

{
    "url": "https://example-shoe-shop-url.com/women/shoes",
    "id": 2,
    "format": "json",
    "firstLoad": true,
    "trackingUserId": "62a0317d17698aa57d369db9",
    "params": {"filters":{"hierarchies": ["Women", "Shoes"]}},
    "products": {
        "start": 0,
        "count": 50,
        "fields": ["id", "title", "price"],
        "filters": [
            "brand:New Balance", "price:100,500"
        ],
        "sorting": [
            "title desc"
        ]
    }
}

More information about each part of the JSON body

Name Type Description
url String (Required) The url of the page. Used for analytics.
id Integer ID of a version of a page. Only needed if you want to fetch the Draft version of a page.
format String Specify the format in which the API will return the results. html and json are accepted values, default value is html.
firstLoad Boolean (Required) Indicates if this is the first render of the page. This allows the template to only return some content on the first load. Views of the page will only be tracked if firstLoad is true. This also determines if available filters (facets) and sorting options shuold be returned
params Object (Required) Parameters that are passed as input to the page loading. Currently only the sub-object "filters" is used. Filters are used as a base filter when selecting products. See more below
trackingUserId String Hello Retail ID of the user visiting your site. This is used to apply personalization and for tracking purposes. You can get this ID server side by getting the value of the cookie named hello_retail_id.
products.start Integer (Required) Starting point when fetching products for the page.
products.count Integer (Required) Number of products to return from the starting point.
products.fields String[] Product fields to return. By default, the system will return all the fields of a product. If you want to use product data from your own database to render the products, and just need a way of knowing what products to include on the page, then you can pass "productNumber", and we will only return the productNumber for each product. You can then use the returned value to find the producs in your own database.
products.filters String[] List of filters to apply to the products. This will typically be filters enabled in a UI shown to the user to further limit the visible products, like for instance a range filter on price, or narrowing down products from a category based on brand
products.sorting String[] List sorting options to sort products by.

Base filters in params

The base filters in the params property are used to determine the gross list of products that the products.filters is applied to. This property allows complex AND/OR filters on any indexed field in your product catalog.

Examples:

By default the filters at the root level of the filters parameter are ANDed together. The following will find products in the hierarchy Women›Shoes with the brand Nike

{
    "hierarchies": ["Women", "Shoes"],
    "brand": "Nike"
}

The following examples are equivalent, and will find products from the hierarchy Shoes or Shirts

{ 
    "hierarchies": {"$or": [["Shoes"], ["Shirts"]]} 
}
{ 
    "$or": [
        {"hierarchies": ["Shoes"]},
        {"hierarchies": ["Shirts"]},
    ] 
}

The following examples are equivalent, and will find products that are in both the Female and the Shoes hierarchies

{ 
    "hierarchies": {
        "$and": [["Female"], ["Shoes"]]
    }
}
{
    "$and": [
        { "hierarchies": ["Female"]},
        { "hierarchies": ["Shoes"]}
    ] 
}

The filters can be combined and nested, like the following:

{
    "$or": [
        {
            "$and": [
                { "brand": "Nike"},
                { "isOnSale": true }
            ]
        },
        { "brand": "NoName"}
    ]
}

Response

The response will be a JSON document. The content will depend on the requested format.

Example of a response with rendered HTML:

{
    "success": true,
    "firstLoad": true,
    "products": {
        "start": 0,
        "count": 50,
        "total": 500,
        "html": "<div>Products rendered using the design selected for the page</div>",
        "javascript": "/* javascript from the design selected for the page */",
        "style": "/* css from the design selected for the page */"
    }
}

Example of a response with JSON formatted products

{
    "success": true,
    "firstLoad": true,
    "products": {
        "start": 0,
        "count": 50,
        "total": 500,
        "result": [
            {
                "title": "abc",
                "url": "url/url.com",
                "imgUrl": "imgurl/url.com",
                "currency": "DKK",
                "priceLowered": true,
                "description": "sample description",
                "keywords": "ab, gh, dd",
                "inStock": true,
                "productNumber": "product1234",
                "variantProductNumbers": [],
                "price": 233.44,
                "previousPrice": 500.23,
                "score": 7.0
            },
            ...
        ]
    }
}

  1. The reason for supporting text/plain is to allow requests to this endpoint, made from the browser, to be categorized as simple thereby avoiding CORS preflight requests. You can read more here https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS#simple_requests