…the wise rule the strong…

Activist Nerd

SimpleHighrise, a PHP wrapper class for the Highrise API

August 14th, 2007 by garlinii

I have just began using some of the products from 37signals, including Ta-da List, Backpack, and Highrise (I also have a dormant Basecamp account).

Today I’d like to announce the first of many coding projects I’ll be posting at Activist Nerd: SimpleHighrise. This was inspired SimpleBackpack, the PHP wrapper class for Backpack, and much of the underlying utility code remains intact.

Download

SimpleHighrise.php, vAlpha

SimpleHighrise.php, vBeta

SimpleHighrise.php, vGamma

Disclaimer

This code comes no warranty, so use it at your own risk

What it doesn’t do [yet]

  • Error checking/handling
  • Update operations on objects listed in the Highrise API

What it does do

On all objects listed in the Highrise API:

  • Show
  • List
  • Create
  • Destroy

Please try it out and let me know any problems, issues, or ideas about SimpleHighrise!

Sample Usage

The following code instantiates a SimpleHighrise object. $result will hold the raw XML for all of the people the user can see:

include('simplehighrise.php');
$token = "token".":foo"; // tack on : (colon) and dummy password
$hr = new SimpleHighrise('user', $token);
$result = $hr->list_people();
echo $result;

Just as in SimpleBackpack, in order to return SimpleXML, do the following:

include('simplehighrise.php');
$token = "token".":foo";
$hr = new SimpleHighrise('username', $token, 'simplexml');

I’ll be adding to this as time progresses.

Update (24 Sep 2007): I posted vGamma, which has the following changes:

  • Error handling: returns -1 if no results are returned from an op or if an op fails
  • Better case support
  • Miscellaneous bug fixes in handling different data types

Update (16 Aug 2007): I posted vBeta, which has the following changes:

  • Added ability to return results as an array, using code from here. Here is an example:include('simplehighrise.php');
    $token = "token".":foo";
    $hr = new SimpleHighrise('username', $token, 'array');
  • Fixed search_people() and search_companies() to be able to return multiple people/companies (before, it was written to only return the1st person/company.
  • Miscellaneous bug fixes.
Filed under Code having

15 Responses

  1. Otto Says:

    Nice, but your code here includes your token. I changed that line to
    curl_setopt($ch, CURLOPT_USERPWD, $this->token);

  2. Activist Nerd » Blog Archive » SimpleHighrise Update posted Says:

    […] on it here. Filed under Code having Leave a […]

  3. Brian Says:

    We are using a paid version of HiRise which means the class needed a couple of mods:-
    1. to ‘request()’ mod to read https (or better make a variable)
    2. to ‘curl_request()’ add ‘curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);’

    However I did note that using ‘http://…’, I got a message attempting to redirect to ‘https://…’ would be nice to capture that and call recersively (no need for a flag). I’ve been put on other work for now 8-(

  4. Activist Nerd » Blog Archive » nContxt: The right things. The right time. Says:

    […] is a mobile interface for 37signals‘ Highrise contact manager, built using my SimpleHighrise PHP […]

  5. Ehud Says:

    This is just what I needed for a personal project. How exactly should I credit you?

  6. Chris Says:

    I’m trying to use Simplehighrise for some API interaction and I’m having problems. I would like to get at the information like first-name and company-id but whenever I try to access it by entering $result->company-id or $result->first-name I’m getting a PHP error because of the format.

    Any idea how I can get at this data?

  7. garlinii Says:

    @Chris,

    You can get at this information using XPath to navigate the XML structure documented on the HR dev site. Here’s an example that grabs a search term from the URL query string, does a search via SimpleHighrise, and returns the ids of all companies matching the term:

    $hr = new SimpleHighrise($site, $token, 'simplexml');
    $searchTerm = $_GET['query'];
    $resultCompanies = $hr->search_companies((string)$searchTerm);
    foreach ($resultCompanies as $company) {
    $idElements = $resultCompanies->xpath(’//company/id’);
    $id = $idElements[$i];
    echo ‘Comapny id: ‘.$id;
    }

    Using XPath, you can get to any of the desired data returned in the XML.

    Thanks for using SimpleHighrise, and let me know if you have any further questions.

  8. garlinii Says:

    @Ehud,

    Please credit Garlin Gilchrist II of Opportunity Technology.

    Thanks for using SimpleHighrise!

  9. Michael Wuori Says:

    May be obvious, may be helpful: To add street address when adding a new contact, I altered the function create_new_person() to the one below. Hope it helps someone (useful for capturing contact-form info).

    function create_new_person($firstName = "", $lastName = "", $phoneNumber = "", $companyName = "Just Added", $emailAddress = "foo@bar.com", $location = "Work",$street="", $city="", $state="",$zip="") {
    return($this->request("people.xml",
    array(
    "person" => array(
    "first-name" => $firstName,
    "last-name" => $lastName,
    "company-name" => $companyName,
    "contact-data" => array(
    "email-addresses" => array(
    "email-address" => array(
    "address" => $emailAddress,
    "location" => $location
    )
    ),
    "phone-numbers" => array(
    "phone-number" => array(
    "number" => $phoneNumber,
    "location" => $location
    )
    ),
    "addresses" => array(
    "address" => array(
    "street"=>$street,
    "city" => $city,
    "state"=> $state,
    "zip"=>$zip,
    "location"=>$location
    )
    )
    )
    )
    )
    , "POST"));
    }

  10. Bill DA Says:

    I would also love to see this support SSL (and non-SSL, auto-detecting).

    As it is now, you have to give up a good bit of security in order to use this script.

  11. Phil B Says:

    Would love to try any examples of the update record function. I want to add notes to both people and cases but am struggling here. I would also love the ability to search by email address but know that the Highrise API is not doing this yet! It is all good and loving your work!

  12. Aaron Brockhurst Says:

    Does any one have an example of how to set up a form to create a new person?

    Thanks

  13. garlinii Says:

    @Aaron,

    Here’s some sample for form code from nContxt, an app I built using SimpleHighrise:

    Form






    PHP


    $hr = new SimpleHighrise($site, $token, 'simplexml', $sub_type);

    $fn = $_POST['firstName'];
    $ln = $_POST['lastName'];
    $pn = $_POST['phoneNumber'];

    $result = $hr->create_new_person($fn, $ln, $pn);
    if (isset($_GET['debug'])) print_r($result);
    $personIdElement = $result->xpath('//id');
    $personId = $personIdElement[0];

  14. Aaron Says:

    This isn’t working for me - maybe I’m missing something.

    When I print out the result I get SimpleXMLElement Object ( [body] => You are being . )

    Any tips greatly appreacated

    Thanks

  15. luke Says:

    had some problems getting get_Id to work, most likely due to php version (wants 5, have 4) I got around that by doing:

    //function to pull first found persons ID out of the xml
    function find_ID ($result = ""){
    // goto person section
    $PersonLine=strpos($result, "");
    $string=substr($result, $PersonLine);
    //goto ID line
    $IDLine=strpos($result, "");
    $string=substr($result, $IDLine);
    // find first and last position of ID field
    $IDLine=strpos($string,">");
    $IDLineEnd=strpos($string,"");
    //save out the ID
    $string=substr($string,$IDLine + 1,$IDLineEnd - 1 - $IDLine );
    return $string;
    }

    also, I didn’t see a way to add a tag to a person. am I just blind?

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.