We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 36786 ☆ A M B ☆
    • 209 Posts
    I would like to use the PetFinder API and PHP library to call and list all pets from a specific shelter in a Modx snippet with chunk formatted output. I think I figured out how to enter in the credentials, but telling it what shelter to draw from and how to place that into an array and output properly via chunk formatting is beyond me.

    PHP Library: https://github.com/brianhaveri/Petfinder/blob/master/Petfinder.php

    According to the PHP library, this is what I am given as an example, but I really don't know how to implement this. Could someone please walk me through it? This is a pro bono job for a local shelter that does great work so I want to help.

    	public function shelter_get($data) {
    		if(! is_array($data)) {
    			$data = array('id'=>(string) $data);
    		}
    		return $this->_callMethod(__FUNCTION__, $data);
    	}


    If this is really too big of a thing to ask for on the forums, I could buy someone a few beers via paypal for the help.

    This question has been answered by BobRay. See the first response.

      Ben Morrison
      Hacking templates to pieces since 2003
    • discuss.answer
      • 3749
      • 24,544 Posts
      There's more information here: http://www.petfinder.com/developers/api-docs.

      It looks like the process would go something like this:

      include 'path/to/petfinder.php';
      
      $pf = new Petfinder($apiKey, $apiSecret);
      
      $shelterId = 'NJ94';
      $developerKey = 'your developer key here';
      
      $data = array(
          'key' => $developerKey,
          'token' => $pf->getToken(),
          'id' => $shelterId,
          'format' => 'json',  /* could also be 'xml' */
      
      );
      
      $shelterInfo = $pf->shelter_get($data);
      $fields = $modx->fromJSON($shelterInfo);
      echo "<pre>" . print_r($fields, true);


      [ed. note: BobRay last edited this post 12 years, 7 months ago.]
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 36786 ☆ A M B ☆
        • 209 Posts
        Thanks, I will try that in an hour when I get home. How would I output that array as you usually would in a snippet, using a chunk for formatting?
          Ben Morrison
          Hacking templates to pieces since 2003
          • 3749
          • 24,544 Posts
          Run it as written (I just made a change) to see what the fields are and name the placeholders in your Tpl chunk with the field names. Then do this:


          return $modx->getChunk('ShelterInfo', $fields);
            Did I help you? Buy me a beer
            Get my Book: MODX:The Official Guide
            MODX info for everyone: http://bobsguides.com/modx.html
            My MODX Extras
            Bob's Guides is now hosted at A2 MODX Hosting
            • 36786 ☆ A M B ☆
            • 209 Posts
            Well I got it working, but it was constantly glitching out... then I spoke to a few people and it turns out it is considered one of the most uselessly unreliable APIs one can find. Thanks guys, but I think I will just forego using bad tech sad
              Ben Morrison
              Hacking templates to pieces since 2003
              • 3749
              • 24,544 Posts
              Sorry it didn't work out.
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting