![]()
I began working on a project today creating a type of work-request form. We use Basecamp for all of our project management, but since it’s a paid subscription and not something that we have control over, any extra functionality must be done elsewhere using Basecamp’s API.
The Project: I work for a web development company, and we have a good number of clients who request little updates/projects/additions on a fairly regular basis. We started running into the occasion more and more that a client would send us an email labeled “URGENT” and expect us to get something done for them within the hour. When you are busy with other things, that is an unreasonable expectation. So, we have since applied “Rush Jobs”. The standard turn-around guarantee is 10 business days. If they want it done in 5 days, or 2 days, they pay more (just like FedEx).
We sent out letters at the beginning of 2008 informing all of our clients of the new policy, however, it didn’t really sink in. So, our next thought (which is what I’m working on now) is to create a work-request form, forcing them to have to manually select the turn-around time, having the prices right there in front of their eyes, every time.
I won’t go into detail about how we’ve decided to architect the interface, and how it all works – but I will say that we are keeping the system up-do-date at all times with company, project, and person data from Basecamp using the available API. I had an very difficult time finding good examples of how to both gather, and post information to and from Basecamp. But, I managed to successfully do both, and I thought I’d share the wealth!
Getting All Projects
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $session = curl_init(); $basecamp_url = 'https://YOUR-BASECAMP-URL/'; $username = 'YOUR-BASECAMP-USERNAME'; $password = 'YOUR-BASECAMP-PASSWORD'; curl_setopt($session, CURLOPT_URL, $basecamp_url.'projects.xml'); curl_setopt($session, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); curl_setopt($session, CURLOPT_HTTPGET, 1); curl_setopt($session, CURLOPT_HEADER, false); curl_setopt($session, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml')); curl_setopt($session, CURLOPT_RETURNTRANSFER, true); curl_setopt($session,CURLOPT_USERPWD,$username . ":" . $password); if(ereg("^(https)",$request)) curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false); $response = curl_exec($session); curl_close($session); |
Getting People By Company ID
You only need to change line 7 of the code above to:
1 | curl_setopt($session, CURLOPT_URL, $basecamp_url.'contacts/people/COMPANY-ID'); |
Getting A Single Project
Again, you only need to change line 7 to:
1 | curl_setopt($session, CURLOPT_URL, $basecamp_url.'projects/PROJECT-ID.xml'); |
As you can see, there’s not much to change to get different results of information. Though Basecamp’s API doesn’t really tell you how to set everything up in PHP very well, it does give you enough, once you’ve got it all setup, to figure out what you need to change line 7 to to give you the results you want.
The results that are returned are pure XML. You can choose to do whatever you want with that information. I personally have been using PHP’s Simple XML. If you echo out the results, you’ll see the XML and see all the available children, otherwise, you can also check out this page on Basecamp’s API for a quick-reference of everything.
Let’s say we used the API to return all of the people from a specific company id (2nd example above) to the variable $response. Here is an example of how to display some of the XML results that we specify using Simple XML:
1 2 3 4 5 6 7 8 | $people_xml = new SimpleXMLElement($response); foreach ($people_xml->person as $person) { echo "<strong>".$person->{'first-name'}." ".$person->{'last-name'}."</strong><br />"; echo "Email: ".$person->{'email-address'}."<br />"; echo "ID: ".$person->id."<br /><br />"; } |
And that’s all there is to it. It’s pretty straight-forward. I’m currently working on a Basecamp PHP class that will at least handle all the functions that we’ll be using. Maybe once it’s done, I’ll post it for download. If you have any interest in a Basecamp PHP class, please post a comment and let me know – the more interest I get, the more motivated I’ll be to post it when I’m done.
I will be posting another article very soon about how to post information (messages, to-dos, file attachments) to Basecamp using the API. Look for that fairly soon.

Hi,
Did you ever create a php class for this? I have been looking all over!
Cheers
How do i create a project? is it available in your class?
Unfortunately, creating projects is not something that is built into Basecamp’s API. It’s a frustrating fact that many people dislike – so, make it known to 37 Signal’s if you want it to be a feature!
Hi,
Could you please guide me to retrive the following using basecamp’s API ,
1. To do list item importing
2. Time importing
3. each to do list items to the relevant Basecamp URL for comments on the to do list item
looking forward
Would love to see the PHP class.
You can create your own class with the information so generously provided. Thanks !!!!!
Excellent work! Thank you.
to everyone asking for the class; MAKE YOUR OWN!
use this as a starting point and use 37signals’s API docs for your reference.
I’m interested.
Genial dispatch and this post helped me alot in my college assignement. Thank you on your information.
For a simple beginner, isn’t there someone who could provide an example php class in order to view the result of this code? I would just like to be able to read the xml file in my browser with php, how do i execute this?
This is the BEST blog I read all month
This has helped a lot!
I am able to pull in all the data from each of the api.xml files from basecamp.
But so far have only been able to read the data.
How would I put/post something to the api do you have an example ?
Got what i was looking for!
Quick note that may save some people time:
Username isn’t your Basecamp username, it’s the API Key list under My Info. The password field can be filled with whatever.
Thanks for this information!
Here is the answer to all your problems
http://code.google.com/p/basecamp-php-api/
I have tried above code from my local calling basecamp with:
$username = ‘my basecamp token’;
$password = ‘X’;
But I get empty response without any error message. Has anyone ever encountered this issue before?
Appreciate any input.
Thanks.
Does anybody know how to get all the time entries at once? Like this for example: /projects/8169011/time_entries?page=all (which does’nt work)
Using this: /projects/8169011/time_entries
will only return the first page
You can go trough the pages by passing the page paramater, like this:
/projects/8169011/time_entries?page=2 (for page 2)
But I like to get all teh entries at once
I am new in highrise. I got to create highrise case.help me out guys
@saurav – You’ll have to figure it out on your own. Sorry man. Hope you are able to figure it out.