API Sample Code

We have provided the following code samples to assist you with developing your application to add & remove listings.

Adding Listings

This request demonstrates all of our available data elements for adding a listing. For further information, review our documentation.

Request

<xml>
  <vendor>Your vendor key</vendor>
  <properties>
    <property>
      <action>List</action>
      <id>1000</id>
      <updated>2016-12-06 15:07:20</updated>
      <expire>2017-03-06</expire>
      <type>House</type>
      <street>123 Birch Lane</street>
      <city>Raleigh</city>
      <state>NC</state>
      <zip>27615</zip>
      <latitude>35.875897</latitude>
      <longitude>-78.725046</longitude>
      <contact_name>Your Name</contact_name>
      <contact_email>your.name@company.com</contact_email>
      <contact_phone>(919) 555-1212</contact_phone>
      <contact_phone_alt>(919) 555-1212</contact_phone_alt>
      <contact_fax>(919) 555-1212</contact_fax>
      <floorplans>
        <floorplan>
          <name>4 Bedroom</name>
          <beds>4</beds>
          <baths>2.5</baths>
          <sqft>2250</sqft>
          <rent_min>1250</rent_min>
          <rent_max>1500</rent_max>
          <term>Month</term>
        </floorplan>
      </floorplans>
      <amenities>
        <amenity>ac</amenity>
        <amenity>bl</amenity>
        <amenity>cb</amenity>
        <amenity>cf</amenity>
      </amenities>
      <features>
        <feature>bp</feature>
        <feature>bo</feature>
        <feature>ch</feature>
        <feature>ca</feature>
      </features>
      <pictures>
        <picture>
          <description>Front of home</description>
          <url>http://www.rentalsource.com/images/listings/1000-1.jpg</url>
        </picture>
        <picture>
          <description>Kitchen</description>
          <url>http://www.rentalsource.com/images/listings/1000-2.jpg</url>
        </picture>
        <picture>
          <description>Living Room</description>
          <url>http://www.rentalsource.com/images/listings/1000-3.jpg</url>
        </picture>
      </pictures>
      <description>Insert description of rental property</description>
      <terms>Insert rental property lease terms</terms>
      <website>http://www.rentalsource.com/1000</website>
    </property>
  </properties>
</xml>

Response - Success

<xml>
  <response>
    <properties>
      <property>
        <id>1000</id>
        <action>List</action>
        <result>Success</result>
        <listing>http://www.rentalsource.com/xxxxxx</listing>
      </property>
    </properties>
  </response>
</xml>

Response - Success (with warnings)

<xml>
  <response>
    <properties>
      <property>
        <id>1000</id>
        <action>List</action>
        <warnings>
          <warning>sqft value wasn't specified - we have defaulted to n/a</warning>
          <warning>rent_term doesn't reference a valid duration - we have defaulted to a monthly rental term</warning>
          <warning>picture #1 url doesn't reference a valid picture</warning>
        </warnings>
        <result>Success</result>
        <listing>http://www.rentalsource.com/xxxxxx</listing>
      </property>
    </properties>
  </response>
</xml>

Response - Failed

<xml>
  <response>
    <properties>
      <property>
        <id>1000</id>
        <action>List</action>
        <errors>
          <error>type specified must be a valid category</error>
          <error>valid zip must be specified for each property listing</error>
        </errors>
        <result>Failed</result>
      </property>
    </properties>
  </response>
</xml>

Removing Listings

This request demonstrates how to remove listings.

Request

<xml>
  <vendor></vendor>
  <properties>
    <property>
      <action>Remove</action>
      <id>1000</id>
    </property>
  </properties>
</xml>

Response - Success

<xml>
  <response>
    <properties>
      <property>
        <id>1000</id>
        <action>Remove</action>
        <result>Success</result>
      </property>
    </properties>
  </response>
</xml>

Response - Failed

<xml>
  <response>
    <properties>
      <property>
        <id>1000</id>
        <action>Remove</action>
        <errors>
          <error>id specified doesn't reference a valid property listing</error>
        </errors>
        <result>Failed</result>
      </property>
    </properties>
  </response>
</xml>

PHP Connection Code

This simulates the adding of a listing using PHP cURL and printing the response.

<?php

$feed = "<xml>
  <vendor>Your vendor key</vendor>
  <properties>
    <property>
      <action>List</action>
      <id>1000</id>
      <type>House</type>
      <street>123 Birch Lane</street>
      <zip>27615</zip>
      <contact_name>Your Name</contact_name>
      <contact_email>your.name@company.com</contact_email>
      <pictures>
        <picture>
          <url>http://www.company.com/images/listings/1000-1.jpg</url>
        </picture>
      </pictures>
      <description>Insert description of rental property</description>
    </property>
  </properties>
</xml>";

$session = curl_init();

curl_setopt($session, CURLOPT_URL, "http://www.rentalsource.com/sign-up/to/receive/api/url/");
curl_setopt($session, CURLOPT_POST, 1);
curl_setopt($session, CURLOPT_POSTFIELDS, $feed);
curl_setopt($session, CURLOPT_HEADER, true);
curl_setopt($session, CURLOPT_HTTPHEADER, array("Accept: text/xml", "Content-Type: text/xml"));
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);

$response = curl_exec($session);
curl_close($session);

echo $response;

?>