...
Create the array of data to send to the API:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme | Eclipse |
---|
linenumbers | true |
---|
|
$data = array(
"apikey" => "987zyx", // Use your API key here
"objectType" => "animals",
"objectAction" => "define",
); |
Encode the array into a JSON string:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme | Eclipse |
---|
linenumbers | true |
---|
|
$jsonData = json_encode($data) |
Post the JSON data to the RescueGroups.org API:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme |
---|
Eclipse | linenumbers | true |
---|
|
// create a new cURL resource
$ch = curl_init();
// set options, url, etc.
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_URL, "https://api.rescuegroups.org/http/v2.json");
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if (curl_errno($ch)) {
$results = curl_error($ch)
} else {
// close cURL resource, and free up system resources
curl_close($ch);
$results = $result;
}
|
Decode the JSON results back into a PHP array:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme | Eclipse |
---|
linenumbers | true |
---|
|
$resultsArray = json_decode($results); |
...
Print out the array so we can see the actual definition:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme |
---|
Eclipse | linenumbers | true |
---|
|
print_r($resultsArray); |
...
Code Block |
---|
language | php |
---|
linenumbers | true |
---|
|
Array
(
[status] => ok
[messages] => Array
(
[generalMessages] => Array
(
)
[recordMessages] => Array
(
)
)
[foundRows] => 3
[data] => Array
(
[define] => Array
(
[modules] => Public
[permissions] => Public
)
[publicView] => Array
(
[modules] => Public
[permissions] => Public
[fields] => Array
(
[animalID] => Array
(
[name] => animalID
[friendlyname] => ID
[type] => key
[lengthMax] =>
[lengthMin] =>
[default] =>
[properties] => Array
(
[0] => required
)
[modules] => Public
)
)
)
[publicSearch] => Array
(
[modules] => Public
[permissions] => Public
[fields] => Array
(
[animalID] => Array
(
[name] => animalID
[friendlyname] => ID
[type] => key
[lengthMax] =>
[lengthMin] =>
[default] =>
[properties] => Array
(
)
[modules] => Public
)
[animalOrgID] => Array
(
[name] => animalOrgID
[friendlyname] => Org ID
[type] => key
[lengthMax] =>
[lengthMin] =>
[default] =>
[properties] => Array
(
)
[modules] => Public
)
[animalActivityLevel] => Array
(
[name] => animalActivityLevel
[friendlyname] => Activity level
[type] => string
[lengthMax] =>
[lengthMin] =>
[default] =>
[values] => Array
(
[0] =>
[1] => Highly Active
[2] => Moderately Active
[3] => Not Active
[4] => Slightly Active
)
[properties] => Array
(
)
[modules] => Public
)
More fields will follow here...
)
)
)
)
|
Info |
---|
See the Actions page for additional information on the results of the define API call. |
...
Create the array of data to send to the API:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme | Eclipse |
---|
linenumbers | true |
---|
|
$data = array(
"apikey" => "987zyx",
"objectType" => "animals",
"objectAction" => "publicSearch",
"search" => array (
"resultStart" => 0,
"resultLimit" => 20,
"resultSort" => "animalID",
"resultOrder" => "asc",
"calcFoundRows" => "Yes", "filters" => array(
array(
"fieldName" => "animalSpecies",
"operation" => "equals",
"criteria" => "dog",
),
array(
"fieldName" => "animalGeneralSizePotential",
"operation" => "equals",
"criteria" => "small",
),
),
"fields" => array("animalID","animalOrgID","animalName","animalBreed")
),
); |
Encode the array into a JSON string:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme | Eclipse |
---|
linenumbers | true |
---|
|
$jsonData = json_encode($data); |
Post the JSON data to the RescueGroups.org API:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme | Eclipse |
---|
linenumbers | true |
---|
|
// create a new cURL resource
$ch = curl_init();
// set options, url, etc.
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-Type: application/json"));
curl_setopt($ch, CURLOPT_URL, "https://api.rescuegroups.org/http/v2.json");
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonData);
curl_setopt($ch, CURLOPT_POST, 1);
//curl_setopt($ch, CURLOPT_VERBOSE, true);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$result = curl_exec($ch);
if (curl_errno($ch)) {
$results = curl_error($ch);
} else {
// close cURL resource, and free up system resources
curl_close($ch);
$results = $result;
}
|
Decode the JSON results back into a PHP array:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme | Eclipse |
---|
linenumbers | true |
---|
|
$resultsArray = json_decode($results); |
...
Print out the array so we can see the actual definition:
Code Block |
---|
theme | Eclipse |
---|
language | php |
---|
theme | Eclipse |
---|
linenumbers | true |
---|
|
print_r($resultsArray); |
The resulting PHP array will look something like:
Code Block |
---|
theme | Eclipse |
---|
language | php | theme | Eclipse |
---|
linenumbers | true |
---|
|
Array
(
[status] => ok
[messages] => Array
(
[generalMessages] => Array
(
)
[recordMessages] => Array
(
)
)
[foundRows] => 101
[data] => Array
(
[2685836] => Array
(
[animalID] => 2685836
[animalOrgID] => 1
[animalName] => Al
)
[2685840] => Array
(
[animalID] => 2685840
[animalOrgID] => 1
[animalName] => Alfonso
)
More records would follow here...
)
)
|