# Our listings

Source: https://help.ruuster.com/idx/recipe-our-listings

> An /our-listings page with your brokerage's own listings, rendered on your server, each linking to its listing page and your tour form.

A page at `/our-listings` with your brokerage's own listings: the listings of your agents and of the
offices Ruuster has confirmed as yours. One parameter, `ownListings=1`, asks for them, and it needs no
location. Each card links to its listing page, where your tour form sends requests to your CRM.

## What the visitor sees

<figure class="idx-shot"><img src="/idx-docs/screens/ours/listing-grid-1440.png" alt="Listing grid with the disclaimers under it, on a desktop (1440 px wide)" width="1440" height="900" loading="lazy" decoding="async"><figcaption>Your listings in the card grid.</figcaption></figure>

<figure class="idx-shot"><img src="/idx-docs/screens/ours/listing-grid-375.png" alt="Listing grid with the disclaimers under it, on a phone (375 px wide)" width="375" height="1403" loading="lazy" decoding="async"><figcaption>Your listings in the card grid.</figcaption></figure>

The markup is `static/html/listing-grid.html` in `@ruuster/idx-recipes`. The [HTML and CSS recipe](https://help.ruuster.com/idx/recipe-html-css) shows how to fill it and which stylesheet and script to load.

## What the page calls

| When | Request | Key | Cached |
|---|---|---|---|
| Each page view | `GET /v1/listings` with `ownListings=1` | secret key, on your server | 5 minutes by Next.js |

cURL:

```bash
curl -s -G "https://idx.ruuster.com/v1/listings" \
  --data-urlencode ownListings=1 \
  --data-urlencode status=active \
  --data-urlencode status=coming_soon \
  --data-urlencode status=pending \
  --data-urlencode limit=24 \
  --data-urlencode pageHref=/our-listings \
  -H "Authorization: Bearer $IDX_SECRET_KEY"
```

TypeScript:

```typescript
import { createClient } from "@ruuster/idx";

const idx = createClient({ secretKey: process.env.IDX_SECRET_KEY });

const r = await idx.search({
  ownListings: true,
  status: ["active", "coming_soon", "pending"],
  limit: 24,
  pageHref: "/our-listings",
});
if (!r.ok) throw new Error(`${r.error.code}: ${r.error.message}`);
console.log(r.data);
```

Python:

```python
import os

import requests

res = requests.get(
    "https://idx.ruuster.com/v1/listings",
    params={
        "ownListings": "1",
        "status": ["active", "coming_soon", "pending"],
        "limit": "24",
        "pageHref": "/our-listings",
    },
    headers={"Authorization": "Bearer " + os.environ["IDX_SECRET_KEY"]},
    timeout=30,
)
body = res.json()
if not body["ok"]:
    raise RuntimeError(body["error"]["code"] + ": " + body["error"]["message"])
print(body["data"])
```

PHP:

```php
<?php

// Repeated names are sent once per value: http_build_query would add [] to them.
$pairs = [
    ['ownListings', '1'],
    ['status', 'active'],
    ['status', 'coming_soon'],
    ['status', 'pending'],
    ['limit', '24'],
    ['pageHref', '/our-listings'],
];
$query = implode('&', array_map(fn ($p) => rawurlencode($p[0]) . '=' . rawurlencode($p[1]), $pairs));
$ch = curl_init('https://idx.ruuster.com/v1/listings' . '?' . $query);
curl_setopt_array($ch, [
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_HTTPHEADER => ['Authorization: Bearer ' . getenv('IDX_SECRET_KEY')],
    CURLOPT_TIMEOUT => 30,
]);
$body = json_decode(curl_exec($ch), true);
curl_close($ch);
if (!$body['ok']) {
    throw new RuntimeException($body['error']['code'] . ': ' . $body['error']['message']);
}
print_r($body['data']);
```

When Ruuster does not yet have your agents' MLS ids, the API answers 422
`own_listings_unconfigured` and the page answers 404. Ask Ruuster support (`helpme@ruuster.com`) to add them.

## Steps

1. Add `lib/idx.ts`, `lib/site.ts` and `components/results.tsx` from the
   [recipes overview](https://help.ruuster.com/idx/recipes), and `lib/area-query.ts` and
   `lib/results.ts` from the [search page recipe](https://help.ruuster.com/idx/recipe-search-page).
2. Create `app/our-listings/page.tsx` with the code below.
3. Build the [listing detail page](https://help.ruuster.com/idx/recipe-listing-detail) with its tour
   form, so each card leads to a page that takes a tour request.
4. Open `http://localhost:3000/our-listings` and check the cards are your listings.

## The code

<p class="code-title"><code>app/our-listings/page.tsx</code></p>

```tsx
// /our-listings: your brokerage's own listings (your agents' and your confirmed offices').
// ownListings needs no location. Each card links to its listing page, where the tour form is.
import { notFound } from "next/navigation";
import { Results } from "@/components/results";
import { idx } from "@/lib/idx";
import { PAGE_SIZE, visitorQuery, type CardQuery } from "@/lib/area-query";
import { failureAction, resultsMetadata } from "@/lib/results";
import { SITE_NAME } from "@/lib/site";

export const revalidate = 300;

type Props = { searchParams: Record<string, string | string[] | undefined> };

function query(searchParams: Props["searchParams"]): CardQuery {
  return { ...visitorQuery(searchParams), ownListings: true, status: ["active", "coming_soon", "pending"], limit: PAGE_SIZE, pageHref: "/our-listings" };
}

export async function generateMetadata({ searchParams }: Props) {
  const r = await idx.search(query(searchParams));
  return r.ok ? resultsMetadata(r.data.head, `Listings from ${SITE_NAME}`) : {};
}

export default async function OurListings({ searchParams }: Props) {
  const r = await idx.search(query(searchParams));
  if (!r.ok) {
    if (failureAction(r) === "not_found") notFound();
    throw new Error(`Listings API ${r.status} ${r.error.code}`);
  }
  return (
    <main>
      <h1>{`Listings from ${SITE_NAME}`}</h1>
      <Results r={r} basePath="/our-listings" searchParams={searchParams} listName="Our listings" emptyText="We have no listings on the market right now." />
    </main>
  );
}
```

## Forms and your CRM

The tour form is on each listing page, and it posts to your own route, which sends the request to
your CRM with the listing attached ([Registration, tour and contact forms](https://help.ruuster.com/idx/recipe-forms),
[Your CRM](https://help.ruuster.com/idx/crm-overview)).

## Rules this page follows

**MUST**

- Show each card's attribution line where its board requires one, and every board's disclaimer.
- Link each card to your own listing page.

**NEVER**

- Add listings to the page by hand or copy them from another site.
- Describe your listings by who they suit ([Fair housing](https://help.ruuster.com/idx/fair-housing)).

## Test it

```sh
curl -s http://localhost:3000/our-listings | grep -o 'href="[^"]*/homes/[^"]*"' | sort -u | wc -l
```

The count matches the cards on the page. Open a card and send a test tour request: it arrives in your
CRM with the listing attached.

## Build it with AI

```text
Read RUUSTER_IDX.md first and follow its MUST and NEVER rules. Ask me if it doesn't cover something.

Build an "Our listings" page at /our-listings that follows <https://help.ruuster.com/idx/recipe-our-listings>. Call GET /v1/listings with ownListings=1 on the server and render the ListingGrid, Pagination and MlsDisclaimers components. Each card links to my listing page, and the listing page carries the TourForm, which posts to my own lead route and from there to my CRM (<https://help.ruuster.com/idx/recipe-forms>). If the API answers own_listings_unconfigured, stop and tell me, because Ruuster needs my agents' MLS ids first.

Use these environment variables: IDX_SECRET_KEY (server only), SITE_ORIGIN and SITE_NAME. Never paste a secret key into a chat, and never put IDX_SECRET_KEY in browser code, a URL or a log. No key goes in any page: my pages call my own /api/idx route, made with createListingsRoute from @ruuster/idx/route, which adds my secret key on the server (on a site with no server, the widgets call the API with no key from my approved website address).

Fair housing: describe homes, places and amenities only. Never describe the people who live in an area or who a home or area suits, and never rank schools as a reason to buy.

When you are done, show me how to send a test tour request and find it in my CRM.
```

On a site without React, such as PHP, Python, Ruby on Rails, Go or plain HTML, [Build without React: HTML, CSS and JavaScript](https://help.ruuster.com/idx/recipe-html-css) gives you the same markup, the stylesheet and the script for every widget.
