Overview
The Shopping Agent API provides two endpoints: one to initiate a real-time menu scan via a Trigger.dev task, and one to retrieve a cached scan result. The scan is an asynchronous operation. Web clients can request a Trigger.dev trigger token foruseRealtimeTaskTrigger; native clients set triggerServerSide: true and subscribe to the returned run with the publicAccessToken.
Endpoints
POST /api/v1/shopping/scan-token
Creates a public Trigger.dev access token and triggers theshopping-menu-scan task. If a valid cached scan already exists for the requested dispensary, the token is returned alongside the cached result and no new task is started. If a scan for the same dispensary is already running (de-duplication check), the token for that active run is returned instead.
Request
Request Body Schema
Responses
200 OK — Cache Hit A valid scan was found in cache. No new task is triggered.triggerServerSide: true starts the Trigger.dev run from the API and returns a scoped token for subscribing to that run.
triggerServerSide is omitted or false, the API returns a short-lived token that the web client uses with useRealtimeTaskTrigger.
websiteDomain:
GET /api/v1/shopping/scan/:domain/cached
Retrieves the most recent cached scan result for a dispensary domain. Returns404 if no valid cache entry exists or if the cache has expired (4-hour TTL).
Request
Path Parameters
Response
200 OK — Cache HitData Schemas
Product
A matched menu product with strain data and personalization tags.Recommendation
An AI-generated top recommendation from the current menu.Discovery
An unmatched product flagged for potential database addition.Real-Time Progress
The mobile app does not poll for scan results. Native clients call/scan-token with triggerServerSide: true, then subscribe to the returned runId using publicAccessToken and Trigger.dev realtime SSE. Web clients can use the returned triggerToken with useRealtimeTaskTrigger and submit the task input client-side.
Progress Event Shape
Trigger.dev emits run metadata updates as the task progresses. The Shopping Agent task emits structured metadata at each stage:Native Integration
Web Integration
The shopping-menu-scan Trigger.dev Task
The Trigger.dev task runs in the @tiwih/trigger package and executes six stages in sequence.
Task ID
Trigger.dev Dashboard
View task in dashboardStage Details
Input Schema
Output Schema
Strain Matching Algorithm
The match stage runs three passes in sequence, stopping as soon as a match is found for each product.Pass 1: Exact Match
high
Pass 2: Slug Match
high
Pass 3: Trigram Match
medium if similarity > 0.6, low if 0.4–0.6
Products with no match across all three passes are placed in the discoveries array.
Database
Scan results are stored in themenu_scans table in Supabase.
Table: menu_scans
Unique constraint:
UNIQUE (website_domain, categories_hash) — prevents duplicate scans for the same dispensary and menu composition.
