Server-side Search and Recommendations
Use this guide when your storefront renders on a server (a custom backend, a headless storefront, server-side rendering) and cannot run the browser SDK. Your server calls Smart Search and Recommendations with a secret API key, and reports what the shopper does next so reports match what the SDK would have recorded.
Download the OpenAPI 3.1 spec for the seven routes used here: search, collection metadata, collection query, recommendations, event tracking, attribution touchpoints and commerce conversions.
All paths are relative to https://api.upsur.ge/api/v1.
Get access
- Ask Upsurge to turn on server access for your account. This is a per-merchant switch that Upsurge enables for you. It is not a setting in the dashboard. Until it is on, secret-key search and recommendations calls are refused (see Errors). Browser traffic is not affected by the switch.
- Create a secret key in Dashboard → API Keys for the site, with these five permissions:
| Permission | Used for |
|---|---|
search:read | Search and Smart Collection queries |
recommendations:read | Recommendations |
events:track | Search clicks, recommendation clicks and the purchase event |
attribution:touch | Reporting a recommendation click as an attribution touch |
commerce:convert | Reporting the order for revenue |
If the switch is still off, the API Keys page shows a notice beside the search and recommendations permissions. Keys can still be created.
- Turn on Revenue attribution for the store in Dashboard → Sites → Edit site if you want recommendation revenue. It is off by default. While it is off,
POST /attribution/touchpointsandPOST /commerce/conversionsreturn403with the message "Revenue attribution is not enabled for this website". Search, recommendations, clicks and search-attributed purchases work either way.
Send the key in X-API-Key and keep it on your server:
X-API-Key: upsurge_sk_test_replace_me
Shopper identity, session and consent
Your server owns the shopper's identity, because there is no browser SDK to keep it.
session_id: keep one stablesession_idof 8–128 characters per shopper visit, and use that same value in every call below: search, recommendations, clicks, touches and the order. Upsurge never invents one, and events without a session are not recorded. The 8–128 character limit is the touchpoint limit; use it everywhere so one ID works in every call.device_id: an anonymous ID you keep in your own cookie.merchant_user_id: your customer ID, when the shopper is signed in. You can name the customer directly with a secret key; no profile token is needed.- Consent: Upsurge records search and recommendation events only when you pass analytics consent as explicitly
true. Personalization needs its own consent. Search ignoressubject.merchant_user_idunlessconsent.personalizationistrue: the results are not personalized and the recorded search event does not carry it. Recommendation impressions never carry a user ID, because recommendations has no personalization consent flag.
Those consent checks cover only the events Upsurge records for search and recommendations. The calls your server makes itself are trusted as sent:
/events/trackrecords a secret-key event without checking consent, and the event goes through full processing: shopper profiles, workflows and connected destinations. Send clicks and purchases only for shoppers who allowed analytics, and mark each one withcontext.analytics_consent: true.- Recommendations uses the shopper IDs you send (
merchant_user_id,device_id) to look up the shopper's profile and history, and has no consent flag for that. Send them only for shoppers who allowed personalization. Without them the shopper gets recommendations that are not personalized, and a campaign in an experiment serves its base behavior instead of a variant.
Search
POST /storefront/search needs search:read. The body is the same as the browser search request.
curl --request POST 'https://api.upsur.ge/api/v1/storefront/search' \
--header 'Content-Type: application/json' \
--header 'X-API-Key: upsurge_sk_test_replace_me' \
--data '{
"q": "running shoes",
"surface": "headless",
"per_page": 12,
"consent": { "personalization": false, "analytics": true },
"subject": { "session_id": "sess_2f9c1a7d4b", "device_id": "dev_8c13e0aa" }
}'
The results are in data. Each product in data.products has product_id (the Upsurge ID) and external_id, your own product ID. A product may lack external_id if it has none. data.search_id identifies the search; you send it back with clicks. The top-level meta holds only the response's timestamp and request_id.
A search is recorded as a search event when consent.analytics is true, subject.session_id is present and the query is not blank. Without personalization consent, subject.session_id and subject.device_id are used for analytics only.
Smart Collections work the same way: GET /storefront/collections/{slug} returns public metadata in data.collection, and POST /storefront/collections/{slug}/query takes the search body. A collection query returns data.collection and data.result, which is shaped like data of a search response, so its products are in data.result.products. An unknown or inactive slug is a 404. A collection query also records a smart_collection_impression.
Recommendations
GET /recommendations needs recommendations:read.
curl 'https://api.upsur.ge/api/v1/recommendations?context=product_page&external_product_id=SKU-1042&limit=6&session_id=sess_2f9c1a7d4b&analytics_consent=true' \
--header 'X-API-Key: upsurge_sk_test_replace_me'
- Your own product IDs. Send
external_product_id(one, forproduct_page) orexternal_product_ids(up to 50, repeated or comma-separated, forcart_pageandcheckout) instead ofproduct_idandproduct_ids. Mixing the two kinds is a400. IDs resolve against your own site only. Unknown IDs insideexternal_product_idsare dropped; an unknownexternal_product_idis a400. - Impressions. Each serve is recorded as one
recommendation_impressiononly when you send bothanalytics_consent=trueandsession_id. Only the literaltruecounts. A serve with no recommendations records nothing, except in a running experiment, where the impression is recorded even when the response is empty and carries the experiment. - Items are in
data.recommendationsand carryexternal_idandskuwhen the product has them. data.meta(not the top-levelmeta) carriesrecommendation_idandcampaign_id, which you send with the click. When a campaign matched, it also carriesattribution_delivery_token, which you need for the touch below. Without a matching campaign,campaign_idisdefaultand there is no token, so the click earns no recommendation revenue.
Report what the shopper does
Reports only credit search and recommendations if your server sends the shopper's actions back. A full integration sends these calls, each carrying the same session_id.
| When | Call | Permission |
|---|---|---|
| A search result is clicked | POST /events/track, search_result_click | events:track |
| A recommendation is clicked | POST /events/track, recommendation_click | events:track |
| A recommendation is clicked | POST /attribution/touchpoints, a product touch | attribution:touch |
| An order is placed | POST /events/track, purchase | events:track |
| An order is placed | POST /commerce/conversions, purchase | commerce:convert |
Secret-key touchpoint calls need no Origin or Referer header. The touch and the commerce conversion need Revenue attribution turned on for the store (see Get access).
Which product ID to use
Search attribution compares Upsurge product IDs, so click events carry the product_id from the response. A purchase can instead carry your own IDs in properties.external_product_ids (up to 50). Send these purchases to /events/track, not /events/batch, which does not resolve them. Unknown IDs are dropped without an error.
Recommendation experiments
When the campaign is in a running experiment, the recommendations response carries data.meta.experiment. Experiment results count a click or a purchase only when the event carries that object, so your server has to copy it, unchanged, as properties.experiment:
- onto the shopper's
recommendation_click, withproperties.campaign_idset to the response'sdata.meta.campaign_id; - onto the shopper's
purchaseevents after that click, while they fall within the experiment's conversion window:experiment.conversion_window_hourshours from the serve.
The browser SDK does this itself. Without it, the experiment shows impressions but no clicks or conversions.
End-to-end example
One shopper visit, from search to order. Every call uses session_id sess_2f9c1a7d4b.
1. Search, with analytics consent and the session. The response returns search_id srch_01JEXAMPLE.
POST /storefront/search
{
"q": "running shoes",
"consent": { "personalization": false, "analytics": true },
"subject": { "session_id": "sess_2f9c1a7d4b" }
}
2. The shopper clicks the second result. Report it with the search_id, the query, the product's product_id and the position.
POST /events/track
{
"event_type": "search_result_click",
"session_id": "sess_2f9c1a7d4b",
"properties": {
"search_id": "srch_01JEXAMPLE",
"query": "running shoes",
"product_id": "prod_7f3a",
"position": 2
},
"context": { "page_url": "https://shop.example.com/search?q=running+shoes", "user_agent": "ExampleStorefront/1.0", "analytics_consent": true }
}
3. Fetch recommendations on the product page. The response's data.meta returns recommendation_id rec_01JEXAMPLE, campaign_id camp_01JEXAMPLE and an attribution_delivery_token.
GET /recommendations?context=product_page&external_product_id=SKU-1042&session_id=sess_2f9c1a7d4b&analytics_consent=true
4. The shopper clicks a recommendation. Report the click event:
POST /events/track
{
"event_type": "recommendation_click",
"session_id": "sess_2f9c1a7d4b",
"properties": {
"recommendation_id": "rec_01JEXAMPLE",
"campaign_id": "camp_01JEXAMPLE",
"product_id": "prod_91bc"
},
"context": { "page_url": "https://shop.example.com/products/trail-shoe", "user_agent": "ExampleStorefront/1.0", "analytics_consent": true }
}
5. Report the touch, with the attribution_delivery_token from the recommendations data.meta. Without the delivery token the touch is stored but earns the campaign no revenue; a token older than 24 hours is refused.
POST /attribution/touchpoints
{
"schema_version": 1,
"consent": { "analytics": true, "advertising": false },
"touchpoints": [{
"schema_version": 1,
"touchpoint_id": "tp_01JEXAMPLE0001",
"session_id": "sess_2f9c1a7d4b",
"occurred_at": "2026-11-21T10:15:00Z",
"kind": "product",
"state": "recommendation",
"channel": "recommendation",
"campaign_id": "camp_01JEXAMPLE",
"campaign_type": "recommendation",
"product_interaction": "recommendation_click",
"delivery_token": "ATTRIBUTION_DELIVERY_TOKEN"
}]
}
The response returns a journey_token. Keep it with the shopper's session and send it with the next touch and with the order.
6. The order is placed. Send the purchase event, for search attribution:
POST /events/track
{
"event_type": "purchase",
"session_id": "sess_2f9c1a7d4b",
"properties": {
"transaction_id": "order_10045",
"total_amount": 129.9,
"currency": "EUR",
"external_product_ids": ["SKU-1042", "SKU-2210"]
},
"context": { "page_url": "https://shop.example.com/checkout/thank-you", "user_agent": "ExampleStorefront/1.0", "analytics_consent": true }
}
7. Send the commerce conversion, with the journey_token, for recommendation revenue. Amounts are in minor units.
POST /commerce/conversions
{
"schema_version": 1,
"event_type": "purchase",
"idempotency_key": "order_10045_purchase",
"website_id": "site_01JEXAMPLE",
"order_id": "order_10045",
"occurred_at": "2026-11-21T10:22:00Z",
"source": "trusted_server",
"currency": "EUR",
"revenue_minor": 12990,
"journey_token": "JOURNEY_TOKEN_FROM_STEP_5"
}
Reporting one order as both a purchase event and a commerce conversion does not double count it. Attribution deduplicates by order, and revenue reports read the two from separate tables.
Errors and reason codes
Errors use the standard envelope. A 400, 403 or 429 can carry error.details.reason:
| Status | reason | Meaning |
|---|---|---|
403 | server_api_not_enabled | Upsurge has not turned on server access for your account. |
403 | merchant_inactive | The merchant account is suspended or inactive. |
403 | recommendations_disabled | Recommendations are off for the key's site. |
400 | unknown_external_product_id | The external_product_id matches no product on the site. |
400 | ambiguous_external_product_id | The ID matches more than one product on the site. |
429 | search_monthly_allowance_exceeded | Search or a collection query used up the plan's monthly search allowance. |
search_monthly_allowance_exceeded is a monthly allowance, not a rate limit. The response has no X-RateLimit-Reset, and retrying does not help until the allowance renews at the start of the next month (UTC).
Other responses: 401 for a missing or invalid key, 403 for a key without the permission, 403 from /attribution/touchpoints or /commerce/conversions when Revenue attribution is off for the store, 404 for an unknown or inactive collection slug, 429 without a reason when the hourly rate limit is used up (wait until X-RateLimit-Reset, then retry with jitter), and 503 when a dependency is unavailable (retry with backoff). A server-API access check that cannot read its data returns 503.
Limits, caching and latency
- Secret-key calls are rate limited per account over a sliding hour. Every call in this guide (search, collections, recommendations, event tracking, touchpoints and conversions) draws on that one hourly budget, across all of your account's secret keys. Upsurge sets your key's limit when it turns on server access; ask if you need a higher one.
- Searches and recorded events count against your plan's monthly search and event allowances. A used-up event allowance never changes the search or recommendations response: it only stops recording.
- Recorded events are published after the response is sent, so they add no latency and a failure never fails the call.
- Search responses are
Cache-Control: no-store. Do not cache them across shoppers; if you cache on your side, key the cache by the full request including consent and identity. - Call search and recommendations in parallel when a page needs both, and set a short client timeout so a slow call never blocks rendering.