Toodledo API implemented in PHP

Posted: March 29th, 2010 | Author: | Filed under: PHP | Tags: , , , | 12 Comments »

Toodledo API 2.0 is out, which is not supported by this class. The 1.0 version is depreciated, but still supported for now. I’ll publish a new version when I have some free time.

I couldn’t find one, so I decided to write a PHP class that talks with Toodledo API. its not very well documented/commented, but quite simple and works well.

Works on PHP5+ only. Uses the built-in stream wrapper for making HTTP requests, and returns the response as an SimpleXML object. It uses file-system caching for storing the tokens the API gives you (there’s a CACHEDIR const to define where it should be saved).

The usage is as follows:

$t = new Toodledo('user id', 'password', 'app id'); // last parameter is optional

// Add task
$response = $t->addTask(array(
	'title' => 'Finish writing toodledo class in PHP',
$id = (string)$response->added;

// Get tasks
$tasks = $t->getTasks(array(
	'title' => 'foo',
	'tag' => 'bar',
foreach ($tasks->task as $task) {
	echo (string)$task->title;

You can also get the response as raw XML string and as array, by using Toodledo::RAW and Toodledo::ARR as the second argument.

print_r($t->getTasks(array('title' => 'foo'), Toodledo::ARR));

OK, so, I must admit – I cheated. I didn’t really implement the entire API, I just wrote one method named request() and used some __call() magic to make everything work. basically, you just call $object->APIMethodName(array(‘extra’=>’parameters’)) with whatever method name and parameters and it just build the request accordingly.

When an error occurs (either while making the request or the Toodledo API returns an error), an Exception is thrown. Make sure to catch those.

That’s about it. You can download it here. Released under the WTFPL license.

12 Comments on “Toodledo API implemented in PHP”

  1. 1 Jon said at 9:13 am on March 29th, 2010:

    Great post, I have considered using Toodledo’s API for my business purposes but have lacked the will to write my own implementation for PHP.

    Your contribution is much appreciated.

  2. 2 Charlie Rosenbury said at 12:25 am on June 1st, 2010:

    This thing is looking great! Thanks for taking the time.

    However, the getFolders call only returns the folder’s titles. Is there a way to include each folder’s attributes?

  3. 3 shesek said at 6:36 pm on June 2nd, 2010:

    That’s really more up to Toodledo’s API, and since I never needed the folder’s attributes, you should probably ask that at their forums

  4. 4 Charlie Rosenbury said at 4:20 pm on June 4th, 2010:

    If you look on the first page of the api (, it says that it returns attributes with the folders when you call ‘getFolders.’

    So the information is definitely available in the API. Would it be tricky to implement?

  5. 5 shesek said at 4:55 pm on June 10th, 2010:

    If Toodledo’s API returns it, it should be there. How are you trying to read it? The correct way of accessing those attributes is:
    $folders = $t->getFolders();
    foreach ($folders as $folder) {
    $attributes = $folder->attributes();
    echo 'id: '.$attributes['id'];
    echo 'private: '.$attributes['private'];

    If it doesn’t work, check the raw response:
    echo $t->getFolders(array(), Toodledo::RAW);
    Is it there?

  6. 6 cohuman said at 1:06 am on September 10th, 2010:

    [...] Toodledo API implemented in PHP shesek I think this is the second time in a week that I've found something created shesek. Nice implementation, I like the fact that he cheats, his words, and uses __call magic. (tags: api tasks programming) [...]

  7. 7 HJ said at 12:57 pm on July 27th, 2011:


    where can I get the PHP-API.
    The link is dead.

    Thank U

  8. 8 shesek said at 3:07 pm on July 27th, 2011:

    Thanks for letting me know, I updated the link.

  9. 9 HJE said at 1:11 pm on August 2nd, 2011:


    can you help me.
    I don’t get it works with php5.
    Message: “Fatal error: Uncaught exception ‘Exception’ with message ‘Empty response’ ”

    What paramter do I have to give to the token API?
    $t = new Toodledo(‘???’, ‘???’); // last parameter is optional

    Can you give me a working example, that shows all tasks in one folder?

    Thank U

  10. 10 HJE said at 1:19 pm on August 2nd, 2011:


    does the API work with the version 2.0?

    Thank U

  11. 11 shesek said at 1:31 am on August 13th, 2011:

    @HJE, No, it works with the 1.0 API. I’ll do my best to publish a new version when I get some time.

    The parameters for the constructor are your user id and password. There’s an usage example in the post contents. I’m not sure why you’re getting that error, Toodledo’s API should return something, even if some error occurred. Can you show me how you’re using it?

  12. 12 dbw said at 10:02 pm on September 20th, 2011:

    Any chance you’re going to update it soon? Seems like your (simple & elegant) implementation wouldn’t require too many changes…would it?

Leave a Reply