> ## Documentation Index
> Fetch the complete documentation index at: https://docs.newlead.ai/llms.txt
> Use this file to discover all available pages before exploring further.

# Show your properties on your website

> List your published properties with their photos and keep your website up to date.

[`GET /v1/properties`](https://docs.newlead.ai/api-reference/properties/list-properties) returns the properties of your subaccount that have at least one published listing, most recently added first, with their photos: the ones on Idealista and the ones you send from your CRM (below). A property you withdraw drops out of the list.

**1. Call the API from your server**

Your API key also reads your leads and conversations, so it must never reach the browser. Browsers cannot call the API anyway: requests from other websites are rejected. Fetch the list from your backend, or when you build your site.

**2. Fetch every page**

Request 100 properties at a time and follow `next_cursor` until `has_more` is `false`:

```javascript Node.js theme={null}
async function listProperties() {
  const properties = [];
  let cursor;
  do {
    const url = new URL("https://rest.newlead.ai/v1/properties");
    url.searchParams.set("limit", "100");
    if (cursor) url.searchParams.set("cursor", cursor);
    const res = await fetch(url, {
      headers: { Authorization: `Bearer ${process.env.NEWLEAD_API_KEY}` },
    });
    if (!res.ok) throw new Error(`NewLead API responded ${res.status}`);
    const page = await res.json();
    properties.push(...page.data);
    cursor = page.has_more ? page.next_cursor : undefined;
  } while (cursor);
  return properties;
}
```

If a page answers `400 parameter_invalid` on `cursor`, a property was withdrawn while you were reading: start again from the first page.

**3. Cache the list**

Store the list and refresh it every few minutes instead of calling the API on every visit. Each API key can make 120 requests per minute, as described in [Rate limits](https://docs.newlead.ai/rate-limits.md).

**4. Map the fields**

| On your website | Field |
| - | - |
| Title | `type_label` and `city`, or `summary`, a ready-made line in Spanish |
| Price | `price` of each item in `listings` with `available: true`. `operation` is `sale` or `rent`, and rent is per month. |
| Photos | `images[].url`, in order |
| Rooms and size | `bedrooms`, `bathrooms`, `built_m2` |
| Location | `address`, which is `null` when the listing hides it, `city` and `province` |
| Description | `description` and `features` |
| Link to Idealista | `url` |

`agent_notes` are the internal notes for your agent: do not publish them.

## Upload your catalog from your CRM

If your properties are not on Idealista, send them from your CRM with [`PUT /v1/properties/{reference}`](https://docs.newlead.ai/api-reference/properties/create-or-replace-a-property). Your agents find them like any other property, and `GET /v1/properties` lists the available ones.

* `reference` is your CRM's reference: 1 to 50 letters, digits, dots, hyphens or underscores, and not only dots. If yours have spaces or other characters, replace them the same way every time.
* Each `PUT` replaces the whole property, so send every field each time. A photo already copied is not downloaded again: sending your whole feed every day is cheap. Send the requests for one reference one at a time.
* Set `available` to `false` when a property is reserved or sold but your agents should still recognise it by its reference. [`DELETE`](https://docs.newlead.ai/api-reference/properties/delete-a-property) it when it leaves your catalog.
* `features` takes `terrace`, `balcony`, `lift`, `parking`, `pool`, `garden`, `air_conditioning`, `storage_room`, `fitted_wardrobes` and `pets_allowed`. In the response, `features` is a line of text in Spanish, the one your agents read.
* Photos: up to 50, JPG, PNG or GIF, at a public URL that answers without redirects. A photo that cannot be copied comes back in `warnings` and the property is saved without it. `image_not_copied` means the URL does not work (not an image, an HTTP error, a redirect, too slow or larger than 20 MB): fix it at the source. `image_deferred` means it was not copied in time or we had a temporary problem: send the same `PUT` again, photos already copied are reused by URL.

This script reads an XML feed, sends each property and deletes the ones that are no longer in the feed. It remembers what it sent in `uploaded.json`.

```javascript Node.js theme={null}
import { readFile, writeFile } from "node:fs/promises";
import { XMLParser } from "fast-xml-parser";

const API = "https://rest.newlead.ai/v1/properties";
const HEADERS = {
  Authorization: `Bearer ${process.env.NEWLEAD_API_KEY}`,
  "Content-Type": "application/json",
};
// Your CRM's names for the features we know.
const FEATURES = { terraza: "terrace", ascensor: "lift", garaje: "parking", piscina: "pool" };
const sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
const list = (value) => (value === undefined ? [] : [].concat(value));

// <properties><property><ref>SH-0042</ref><type>flat</type>…</property></properties>
function toProperty(item) {
  return {
    type: item.type,
    listings: [
      {
        operation: item.operation === "rent" ? "rent" : "sale",
        price: Number(item.price),
        available: item.status === "available",
      },
    ],
    address: {
      street: item.street ?? null,
      street_number: item.number ? String(item.number) : null,
      postal_code: item.zip ? String(item.zip).padStart(5, "0") : null,
      city: item.city ?? null,
      visibility: "street",
    },
    bedrooms: item.bedrooms ? Number(item.bedrooms) : null,
    bathrooms: item.bathrooms ? Number(item.bathrooms) : null,
    built_m2: item.size ? Number(item.size) : null,
    description: item.description ?? null,
    features: [...new Set(list(item.features?.feature).map((name) => FEATURES[name]).filter(Boolean))],
    images: list(item.photos?.photo).map((url) => ({ url })),
  };
}

// 429: wait as the API says. 5xx: wait and send it again; PUT and DELETE can be repeated.
async function send(method, reference, body) {
  for (let attempt = 1; attempt <= 5; attempt++) {
    const res = await fetch(`${API}/${encodeURIComponent(reference)}`, {
      method,
      headers: HEADERS,
      body: body === undefined ? undefined : JSON.stringify(body),
    });
    if (res.status !== 429 && res.status < 500) return res;
    await sleep(Number(res.headers.get("Retry-After") ?? attempt) * 1000);
  }
  throw new Error(`${method} ${reference} kept failing`);
}

const xml = await readFile("feed.xml", "utf8");
const feed = list(new XMLParser().parse(xml).properties?.property);
const references = feed.map((item) => String(item.ref));
const uploaded = JSON.parse(await readFile("uploaded.json", "utf8").catch(() => "[]"));

for (const item of feed) {
  const res = await send("PUT", String(item.ref), toProperty(item));
  const body = await res.json();
  if (!res.ok) {
    console.error(item.ref, body.error.code, body.error.param, body.error.message);
    continue;
  }
  for (const warning of body.warnings) console.warn(item.ref, warning.param, warning.message);
}

const failedDeletes = [];
for (const reference of uploaded.filter((ref) => !references.includes(ref))) {
  const res = await send("DELETE", reference);
  if (!res.ok && res.status !== 404) {
    console.error(reference, res.status);
    failedDeletes.push(reference);
  }
}

// Every reference in the feed, also the ones that failed: a failed PUT must not delete it next time.
// Plus the ones whose DELETE failed, so the next run tries to delete them again.
await writeFile("uploaded.json", JSON.stringify([...references, ...failedDeletes]));
```

The API has no way to list the properties you sent that are not available, so your CRM must remember which references it sent, as the script does, to know what to delete.

Run it as often as your feed changes. Each API key can make 120 requests per minute, as described in [Rate limits](https://docs.newlead.ai/rate-limits.md): with a large feed the script hits `429` and waits.


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.