Crownpeak
  • Product Discovery Developer Guide
  • 🛒Item catalog management
    • What is the Items API?
    • How to work with Items
      • Item Schema
        • Attributes
        • Nested Item Schemas
        • Using the Item Schema API
        • DefaultLocale API
        • Onboarding on/migrating to Fredhopper
        • List of Reserved Attributes
      • Category Tree
        • Using the Category Tree API
        • Onboarding on XO
      • Item Catalog
        • Using the Catalog API
      • Items
        • Using the streaming Items API
        • Using the batch Items API
    • Step by Step guide
      • Step by step guide for Fredhopper customers
    • Feedback
      • Using the Feedback API
    • Authorization to APIs
    • Troubleshooting API errors
  • 🎯XO Recommendations
    • Introduction
    • Using the Recommendations API
    • Setting up the Chrome extension
    • Micro-segmentation
    • XO Legacy APIs
  • 🔎XO Search
    • Introduction
    • Getting started
    • API Reference
      • Search API
      • Autocomplete API (Beta)
      • Product Suggest API
    • API Parameters
      • Search
      • Pagination
      • Faceting
      • Sorting
      • Grouping
      • Filtering
      • Disable features
      • Response mask
      • Context
    • Configuration limitation
  • 🧪A/B testing
    • Fredhopper A/B testing
      • Integration steps for a non-caching solution
      • Integration steps for a caching solution
        • Java SDK Integration
          • Setup
          • Retrieve running A/B tests - Java SDK
          • Filter and request variant - Java SDK
          • Extending the SDK
        • Manual A/B tests integration
          • Retrieve running A/B tests
          • Filter out irrelevant A/B tests
          • Assign variants to user
          • Request variant for page
        • Limitations and Best Practices
  • 📚Resources
    • Glossary
    • Best Practices
      • Tracker Best Practices
      • Items API Best Practices
      • Fredhopper Data Configuration Best Practices
      • Fredhopper Query Response Best Practices
      • Fredhopper Merchandising Studio Best Practices
    • Privacy Notice
  • Archived Pages
    • FHR Tracking plan
    • XO Tracking plan
    • The Tracking API and JS Library
      • What to Track
        • Generic Actions
          • View
          • Click
          • Add to Cart
          • Remove from Cart
          • Purchase
        • Custom Actions
      • Initializing the JavaScript Library
      • REST API Technical Documentation
Powered by GitBook
On this page
  • Parameters
  • variables
  • System variables
  • Usage example
  1. XO Search
  2. API Parameters

Context

Add contextual information to your queries

Parameters

To add contextual information to you queries, you can use the following parameters:

Parameter
Type
Is Required?

variables

object

✖

variables

The variables that you want to make available to your custom triggers. The object is composed of a key/value pair.

Supported types are:

  • String

  • Long (int64)

  • Double (float64)

  • Date (as a String with ISO-8601 format. Such as 2023-01-01T00:00:00+01:00)

  • Boolean

  • Array of String

System variables

XO Search uses some variables internally, that are available to your custom triggers. You can use them to customize your search results. You cannot set variables with these names in your context.

Variable name
Type
Description

$SEARCH_QUERY

string

The query that was used to perform the search.

$SEARCH_FACET_*

array

The facets that were used to perform the search.

$SEARCH_TAGS_FACET_*

array

The facets that were used to perform the search.

$SEARCH_DATE_TIME

date

The date and time of the search.

$SEARCH_HOUR

long

The hour of the search. (Server time!) Range: 0-23

Configure your own variables!

To configure your variables please visit the XO Console.

In the side menu expand the "Developer" section and click on "Variables".

Here you can create and modify your own variables.

(As of this moment system variables are not editable.)

Usage example

SDK - JS

NodeJS / NPM example

import { search } from '@attraqt/search';

const query = '';

search.init({ token: SEARCH_API_TOKEN });

const requestOptions = {}

const context = {
  variables: {
    '$my-variable': 'my-value'
  }
};

const response = await search.query(query, requestOptions, context);
console.log(response);

HTML example

<script type="text/javascript">
    xo.init({
        search: {
            token: SEARCH_API_TOKEN
        }
    });
    
    const requestOptions = {}

    const context = {
      variables: {
        '$my-variable': 'my-value'
      }
    };
    
    xo.search.query('', requestOptions, context).then((response) => {
        console.log(response);
    });
</script>

API - POST

HTTP example

POST https://api-eu.attraqt.io/search HTTP/1.1
Content-Type: application/json; charset=UTF-8

{
   "token": "SEARCH_API_TOKEN",
   "query": "",
   "context": {
      "variables": {
         "$my-variable": "my-value"
      }
   }
}

curl example

curl -d "{\"token\":\"${SEARCH_API_TOKEN}\", \"query\":\"\", \"context\":{ \"variables\": { \"$my-variable\": \"my-value\"}}}" \
     -H "Content-Type: application/json; charset=UTF-8"              \
     -X POST "https://api-eu.attraqt.io/search"

JavaScript example

const response = await fetch('https://api-eu.attraqt.io/search', {
  method: 'POST',
  headers: {
    'Content-Type': 'application/json; charset=UTF-8'
  },
  body: JSON.stringify({
    token: SEARCH_API_TOKEN,
    query: '',
    context: {
        variables: {
            '$my-variable': 'my-value'
        }
    }
  })
});

if (response.ok) {
  console.log(await response.json());
}
PreviousResponse maskNextConfiguration limitation

Last updated 2 years ago

🔎