Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Migrated to Confluence 5.3

...

Create the array of data to send to the API:

Code Block
themeEclipse
languagephp
themeEclipse
linenumberstrue
$data = array(
  "apikey" => "987zyx", // Use your API key here
  "objectType" => "animals",
  "objectAction" => "define",
);

Encode the array into a JSON string:

Code Block
themeEclipse
languagephpthemeEclipse
linenumberstrue
$jsonData = json_encode($data)

Post the JSON data to the RescueGroups.org API:

Code Block
themeEclipse
languagephpthemeEclipse
linenumberstrue
// 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/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
themeEclipse
languagephp
themeEclipse
linenumberstrue
$resultsArray = json_decode($results);

...

Print out the array so we can see the actual definition:

Code Block
theme
themeEclipse
languagephp
Eclipselinenumberstrue
print_r($resultsArray);

...

Create the array of data to send to the API:

Code Block
themeEclipse
languagephpthemeEclipse
linenumberstrue
$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
themeEclipse
languagephpthemeEclipse
linenumberstrue
$jsonData = json_encode($data);

Post the JSON data to the RescueGroups.org API:

Code Block
themeEclipse
languagephp
themeEclipse
linenumberstrue
// 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/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
themeEclipse
languagephp
Eclipselinenumberstrue
$resultsArray = json_decode($results);

...

Print out the array so we can see the actual definition:

Code Block
themeEclipse
languagephpthemeEclipse
linenumberstrue
print_r($resultsArray);

The resulting PHP array will look something like:

Code Block
themeEclipse
languagephpthemeEclipse
linenumberstrue
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...

        )

)