Search via API
Search works in three steps: load the shop settings, search, and settle the search once the visitor stops typing. The visitor is created by their first search, not by the page load. All calls are POST with JSON.
Base URL of all calls: https://api.findiyra.com/ais-search-api/v1
Calls from the browser
The search API is meant for calls from your visitors' browsers. Requests without a browser identifier, e.g. straight from a server, are detected as automated access and rejected (BOT_DETECTED). That is why the curl examples send an identifier and use jq for the output.
Only from allowed domains
In the browser, the search API accepts your API key only from your shop's domains. The domain of your shop URL including its subdomains is always allowed, e.g. my-shop.com, www.my-shop.com and staging.my-shop.com. If your search runs on another domain, e.g. your own frontend, a second shop domain or locally on localhost:5173, add it in the account portal under Settings › Shop: card General information, Edit, field Allowed domains for the search widget. An entry applies including its subdomains, with a port only to that port. Calls from other domains are rejected (ORIGIN_NOT_ALLOWED). Calls without a browser, e.g. with curl, are not checked for the domain.
Try it live
This search really runs through the API, with exactly the calls below.
1. Load the shop settings
Once per page load. The response contains your shop's settings, e.g. the wait time for step 3. A new visitor has no user_id here yet (null), their first search creates it. You recognise a returning visitor by sending their stored user_identifier as uid. Then their user_id comes back.
const API_BASE = 'https://api.findiyra.com';
const SHOP_KEY = 'YOUR_API_KEY';
// Stored after the first search (see step 2), otherwise empty
const uid = sessionStorage.getItem('findiyra_uid') ?? undefined;
const res = await fetch(`${API_BASE}/ais-search-api/v1/store/identify`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ key: SHOP_KEY, uid }),
});
const { config } = await res.json();
let userId = config.user_id; // null for a new visitor# Fill in your values
API_BASE="https://api.findiyra.com"
SHOP_KEY="YOUR_API_KEY"
# Send a browser identifier from the terminal, otherwise bot detection kicks in.
curl -s -X POST "$API_BASE/ais-search-api/v1/store/identify" \
-H "Content-Type: application/json" \
-H "User-Agent: Mozilla/5.0" \
-d "{\"key\": \"$SHOP_KEY\"}" | jq .config{
"success": true,
"user_identifier": null,
"config": {
"user_id": null,
"shop_name": "My Shop",
"search_config_tracking_debounce_ms": 1000
}
}Returning visitors
The first search returns user_identifier. Store it with the visitor and send it as uid to this call on the next page load. That way it stays the same visitor. Without consent you store it for the session only (sessionStorage), permanently (localStorage) only with consent, see Consent & tracking. A made-up uid is not taken over.
2. Search
const res = await fetch(`${API_BASE}/ais-search-api/v1/store/search`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ shop_key: SHOP_KEY, user_id: userId ?? undefined, query: 'running shoes women' }),
});
const result = await res.json();
// A new visitor's first search: keep user_id and user_identifier
if (result.user_id) userId = result.user_id;
if (result.user_identifier) sessionStorage.setItem('findiyra_uid', result.user_identifier);
console.log(result.data.total, result.data.suggestions);QUERY="running shoes women"
# First search without user_id: creates the visitor
RESULT=$(curl -s -X POST "$API_BASE/ais-search-api/v1/store/search" \
-H "Content-Type: application/json" \
-H "User-Agent: Mozilla/5.0" \
-d "{
\"shop_key\": \"$SHOP_KEY\",
\"query\": \"$QUERY\"
}")
echo "$RESULT" | jq
USER_ID=$(echo "$RESULT" | jq -r .user_id)
REQUEST_ID=$(echo "$RESULT" | jq -r .search_request_id)
# Further searches with "user_id": "$USER_ID"Parameters
| Field | Required | Description |
|---|---|---|
shop_key | yes | The API key of your shop |
user_id | no | From step 1 or the first search response. Without it, the search creates the visitor and returns user_id and user_identifier. |
query | yes | The search term |
deep_search | no | true for an extended search when the first one returns few hits |
Response
{
"success": true,
"user_id": "$USER_ID",
"user_identifier": "…",
"search_request_id": "…",
"data": {
"total": 47,
"suggestions": [
{
"id": "…",
"title": "Nike Air Zoom Women",
"sku": "SW10013",
"brand": "Nike",
"price": 129.99,
"availability": "in_stock",
"image_url_external": "https://…",
"slug": "https://your-shop.com/…",
"variants": []
}
],
"brands": [],
"terms": [],
"facets": {},
"priceRange": { "min": 0, "max": 0 },
"deep_search_available": false
}
}deep_search_available is true when an extended search could find more hits. Then send the request again with "deep_search": true.
user_identifier is only included in a new visitor's first search. You need search_request_id in step 3.
3. Settle the search
If your interface searches while typing, every pause creates a search. So report the search the visitor stops at as settled. Only then it counts as a real search in the statistics in the account portal. Without this step, all searches show up there as an "interim step".
For this, wait the time from config.search_config_tracking_debounce_ms (step 1, usually 1000 ms) after the last response. If a new search comes first, the report for the old one is dropped. If the visitor submits the search on purpose, e.g. with Enter, report it right away.
await fetch(`${API_BASE}/ais-search-api/v1/store/tracking`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
keepalive: true,
body: JSON.stringify({
key: SHOP_KEY,
uid: userId,
events: [{
event_name: 'search',
source: 'search',
search_query: 'running shoes women',
search_request_id: result.search_request_id,
}],
}),
});curl -s -X POST "$API_BASE/ais-search-api/v1/store/tracking" \
-H "Content-Type: application/json" \
-H "User-Agent: Mozilla/5.0" \
-d "{
\"key\": \"$SHOP_KEY\",
\"uid\": \"$USER_ID\",
\"events\": [{
\"event_name\": \"search\",
\"source\": \"search\",
\"search_query\": \"$QUERY\",
\"search_request_id\": \"$REQUEST_ID\"
}]
}" | jquid in this call
Here uid is the user_id (from step 1 or the first search response), not the user_identifier.
Which products were shown, clicked or bought, you report with further events. How that works and when you need consent for it is described under Consent & tracking.
What comes back on errors is listed under Error codes.