Docs menu

    Docs / Guides

    Code Examples: curl, JavaScript, Python and PHP

    Ready-to-adapt server code that asks for listings and returns clean JSON.

    Each example asks for active listings with filters, sends the key from a secret, checks the status, and returns the listings as clean JSON for your page. They run in server code: a Node server, a Lovable or Supabase function, a Python service, or WordPress PHP. Change the filter and fields to fit your page.

    curl

    Good for a first test from a terminal on your own machine.

    curl
    curl -G "$SAIGE_MLS_API_URL/Property" \
      -H "Authorization: Bearer $SAIGE_MLS_API_KEY" \
      -H "Accept: application/json" \
      --data-urlencode "\$filter=StandardStatus eq 'Active' and City eq 'Burnaby'" \
      --data-urlencode "\$select=ListingKey,ListPrice,BedroomsTotal,UnparsedAddress" \
      --data-urlencode "\$top=24"

    JavaScript (Node, Lovable, Supabase and other server functions)

    Uses fetch and URLSearchParams, available in Node 18 and newer and in Deno-based functions.

    JavaScript
    export async function getListings({ city, minPrice, maxPrice, beds }) {
      const filters = ["StandardStatus eq 'Active'"];
      if (city) filters.push(`City eq '${city.replace(/'/g, "''")}'`);
      if (minPrice) filters.push(`ListPrice ge ${Number(minPrice)}`);
      if (maxPrice) filters.push(`ListPrice le ${Number(maxPrice)}`);
      if (beds) filters.push(`BedroomsTotal ge ${Number(beds)}`);
    
      const params = new URLSearchParams({
        $filter: filters.join(" and "),
        $select: "ListingKey,ListPrice,BedroomsTotal,BathroomsTotalInteger,LivingArea,UnparsedAddress,City,ListOfficeName",
        $orderby: "OnMarketDate desc,ListingKey desc",
        $top: "24",
      });
    
      const res = await fetch(`${process.env.SAIGE_MLS_API_URL}/Property?${params}`, {
        headers: {
          Authorization: `Bearer ${process.env.SAIGE_MLS_API_KEY}`,
          Accept: "application/json",
        },
      });
      if (!res.ok) throw new Error(`MLS API error ${res.status}`);
      const data = await res.json();
      return { listings: data.value, next: data["@odata.nextLink"] ?? null };
    }

    Python

    Uses the requests library, which encodes the parameters.

    Python
    import os
    import requests
    
    def get_listings(city):
        url = f"{os.environ['SAIGE_MLS_API_URL']}/Property"
        safe_city = city.replace("'", "''")
        params = {
            "$filter": f"StandardStatus eq 'Active' and City eq '{safe_city}'",
            "$select": "ListingKey,ListPrice,BedroomsTotal,UnparsedAddress",
            "$top": "24",
        }
        headers = {
            "Authorization": f"Bearer {os.environ['SAIGE_MLS_API_KEY']}",
            "Accept": "application/json",
        }
        res = requests.get(url, params=params, headers=headers, timeout=20)
        res.raise_for_status()
        data = res.json()
        return data["value"], data.get("@odata.nextLink")

    PHP (WordPress)

    Uses the WordPress HTTP API and caches the answer in a transient, so each page view does not call the API. Store the secrets in wp-config.php, outside the database.

    PHP
    function saige_get_listings( $city ) {
      $cache_key = 'saige_listings_' . md5( $city );
      $cached = get_transient( $cache_key );
      if ( false !== $cached ) {
        return $cached;
      }
      $filter = sprintf( "StandardStatus eq 'Active' and City eq '%s'", str_replace( "'", "''", $city ) );
      $url = add_query_arg(
        array(
          '$filter' => rawurlencode( $filter ),
          '$select' => 'ListingKey,ListPrice,BedroomsTotal,UnparsedAddress',
          '$top'    => 24,
        ),
        SAIGE_MLS_API_URL . '/Property'
      );
      $res = wp_remote_get( $url, array(
        'headers' => array(
          'Authorization' => 'Bearer ' . SAIGE_MLS_API_KEY,
          'Accept'        => 'application/json',
        ),
        'timeout' => 20,
      ) );
      if ( is_wp_error( $res ) || 200 !== wp_remote_retrieve_response_code( $res ) ) {
        return array();
      }
      $data = json_decode( wp_remote_retrieve_body( $res ), true );
      set_transient( $cache_key, $data['value'], 15 * MINUTE_IN_SECONDS );
      return $data['value'];
    }

    Escaping values in filters

    A value that came from a visitor goes inside single quotes, with every apostrophe doubled, as OData requires. Numbers are converted to numbers before they go into the filter. Each example above does both, so a visitor cannot change the filter.

    Common questions

    Which language should I use?

    The one your builder runs on the server: JavaScript for Lovable, Bolt, v0 and Supabase, PHP for WordPress, any of them on your own server.

    Can I paste these into Lovable?

    Yes, or paste the build prompt from the Lovable guide and let Lovable write the function.

    Why cache the answer?

    Pages load faster and you stay inside your request limits.

    How do I add paging?

    Return the @odata.nextLink with the listings, and request it when the visitor wants more.

    Where do the secrets go in WordPress?

    Define SAIGE_MLS_API_URL and SAIGE_MLS_API_KEY in wp-config.php. The WordPress guide shows the steps.

    How do I stop a visitor from changing the filter?

    Double each apostrophe in text values and convert numbers with Number or int, as the examples do.

    Can I run the curl example from a browser?

    No. It needs your key, so run it only on your own machine or server.

    Is there an SDK?

    The API is standard OData over HTTPS, so any HTTP library works. These examples are the whole client.

    Specifications

    Last reviewed 2026-11-20

    MLS API for BC

    Put live MLS listings on the site you are building

    Saige is an approved MLS data vendor for Greater Vancouver REALTORS, Fraser Valley Real Estate Board, Chilliwack and District Real Estate Board and BC Northern Real Estate Board. Send a request and our team will contact you to check what your board allows and how to connect your builder.

    Call 604.401.4849