We have updated our API Terms of Service. Please review the entire terms before continuing to use the API. Your use of the API means you accept and agree to the updated API Terms of Service found here: https://rescuegroups.org/api-terms-of-service/

Making a request for public information

Before performing a query against the API, you should use the define action to enumerate the available actions and fields associated with the object.  For example, if you would like to search the available adoptable pets, you should take a look at the definition of the animals object before building your query for available animals.

Retrieving the definition for the Animals object (using an API key)

To perform a request for the definition of an object, do the following:

  1. Combine the following into an array:
    1. apikey - your assigned RescueGroups.org API key
    2. objectType - the object you are searching (e.g., animals, events)
    3. objectAction - the method you'd like to call (e.g., define)
  2. Encode the array into JSON (with PHP, use the json_encode() function)
  3. POST the JSON to the API (with PHP, use curl)
  4. Decode the results from JSON into an array (with PHP, use the json_decode() function)
  5. Handle the results -- in this case we want to just print out the results for review

Example of a define (using an API key)

Here is an example (in PHP) of the above steps to retrieve the definition for the Animals object:

Create the array of data to send to the API:

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

Encode the array into a JSON string:

$jsonData = json_encode($data)

Post the JSON data to the RescueGroups.org API:

// 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:

$resultsArray = json_decode($results);

You may decide to put the encoding/decoding of the JSON along with the curl post to the API into a function that you can pass an array and receive the results in an array.

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

print_r($resultsArray);

The resulting PHP array will look something like:

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...

                        )

                )

        )

)

See the Actions page for additional information on the results of the define API call.

The following are the steps required to request public information from the RescueGroups.org API, using your assigned API key:

  1. Combine the following into an array:
    1. apikey - your assigned RescueGroups.org API key
    2. objectType - the object you are searching (e.g., animals, events)
    3. objectAction - the method you'd like to call (e.g., publicSearch)
    4. filters - any search criteria you'd like to use (e.g., animalSpecies = dog)
    5. fields - the information you would like returned from the search (e.g., animalName, animalBreed)

Example of a search (using an API key)

Here is an example (in PHP) of the above steps to search for the Animals:

Create the array of data to send to the API:

$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:

$jsonData = json_encode($data);

Post the JSON data to the RescueGroups.org API:

// 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:

$resultsArray = json_decode($results);

You may decide to put the encoding/decoding of the JSON along with the curl post to the API into a function that you can pass an array and receive the results in an array.

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

print_r($resultsArray);

The resulting PHP array will look something like:

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...

        )

)
  • No labels