Skip to main content

Suggestions

Get real-time search suggestions.

Endpoint

GET /api/suggestions

Headers

HeaderRequiredDescription
X-Widget-TokenYesAuthentication token

Query params

ParamTypeRequiredDescription
qstringYesPartial query
limitnumberNoNumber of suggestions (default: 5)

Response

{
"suggestions": [
{
"type": "query",
"text": "running shoes",
"count": 150
},
{
"type": "category",
"text": "Sports Shoes",
"count": 320
},
{
"type": "brand",
"text": "Nike",
"count": 85
},
{
"type": "product",
"text": "Nike Air Max 90",
"product": {
"id": "prod_123",
"name": "Nike Air Max 90",
"price": 129.99,
"imageUrl": "https://..."
}
}
]
}

Suggestion types

TypeDescription
queryRelated popular search
categoryMatching category
brandMatching brand
productSpecific product

Example

curl -X GET "https://api.neuroon.ai/api/suggestions?q=shoe&limit=5" \
-H "X-Widget-Token: YOUR_TOKEN"

Implement debounce to avoid excessive requests:

import { debounce } from 'lodash';

const fetchSuggestions = debounce(async (query) => {
const response = await fetch(
`https://api.neuroon.ai/api/suggestions?q=${encodeURIComponent(query)}`,
{ headers: { 'X-Widget-Token': token } }
);
return response.json();
}, 150);

input.addEventListener('input', async (e) => {
if (e.target.value.length >= 2) {
const { suggestions } = await fetchSuggestions(e.target.value);
renderSuggestions(suggestions);
}
});

Notes

  • Minimum 2 characters to get suggestions
  • Suggestions are sorted by relevance
  • The count field indicates related products