-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathsimplyrets-example.php
More file actions
37 lines (30 loc) · 924 Bytes
/
simplyrets-example.php
File metadata and controls
37 lines (30 loc) · 924 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<?php
/** Set up `curl` to make authenticated API requests */
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => "https://api.simplyrets.com/properties",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => "GET",
CURLOPT_HTTPHEADER =>
array(
"Authorization: Basic '" . base64_encode('simplyrets:simplyrets') . "'",
),
));
/**
* 1. Execute the request
* 2. Check for errors
* 3. Close the connection
*/
$response = curl_exec($curl);
$err = curl_error($curl);
curl_close($curl);
if ($err) {
echo "cURL Error #:" . $err;
}
/** Decode JSON response - this is a list of listings */
$json_response = json_decode($response);
/** Print address and list price of the first listing */
echo "<h2>" . $json_response[0]->address->full . "</h2>";
echo "<p>List price: " . $json_response[0]->listPrice . "</p>";
?>