# Build an SEO-friendly site
Search engines may index your listing pages: Bright's IDX rules allow it. This guide shows how
to build pages a search engine can read, with addresses that last, a sitemap, and removal that
stays prompt, all within Bright's display rules ([compliance](compliance.md)).
The short version:
1. Build each page **on your server**, with your secret key.
2. Give each listing **one address, by its `listingKey`**.
3. Write the title, the description and the structured data **only from fields the API
returned**.
4. Build your **sitemap from the key list**.
5. Answer **`410 Gone`** for a listing that was removed, and drop every stored copy of it.
## Build pages on the server
A page that fills itself in the browser, with a publishable key, is an empty page to many
crawlers. Build listing pages and search pages on your server instead:
- Your server calls the API with its **secret key** (`sk_…`), which never leaves the server,
and sends finished HTML. No CORS, no key in the page.
- Keep the publishable key (`pk_…`) for what must run in the browser: a map that moves, a
search box that completes as the visitor types, a favorite button
([map search](map-search.md), [autocomplete](autocomplete.md)).
```js
// A listing page, built on the server (Node 24, any framework).
app.get('/listing/:listingKey/:words?', async (req, res) => {
const r = await fetch(`https://api.apidata.one/v1/listings/${encodeURIComponent(req.params.listingKey)}`, {
headers: { Authorization: `Bearer ${process.env.APIDATA_SECRET_KEY}` },
});
if (r.status === 404) return res.status(removedKeys.has(req.params.listingKey) ? 410 : 404).send(gonePage());
if (!r.ok) return res.status(503).set('Retry-After', r.headers.get('retry-after') ?? '300').send(busyPage());
const { data: listing, compliance } = await r.json();
const canonical = listingPath(listing);
if (req.path !== canonical) return res.redirect(301, canonical); // the address changed: one address a listing
res.send(listingPage(listing, compliance, canonical));
});
```
## One address for each listing
Use the **`listingKey`** to find a listing, never its street address:
```js
// The slug ends with "-" and the listing key: cut that off to get the words.
function listingPath(listing) {
const words = listing.slug.slice(0, -(listing.listingKey.length + 1));
return `/listing/${listing.listingKey}/${words}`;
}
// /listing/805454359664/101-main-st-ardmore-pa-19003
// /listing/805454361120/ardmore-pa (a hidden address: city and state only)
```
- **Look the listing up by the key alone.** The words after it are decoration. When they don't
match the listing's current `slug`, redirect to the address that does, and name that address
in ``.
- **The words come from `slug`, never from your own reading of the address.** When a seller
asks that an address be hidden, the listing's `slug` loses the street at once, and with the
redirect above your old address stops showing it too.
- A listing key is text. Live keys are digits today, and sandbox keys start with `SBX`.
## Titles, descriptions and structured data
Write them from the listing as the API returned it, at that moment:
```js
function listingTitle(l) {
const where = l.address
? `${l.address.line1}, ${l.address.city}, ${l.address.state} ${l.address.postalCode}`
: `${l.statusLabel} listing`; // a hidden address: no street, in any tag
const price = l.price.list === null ? '' : ` | $${l.price.list.toLocaleString('en-US')}`;
return `${where}${price}`;
}
```
- **A hidden address appears nowhere:** not in the `
`, the meta description, an `og:`
tag, the structured data, an image's `alt` text or the page's address. A listing with
`addressDisplay: "withheld"` has `address: null` and `location: null`; write the page without
them.
- **A null field stays out.** A hidden price, hidden days on market, a Coming Soon listing's
missing price history: leave them out of every tag, and never compute them.
- **Structured data** (schema.org JSON-LD) follows the same rule: only what the page itself
shows.
```js
function listingJsonLd(l, url) {
const data = {
'@context': 'https://schema.org',
'@type': 'RealEstateListing',
url,
name: listingTitle(l),
dateModified: l.updatedAt,
image: l.photos.primary ? [l.photos.primary.full ?? l.photos.primary.medium].filter(Boolean) : [],
};
if (l.price.list !== null) data.offers = { '@type': 'Offer', price: l.price.list, priceCurrency: 'USD' };
if (l.address)
data.about = {
'@type': 'Residence',
address: {
'@type': 'PostalAddress',
streetAddress: l.address.line1,
addressLocality: l.address.city,
addressRegion: l.address.state,
postalCode: l.address.postalCode,
},
...(l.location ? { geo: { '@type': 'GeoCoordinates', latitude: l.location.lat, longitude: l.location.lng } } : {}),
};
return JSON.stringify(data).replace(/ tag
}
```
Every page built on the server carries the same disclosures as any other page with listings:
the `compliance` texts, your brokerage's name, and the listing office's name and contact near
the top of a detail page ([what goes where](compliance.md#what-goes-where)). Photos keep
`object-fit: contain`.
## A sitemap from the key list
[`GET /v1/listings/keys`](../reference/endpoints/list-listing-keys.md) lists every listing the
API serves, by key, with the time it last changed. It is for your server, with the secret key:
```js
// Every key the API serves, with when each last changed. About 210 requests for a million keys.
async function allKeys() {
const out = [];
let cursor = null;
for (;;) {
const url = new URL('https://api.apidata.one/v1/listings/keys');
url.searchParams.set('limit', '5000');
if (cursor) url.searchParams.set('cursor', cursor);
const r = await fetch(url, { headers: { Authorization: `Bearer ${process.env.APIDATA_SECRET_KEY}` } });
if (r.status === 429) {
await new Promise((done) => setTimeout(done, 1000 * Number(r.headers.get('retry-after') ?? 2)));
continue; // the same page again
}
if (!r.ok) throw new Error(`key list: ${r.status}`);
const page = await r.json();
out.push(...page.data); // { listingKey, updatedAt }
cursor = page.meta.page.nextCursor;
if (cursor === null) return out;
}
}
```
- **`updatedAt` is your ``.** The list holds no address, so a sitemap entry's address
is the key alone (`/listing/805454359664`); your page redirects it to the full address.
- **A sitemap file holds at most 50,000 addresses.** With more, write several files and a
sitemap index that names them.
- **Rebuild it on a schedule,** such as once a day. The route has a
[limit of its own](../concepts/rate-limits.md#the-key-list): one request every 2 seconds for
a key, with bursts of 5, so a full list takes a few minutes. Honour `Retry-After` on a `429`.
- **A key that was on your last list and is not on this one has left the data.** Take it out
of the sitemap, delete what you stored for it, and answer `410 Gone` for its page.
- The list is for sitemaps. **Do not use it to fetch every listing's detail ahead of time:**
build a listing's page when it is asked for (next section).
## Caching and prompt removal
A removed listing must leave your site at once, stored pages included. So store as little as
you can, for as short a time as you can:
- **Build a page when it is asked for,** from the API. To answer crawlers quickly you may keep
a built page for a short while (minutes, not days) and rebuild it after that.
- **Never show a stored page more than 12 hours old.** That is the rule the API itself keeps
for its own data.
- **Drop a listing the moment its `listing.removed` [notice](../concepts/webhooks.md) arrives:**
the stored page, any row and any image you kept. Remember only its key, so that its address
answers `410 Gone`. Register a [webhook endpoint](webhooks.md), or read
[`GET /v1/events`](../reference/endpoints/list-events.md) every minute.
- **A fetch that answers `404 listing_not_found` for a listing you stored or served** means
the same: drop it, and remember its key as removed. For a key you never served, the same
`404` says only "no such listing": the API can't tell a removed listing from one that
never existed, and neither can you.
- **During a data stop** ([`500 data_stale`](../errors/data_stale.md)), do not fall back to
stored pages. Answer `503` with a `Retry-After` header and a "temporarily unavailable" page;
a search engine then keeps the page in its index and comes back later.
- **After an `account.reinstated` notice,** re-check every listing you stored
([why](../concepts/webhooks.md#suspension-and-reinstatement)).
## What to answer for a listing that is gone
| The listing | Answer | Why |
| --- | --- | --- |
| Removed from the data, and you know it: you got its `listing.removed` notice, or you served it before and it is missing from the key list | `410 Gone`, with a plain page and links to search | It tells a search engine to drop the page for good |
| Never existed, or you can't tell: the API answers `404 listing_not_found` for both, so a key you never served is this case | `404 Not Found` | A `410` for an address that never was a page tells a search engine nothing |
| Live data is stopped (`data_stale`), or the API can't be reached | `503` with `Retry-After` | The page stays indexed |
A `410` page shows nothing of the listing: no address, no photo, no price.
## Crawlers count against your limits
Every page a crawler fetches makes your server call the API, and those calls count against
your secret key's [limits](../concepts/rate-limits.md) like any others. A crawler that takes
thousands of pages in a burst can use up the bucket your visitors share.
- The short store above absorbs most of it: a page built a minute ago is not built again.
- Slow down a crawler that asks too fast: answer it `429` or `503` with `Retry-After` from your
own server before you call the API.
- Search pages with many filters make endless addresses. Let crawlers index a small set (a
city's or a ZIP code's listings, built from `location.placeIds` or `location.postalCodes`)
and mark the rest `noindex`.
## See it working
The sample site at [demo.apidata.one](https://demo.apidata.one) is built this way, on a sandbox
key: pages built on the server, addresses by `listingKey`, a sitemap from the key list, `410`
for a removed listing, and every disclosure.
## Checklist
- [ ] Listing and search pages built on the server with the secret key
- [ ] One address a listing, found by `listingKey`; other spellings redirect to it
- [ ] Title, description and structured data from the API's fields only; nothing for a null
- [ ] A hidden address in no tag, no address and no markup
- [ ] A sitemap from `GET /v1/listings/keys`, rebuilt on a schedule, `lastmod` from `updatedAt`
- [ ] `listing.removed` handled: every copy dropped, `410 Gone` from then on
- [ ] No stored page shown past 12 hours, and none during `data_stale`
- [ ] The disclosures on every page a crawler can reach