Headless Query API examples

Website personalisation: Headless API integration

Here's a quick guide for adding different types of content to different pages.

The approach for each page is the same, but the examples below show asking for different types of content on different types of pages.

Home page recommendations

In this example we add two recommendation elements to the home page.

The uid and sid are not included in this request - this would be the case if the request was triggered by a customer's first ever visit to the site.

Subsequent requests will include the uid and sid.

POST "https://{{domainkey}}.store-{{locationkey}}.ometria.services/api/query"
{
   "format"        : "json",
   "elements"      : ["home_page_recs_1", "home_page_recs_2"],
   "user": {
       "ip_address"    : "99.99.99.99"
   },
   "context": {
       "page_url"      : "https://mywebsite.com/",
       "user_agent"    : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
   }
}

Category/collection page

Get products for the main set of product results on a category/collection page:

POST "https://{{domainkey}}.store-{{locationkey}}.ometria.services/api/query"
{
   "format"        : "json",
   "elements"      : ["category"],
   "user": {
       "uid"           : "ebf3175817b0423eac68a03c68a9be5f",
       "sid"           : "961c660991a547298af8b31f431a66b0",
       "ip_address"    : "99.99.99.99"
   },
   "context": {
       "category_id"   : "dresses",
       "page_url"      : "https://mywebsite.com/dresses/",
       "user_agent"    : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
   }
}

Search

Generate a search page query:

POST "https://{{domainkey}}.store-{{locationkey}}.ometria.services/api/query"
{
   "format"        : "json",
   "elements"      : ["search"],
   "user": {
       "uid"           : "ebf3175817b0423eac68a03c68a9be5f",
       "sid"           : "961c660991a547298af8b31f431a66b0",
       "ip_address"    : "99.99.99.99"
   },
   "context": {
       "page_url"      : "https://mywebsite.com/search?q=floral+dresses",
       "user_agent"    : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
   }
}

Product detail page

In this example we are asking for two recommendations:

POST "https://{{domainkey}}.store-{{locationkey}}.ometria.services/api/query"
{
   "format"        : "json",
   "elements"      : ["pdp_recs_1", "pdp_recs_2"],
   "user": {
       "uid"           : "ebf3175817b0423eac68a03c68a9be5f",
       "sid"           : "961c660991a547298af8b31f431a66b0",
       "ip_address"    : "99.99.99.99"
   },
   "context": {
       "category_id"   : "dresses",
       "product_id"    : "0189012D",
       "page_url"      : "https://mywebsite.com/dresses/green-black-floral-midi-dress",
       "user_agent"    : "Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1"
   }
}