Basecamp: API Examples using PHP and cURL (GET)

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

$session = curl_init();
$basecamp_url = 'https://YOUR-BASECAMP-URL/';
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);

Getting People By Company ID

You only need to change line 7 of the code above to:

curl_setopt($session, CURLOPT_URL, $basecamp_url.'contacts/people/COMPANY-ID');

Getting A Single Project

Again, you only need to change line 7 to:

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:

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

This entry was posted in PHP, Web Apps. Bookmark the permalink.

25 Responses to Basecamp: API Examples using PHP and cURL (GET)

  1. J.I.N. says:

    Hi there,

    I´m also trying to connect with Basecamp and retrieve and display all the projects on the screen. I´d like to do this in PHP but I have no found no relevant information on the web so far. Could you provide us with some sample to achieve this for the new Basecamp (so not the Classic)

    Thanks in advance I’m looking forward to your response.

    Kind regards,


  2. Vivek says:

    Hey.i m just getting black page………..

    any idea about that???????

  3. martin says:

    good blog. helpfull

  4. Pingback: Basecamp: API Examples using PHP and cURL (GET) | Prattski | Magento & Web Development » Web Design

  5. saurav says:

    I am new in highrise. I got to create highrise me out guys

    • Josh Pratt says:

      @saurav – You’ll have to figure it out on your own. Sorry man. Hope you are able to figure it out.

  6. Wouter says:

    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

  7. Julia says:

    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.


    • Vivek says:

      I m getting same……………plz help us

      • Josh Pratt says:

        I haven’t done anything with this for a very long time. On top of that, I have no idea how you are implementing or using this, so, I have no idea. I am no longer supporting this outside of just providing the information in this post. I hope you are able to figure it out.

  8. Roland says:

    Here is the answer to all your problems :)

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

  10. Got what i was looking for! :)

  11. Bobby says:

    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 ?

  12. Connie Webster says:

    This is the BEST blog I read all month :)

  13. Edvin says:

    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?

  14. WP Themes says:

    Genial dispatch and this post helped me alot in my college assignement. Thank you on your information.

  15. Amazing Rando says:

    I’m interested.

  16. dthawkins says:

    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.

  17. perk says:

    You can create your own class with the information so generously provided. Thanks !!!!!

  18. Jeff says:

    Would love to see the PHP class.

  19. Thomas says:

    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

  20. jerich says:

    How do i create a project? is it available in your class?

    • Josh Pratt says:

      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!

  21. James says:


    Did you ever create a php class for this? I have been looking all over!