Skip to content

Commit fb32aa2

Browse files
committed
Initial push to GitHub
0 parents  commit fb32aa2

16 files changed

+2140
-0
lines changed

LICENSE

+674
Large diffs are not rendered by default.

README.md

+123
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
flexmls API - version 2
2+
=====================
3+
A PHP wrapper for the flexmls REST API. This version has enough differences from version 1 that upgrading will
4+
require changes to existing code.
5+
6+
7+
Documentation
8+
-------------
9+
For full information on the API, see http://www.flexmls.com/developers
10+
11+
12+
Usage Examples
13+
------------------------
14+
// include the flexmlsAPI core which autoloads other classes as necessary
15+
require_once("lib/Core.php");
16+
17+
// connect using flexmls API authentication
18+
$api = new flexmlsAPI_APIAuth("api_key_goes_here", "api_secret_goes_here");
19+
20+
// identify your application (optional)
21+
$api->SetApplicationName("MyPHPApplication/1.0");
22+
23+
// authenticate
24+
$result = $api->Authenticate();
25+
if ($result === false) {
26+
echo "API Error Code: {$api->last_error_code}<br>\n";
27+
echo "API Error Message: {$api->last_error_mess}<br>\n";
28+
exit;
29+
}
30+
31+
// get your listings
32+
$result = $api->GetMyListings();
33+
34+
// see the included examples.php for more complete usage
35+
36+
37+
Error Codes
38+
---------------------
39+
<table>
40+
<thead>
41+
<tr>
42+
<th>HTTP Code</th>
43+
<th>flexmls API Error Code</th>
44+
<th>Automatic Retry</th>
45+
<th>Description</th>
46+
</tr>
47+
</thead>
48+
<tbody>
49+
<tr>
50+
<td><tt>401</tt></td>
51+
<td><tt>1000</tt></td>
52+
<td><tt>Yes</tt></td>
53+
<td>Invalid API Key and/or Request signed improperly</td>
54+
</tr>
55+
<tr>
56+
<td><tt>401</tt></td>
57+
<td><tt>1010</tt></td>
58+
<td><tt>No</tt></td>
59+
<td>API key is disabled</td>
60+
</tr>
61+
<tr>
62+
<td><tt>403</tt></td>
63+
<td><tt>1015</tt></td>
64+
<td><tt>No</tt></td>
65+
<td><tt>ApiUser</tt> must be supplied, or the provided key does not have access to the supplied user</td>
66+
</tr>
67+
<tr>
68+
<td><tt>401</tt></td>
69+
<td><tt>1020</tt></td>
70+
<td><tt>Yes</tt></td>
71+
<td>Session token has expired</td>
72+
</tr>
73+
<tr>
74+
<td><tt>403</tt></td>
75+
<td><tt>1030</tt></td>
76+
<td><tt>No</tt></td>
77+
<td>SSL required for this type of request</td>
78+
</tr>
79+
<tr>
80+
<td><tt>400</tt></td>
81+
<td><tt>1035</tt></td>
82+
<td><tt>No</tt></td>
83+
<td>POST data not supplied as valid JSON. Issued if the <tt>Content-Type</tt> header is not <tt>application/json/</tt> and/or if the POST data is not in valid JSON format.</td>
84+
</tr>
85+
<tr>
86+
<td><tt>400</tt></td>
87+
<td><tt>1040</tt></td>
88+
<td><tt>No</tt></td>
89+
<td>The <tt>_filter</tt> syntax was invalid or a specified field to search on does not exist</td>
90+
</tr>
91+
<tr>
92+
<td><tt>400</tt></td>
93+
<td><tt>1050</tt></td>
94+
<td><tt>No</tt></td>
95+
<td>(message varies) A required parameter was not provided</td>
96+
</tr>
97+
<tr>
98+
<td><tt>400</tt></td>
99+
<td><tt>1053</tt></td>
100+
<td><tt>No</tt></td>
101+
<td>(message varies) A parameter was provided but does not adhere to constraints</td>
102+
</tr>
103+
<tr>
104+
<td><tt>409</tt></td>
105+
<td><tt>1055</tt></td>
106+
<td><tt>No</tt></td>
107+
<td>(message varies)Issued when a write is requested that will conflict with existing data. For example, adding a new contact with an e-mail that already exists.</td>
108+
</tr>
109+
<tr>
110+
<td><tt>403</tt></td>
111+
<td><tt>1500</tt></td>
112+
<td><tt>No</tt></td>
113+
<td>The resource is not available at the current API key's service level. For example, this error applies if a user attempts to access the IDX Links API via a free API key. </td>
114+
</tr>
115+
<tr>
116+
<td><tt>503</tt></td>
117+
<td><tt>1550</tt></td>
118+
<td><tt>No</tt></td>
119+
<td>Over rate limit</td>
120+
</tbody>
121+
</table>
122+
123+

