Recent Posts by Matt Larner

Jul 6, 2008
Avatar Matt Larner 1 post

Topic: Basecamp API / Time Tracking API Incomplete

I use time-tracked todo list items with descriptions all the time, and Timepost’s lack of support for this keeps me from using it. I found this forum post after hearing the Basecamp API doesn’t support this feature.

I just wanted to chime in that the Time Tracking API works fine and dandy for me. I dug into the API this weekend to investigate the issue and was able to post time, attached to a specific todo list item, with a description, using PHP and CURL (code below).

I’m working on a super simple timer at the moment using the Aaron Quint’s PHP wrapper for the API. I’ll post my code when I get it functional

Matt Larner
Receiver Design

XML string (straight out the documentation)


<request>
   <entry>
      <project-id>'.$projectID.'</project-id>
      <person-id>'.$personID.'</person-id>
      <date>'.$date.'</date>
      <hours>'.$hours.'</hours>
      <todo-item-id>'.$todoItem.'</todo-item-id>
      <description>'.$description.'</description>
   </entry>
</request>

The CURL options I used are a synthesis of some tutorials I found linked from this forum.


function post($post_xml='', $url, $user, $password)
{
    $user_agent = $_SERVER['HTTP_USER_AGENT'];
    $ch = curl_init(); // initialize curl handle
    curl_setopt($ch, CURLOPT_URL, $url); // set url to post to
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD, $user . ":" . $password);
    curl_setopt($ch, CURLOPT_FAILONERROR, 1); // Fail on errors
    curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1); // allow redirects
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1); // return into a variable
    curl_setopt($ch, CURLOPT_HEADER, false);
    curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept: application/xml', 'Content-Type: application/xml'));
    curl_setopt($ch, CURLOPT_TIMEOUT, 15); // times out after 15s
    curl_setopt($ch, CURLOPT_POSTFIELDS, $post_xml); // add POST fields
    curl_setopt($ch, CURLOPT_USERAGENT, $user_agent);

    if(ereg('^(https)',$request)) {
        curl_setopt($session,CURLOPT_SSL_VERIFYPEER,false);
    }

    $data = curl_exec($ch);
    curl_close($ch);
    return $data;
}