# Saved searches and alerts A visitor saves a search and is told when a listing newly matches it. The API keeps the search and works out the matches; **your site tells the visitor**, by email or however you like. This guide walks through the whole loop. 1. The visitor signs in to **your** site. Your server gives them an opaque client ID. 2. They save a search: `POST /v1/saved-searches`, with an alert frequency. 3. The API records a **notice** when listings newly match. 4. Your server receives the notice (a webhook, or the events list) and fetches the listings. 5. Your site sends the email, with the disclosures an email needs. ## 1. Who the visitor is Saved searches belong to one visitor of your site. The API never sees who they are: your server chooses an **opaque client ID** for each (a UUID is fine; never an email address or a phone number) and speaks for them in one of two ways ([authentication](../concepts/authentication.md#acting-for-one-consumer-client-tokens)): - **from your server:** your secret key plus `X-Client-Id: `; - **from the browser:** your publishable key plus `X-Client-Token`, a short-lived token your server mints for that visitor with [`POST /v1/client-tokens`](../reference/endpoints/create-client-token.md). Keep the link between the client ID and the visitor's email address in your own database. You need it in step 5, and the API never has it. ## 2. Save the search The `criteria` are the filters of a search, exactly as [`POST /v1/listings/search`](../reference/endpoints/search-listings.md) takes them, without paging or sorting: ```bash curl -X POST "https://api.apidata.one/v1/saved-searches" \ -H "Authorization: Bearer $SK_TEST" -H "X-Client-Id: 6b1f0a52-visitor" \ -H "Content-Type: application/json" -H "Idempotency-Key: $(uuidgen)" \ -d '{"name":"Ardmore under 500k","criteria":{"status":["active"],"price":{"max":500000},"location":{"placeIds":["pl_…"]}},"alertFrequency":"daily"}' ``` - **`alertFrequency` is required:** `instant`, `daily`, `weekly` or `off`. Ask the visitor; never guess it. - **Send an `Idempotency-Key`,** so that a repeat after a lost answer does not save the search twice ([idempotency](../concepts/idempotency.md)). - A visitor may keep up to 100 saved searches. - To save a search around a drawn shape (Premium), [save the shape](../reference/saved-shapes.md) first and put its `location.shapeId` in the criteria. Show the visitor their searches with `GET /v1/saved-searches`, let them change the frequency with `PATCH`, and delete with `DELETE` ([reference](../reference/saved-searches.md)). **Show each search's `status`.** A search that reads `paused_tier`, `paused_suspended` or `paused_invalid` is making no alerts, and the visitor should know. A `paused_invalid` search is fixed by saving new criteria. ## 3. What alerts, and when A listing alerts when it is **new**, when its **price** or **status** changes, or when it comes **back on the market**, and it matches the search at the moment the notice is made. | `alertFrequency` | The notice is made | | --- | --- | | `instant` | after each data update, usually within minutes of the change | | `daily` | once a day at 7:00 am Eastern, for the day before | | `weekly` | Mondays at 7:00 am Eastern, for the week before | | `off` | never: the search is only kept | **Listings that already match when the search is saved never alert.** Your site shows those itself, at the moment of saving, with an ordinary search. The same holds after the criteria change and after alerts are turned back on. ## 4. Receive the notice A notice is thin: IDs and the kind of change, never listing content. ```json { "id": "evt_3yQ8mT1xKp7Zc2Nf5Rb9Wd", "type": "saved_search.matches", "createdAt": "2026-11-10T15:00:00.000Z", "accountId": "0b9f6c1e-52a7-4c3e-9d41-7a6f0c2b8e15", "clientId": "6b1f0a52-visitor", "savedSearchId": "ss_Hq2Lw9Xc4Vb7Nm1Kp6Tz3R", "listingKeys": ["300451207716"], "changes": [{ "listingKey": "300451207716", "reasons": ["new"] }] } ``` Take notices one of two ways ([webhooks and notices](../concepts/webhooks.md)): - **A webhook:** the API sends each notice to an `https://` address on your server ([the webhooks guide](webhooks.md)). - **The events list:** your server asks [`GET /v1/events`](../reference/endpoints/list-events.md) every minute for what is new. No public address is needed. Either way, **de-duplicate by the notice's `id`**: the same notice can reach you twice. ## 5. Send the email For each notice: 1. Find the visitor by `clientId` in your own database. If they have unsubscribed, stop. 2. Fetch each listing in `listingKeys` **now**: `GET /v1/listings/{listingKey}`. Never build an email from a copy you stored. - `404 listing_not_found`: the listing has left the data. Leave it out. - `500 data_stale`: live data is stopped. Send nothing with listing content, and try later. 3. Fetch [`GET /v1/compliance`](../reference/compliance.md) once for the texts the email must carry. 4. Send it from your own mail system, to that visitor only. **apidata.one never emails your visitors**, and never has their addresses. An email that shows a listing is a display of Bright's data, with rules of its own: [alert emails](alert-emails.md) lists every element and where its text comes from. ## Favorites alert too A visitor's [favorites](../reference/favorites.md) make two kinds of notice, in the same way: `favorite.listing_updated` (a price, a status, the photos or an open house changed) and `favorite.listing_removed` (the listing left the data: the favorite is gone, and so must be any copy of the listing you kept). ## Try it now, on the sandbox The [sandbox](sandbox.md) changes by itself every 5 minutes, so a saved search there alerts before long. To see one at once, send a [sandbox trigger](../reference/sandbox-triggers.md) with the saved search's ID, and read the notice within about 10 seconds: ```bash curl -X POST "https://api.apidata.one/v1/sandbox/triggers" \ -H "Authorization: Bearer $SK_TEST" -H "X-Client-Id: 6b1f0a52-visitor" -H "Content-Type: application/json" \ -d '{"event":"saved_search.matches","savedSearchId":"ss_…"}' curl -H "Authorization: Bearer $SK_TEST" "https://api.apidata.one/v1/events" ``` ## When a visitor leaves `DELETE /v1/clients/{clientId}` removes everything the API holds for one visitor: favorites, saved searches, saved shapes and their notices. Call it when a visitor closes their account with you or asks to be forgotten ([reference](../reference/endpoints/delete-client.md)). ## Good to know - **While your account is suspended** no notice is made for a saved search or a favorite's change, and what happened meanwhile never alerts later. After `account.reinstated`, [re-check the listings you stored](../concepts/webhooks.md#suspension-and-reinstatement). - **After a downgrade to Basic,** searches with Premium criteria read `paused_tier`. Nothing is deleted, and they are active again when the account is Premium. - **More than 500 matches** at once are split over several notices. - **A very large data repair** can hold alerts back for a person to look at ([when a notice is late](../concepts/webhooks.md#when-a-notice-is-late)).