> For the complete documentation index, see [llms.txt](https://fredhopper.gitbook.io/product-discovery/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://fredhopper.gitbook.io/product-discovery/resources/archived-pages/introduction/api-parameters/response-mask.md).

# Response mask

Select only the fields you want from the response's items

## Parameters

The **`customResponseMask`** parameter allows selecting only the attributes you want from the items in the response.

| **Name**                 | Type     | Is Required ? | Default value |
| ------------------------ | -------- | ------------- | ------------- |
| **`customResponseMask`** | `string` | ✖             | empty string  |

### `customResponeMask`

The items attributes will be filtered based on the response mask. The syntax is:

* `a,b,c` : comma-separated list will select multiple fields
* `a.b.c` : path will select a field from its parent
* `a(b,c)`: sub-selection will select many fields from a parent
* `a.*.c` : the star `*` wildcard will select all items in a field

#### Example

* **`id, product(title, price)`** will return only the id, the title and the price of the items

#### Notes

* If empty, or omitted, all fields will be returned for the items

## Response

All responses from XO Search uses the same format.\
Check [API Reference](/product-discovery/resources/archived-pages/introduction/api.md) page for a more detailed description of this format.

{% content-ref url="/pages/9oz6YlEAkw7zR7txwjhG" %}
[API Reference](/product-discovery/resources/archived-pages/introduction/api.md)
{% endcontent-ref %}

## Usage example

* Only returns the id, the product title and price

{% tabs %}
{% tab title="SDK - JS" %}
**NodeJS / NPM example**

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

const query = 'T-shirt';

search.init({ token: SEARCH_API_TOKEN });

const response = await search.query(query, {
  customResponseMask: 'id, product(title, price)'
});

console.log(response);
```

**HTML example**

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

    xo.search.query('T-Shirt', {
        customResponseMask: 'id, product(title, price)'
    }).then((response) => {
        console.log(response);
    });
</script>
```

{% endtab %}

{% tab title="API - POST" %}
**HTTP example**

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

{
  "token": "SEARCH_API_TOKEN",
  "query": "T-Shirt",
  "options": {
    "customResponseMask": "id, product(title, price)"
  }
}
```

**`curl` example**

```bash
curl -d "{\"token\":\"${SEARCH_API_TOKEN}\", \"query\":\"T-Shirt\", \"options\":{\"customResponseMask\": \"id, product(title, price)\"}}" \
     -H "Content-Type: application/json; charset=UTF-8"                                                                                   \
     -X POST "https://api-eu.attraqt.io/search"
```

**JavaScript example**

```javascript
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: 'T-Shirt',
    options: {
      customResponseMask: 'id, product(title, price)'
    }
  })
});

if (response.ok) {
  console.log(await response.json());
}
```

{% endtab %}

{% tab title="API - GET" %}
**HTTP example**

```http
GET https://api-eu.attraqt.io/search/:token?encoded=:encodedParams HTTP/1.1
```

**`curl` example**

```bash
curl "https://api-eu.attraqt.io/search/${SEARCH_API_TOKEN}?encoded=%7B%22query%22%3A%22T-Shirt%22%2C%22options%22%3A%7B%22customResponseMask%22%3A%22id%2C%20product%28title%2C%20price%29%22%7D%7D"
```

**JavaScript example**

```javascript
const token = SEARCH_API_TOKEN;
const params = encodeURIComponent(JSON.stringify({
  query: 'T-shirt',
  options: {
    customResponseMask: 'id, product(title, price)'
  }  
}));

const response = await fetch(
  `https://api-eu.attraqt.io/search/${token}?encoded=${params}`
);

if (response.ok) {
  console.log(await response.json());
}
```

{% endtab %}
{% endtabs %}
