SimpleHighrise, a PHP wrapper class for the Highrise API
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
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.
August 22nd, 2007 at 3:08 am
Nice, but your code here includes your token. I changed that line to
curl_setopt($ch, CURLOPT_USERPWD, $this->token);
September 24th, 2007 at 11:31 am
[…] on it here. Filed under Code having Leave a […]
September 26th, 2007 at 2:32 am
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-(
October 17th, 2007 at 10:44 pm
[…] is a mobile interface for 37signals‘ Highrise contact manager, built using my SimpleHighrise PHP […]
October 23rd, 2007 at 10:41 am
This is just what I needed for a personal project. How exactly should I credit you?
January 11th, 2008 at 6:57 am
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?
January 11th, 2008 at 8:31 am
@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.
January 11th, 2008 at 8:38 am
@Ehud,
Please credit Garlin Gilchrist II of Opportunity Technology.
Thanks for using SimpleHighrise!
February 8th, 2008 at 8:17 am
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"));
}
February 20th, 2008 at 2:04 pm
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.
March 21st, 2008 at 2:08 am
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!
April 2nd, 2008 at 4:04 pm
Does any one have an example of how to set up a form to create a new person?
Thanks
April 2nd, 2008 at 4:26 pm
@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];
April 3rd, 2008 at 7:33 am
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
April 7th, 2008 at 9:20 am
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?