examples.php

+215
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
<?php
2+
3+
// include the flexmlsAPI core which autoloads other classes as necessary
4+
require_once("lib/Core.php");
5+
6+
7+
/*
8+
* authenticate with the API
9+
* Changed in version 2.0
10+
*
11+
* The newest version of the PHP API client (version 2.0) allows you to select which authentication method
12+
* you'd like to use against the API. Version 1.0 was limited to the flexmls API authentication method and is
13+
* now done using:
14+
*
15+
* $api = new flexmlsAPI_APIAuth("api_key_goes_here", "api_secret_goes_here");
16+
*
17+
* With version 2.0, you can now authenticate using OAuth2 support. For more details on OAuth2 with the flexmls API,
18+
* see https://www.flexmls.com/developers/api/api-services/authentication/
19+
*
20+
* $api = new flexmlsAPI_OAuth($client_id, $client_secret, $application_uri);
21+
*
22+
* To issue a Grant request with the "code" value provided by the API:
23+
*
24+
* $result = $api->Grant($code_value);
25+
*
26+
* A successful response will populate 2 new variables:
27+
*
28+
* $api->oauth_access_token
29+
* $api->oauth_refresh_token
30+
*
31+
* These values can be saved and re-used in future requests using:
32+
*
33+
* $api->SetAccessToken($previous_access_token);
34+
* $api->SetRefreshToken($previous_refresh_token);
35+
*
36+
* Also, for convenience, if the access token has expired and the refresh token is used to automatically have a new access
37+
* token generated, a hook is available to notify you of the new tokens:
38+
*
39+
* $api->SetNewAccessCallback('new_token_given');
40+
*
41+
* which executes a function called "new_token_given" with 2 arguments:
42+
*
43+
* * the type of grant which resulted in new tokens. "authorization_code" or "refresh_token"
44+
* * the values (in array format). "access_token", "refresh_token" and "expires_in" are the 3 array keys
45+
*
46+
*/
47+
48+
$api = new flexmlsAPI_APIAuth("api_key_goes_here", "api_secret_goes_here");
49+
50+
// identify your application (optional)
51+
$api->SetApplicationName("PHP-API-Code-Examples/1.0");
52+
53+
// enable developer mode. this points you to a sandbox for development use
54+
$api->SetDeveloperMode(true);
55+
56+
57+
/*
58+
* enable built-in caching system
59+
* New in version 2.0
60+
*
61+
* The newest version of the PHP API client (version 2.0) contains a system for enabling a
62+
* built-in cache. The following options currently exist:
63+
*
64+
* * Memcache (Uses http://pecl.php.net/package/memcache)
65+
* * Memcached (Uses http://pecl.php.net/package/memcached)
66+
* * WordPress (for use within plugins or themes)
67+
* * MySQLi for storing the cache in a MySQL database
68+
*
69+
* To enable a particular caching system, you must create an instance of the desired object and pass it to
70+
* the API core.
71+
*
72+
*
73+
* To enable Memcache or Memcached cache support, the host and port (both optional) can be given:
74+
*
75+
* $api->SetCache( new flexmlsAPI_MemcacheCache() ); // defaults to localhost and port 11211
76+
* or:
77+
* $api->SetCache( new flexmlsAPI_MemcachedCache('remotehost', 12345) ); // overrides both defaults
78+
*
79+
* depending on the Memcached-compliant driver you choose.
80+
*
81+
*
82+
* To enable WordPress caching, no arguments are required: this method uses the set_transient() and get_transient()
83+
* functions created by WordPress which can be extended by other WP plugins for additional (or modified) functionality.
84+
*
85+
* $api->SetCache( new flexmlsAPI_WordPressCache() );
86+
*
87+
*
88+
* To enable database caching via the MySQLi extension, you can either pass connection details to the class:
89+
*
90+
* $api->SetCache( new flexmlsAPI_MySQLiCache($hostname, $database, $username, $password, $table_name));
91+
*
92+
* or you can re-use an existing MySQLi connection by passing the object:
93+
*
94+
* $api->SetCache( new flexmlsAPI_MySQLiCache($my_mysqli_object) );
95+
*
96+
* By default, a $table_name of "api_cache" is assumed if none is given. The structure for that table is:
97+
*
98+
* CREATE TABLE api_cache (
99+
* cache_key VARCHAR(125),
100+
* cache_value TEXT,
101+
* expiration INT(10),
102+
* PRIMARY KEY(cache_key)
103+
* )
104+
*
105+
*/
106+
107+
108+
// authenticate
109+
$result = $api->Authenticate();
110+
if ($result === false) {
111+
echo "API Error Code: {$api->last_error_code}<br>\n";
112+
echo "API Error Message: {$api->last_error_mess}<br>\n";
113+
exit;
114+
}
115+
116+
/*
117+
* request some basic account and system information
118+
*/
119+
$result = $api->GetSystemInfo();
120+
// https://www.flexmls.com/developers/api/api-services/system-info/
121+
print_r($result);
122+
123+
$result = $api->GetPropertyTypes();
124+
// https://www.flexmls.com/developers/api/api-services/property-types/
125+
print_r($result);
126+
127+
$result = $api->GetStandardFields();
128+
// https://www.flexmls.com/developers/api/api-services/standard-fields/
129+
print_r($result);
130+
131+
$result = $api->GetMyAccount();
132+
// https://www.flexmls.com/developers/api/api-services/my-account/
133+
print_r($result);
134+
135+
136+
/*
137+
* different requests for listings based on context
138+
*/
139+
140+
$result = $api->GetMyListings();
141+
// https://www.flexmls.com/developers/api/api-services/listings/
142+
print_r($result);
143+
144+
$result = $api->GetOfficeListings();
145+
// https://www.flexmls.com/developers/api/api-services/listings/
146+
print_r($result);
147+
148+
$result = $api->GetCompanyListings();
149+
// https://www.flexmls.com/developers/api/api-services/listings/
150+
print_r($result);
151+
152+
/*
153+
* request for listings with some parameters. the above listing requests this argument and most of the options within
154+
*/
155+
$result = $api->GetListings(
156+
array(
157+
'_pagination' => 1,
158+
'_limit' => 3,
159+
'_page' => 2,
160+
'_filter' => "PropertyType Eq 'A'",
161+
'_expand' => 'PrimaryPhoto'
162+
)
163+
);
164+
// https://www.flexmls.com/developers/api/api-services/listings/
165+
print_r($result);
166+
167+
/*
168+
* with a particular listing Id known, several additional API calls are available
169+
*/
170+
171+
$id = "20100912153422758914000000"; // this comes from the Id value in a listing response
172+
173+
$result = $api->GetListingPhotos($id);
174+
// https://www.flexmls.com/developers/api/api-services/listing-photos/
175+
$result = $api->GetListingDocuments($id);
176+
// https://www.flexmls.com/developers/api/api-services/listing-documents/
177+
$result = $api->GetListingOpenHouses($id);
178+
// https://www.flexmls.com/developers/api/api-services/open-houses/
179+
$result = $api->GetListingVideos($id);
180+
// https://www.flexmls.com/developers/api/api-services/listing-videos/
181+
$result = $api->GetListingVirtualTours($id);
182+
// https://www.flexmls.com/developers/api/api-services/virtual-tours/
183+
184+
185+
/*
186+
* with a particular object Id known, you can request additional information about that one item
187+
*/
188+
189+
$photo_id = "20080917142739989238000000";
190+
191+
$result = $api->GetListingPhoto($id, $photo_id);
192+
// https://www.flexmls.com/developers/api/api-services/listing-photos/
193+
194+
195+
/*
196+
* contact management
197+
* https://www.flexmls.com/developers/api/api-services/contacts/
198+
*/
199+
200+
$result = $api->GetContacts();
201+
202+
$new_contact = array(
203+
"DisplayName" => "Example Contact",
204+
"PrimaryEmail" => "[email protected]",
205+
"PrimaryPhoneNumber" => "888-123-4567",
206+
"HomeStreetAddress" => "123 S. Main St",
207+
"HomeLocality" => "Fargo",
208+
"HomeRegion" => "ND",
209+
"HomePostalCode" => "58104",
210+
"Tag" => "Example Group"
211+
);
212+
213+
// $result = $api->AddContact($new_contact); // creates a new contact
214+
215+
$result = $api->GetContact("20090816141725963238000000"); // get a contact by their Id

0 commit comments

Comments
 (0)