Developer's API Documentation : Contexts

Overview

Context is a concept that is frequently used by people who use the GTD methodology. It allows you to assign tasks to certain contexts in which they must be completed. For example, 'work', 'home', and 'shopping' are some commonly used contexts.

Jump To:

Syncing

Syncing contexts is fairly straight forward. The first thing to do is add any new contexts you have created and delete any contexts that you have deleted. Then, look at the "lastedit_context" timestamp returned from Account Info to determine if any changes have happened on the server since the last time you synced. If yes, then you need to fetch the contexts from the server and integrate this into your local copy. This is where you would do conflict resolution if a context was edited in both places. After this, if you have any contexts that you edited, you can send these edits up to the server.

Sync Flowchart

Retrieving Contexts

The "contexts/get.php" API call will return a list of your contexts with their names and id numbers. You can access this via GET or POST.

http://api.toodledo.com/3/contexts/get.php?access_token=yourtoken

This call will return a JSON encoded object that looks like this.

[{"id":123,"name":"Work","private":0},{"id":456,"name":"Home","private":1},{"id":789,"name":"Car","private":0}]

You can also specify xml as the output format for any API calls by attaching "f=xml" to the URL.

http://api.toodledo.com/3/contexts/get.php?access_token=yourtoken&f=xml

<contexts>
	<context><id>123</id><name>Work</name><private>0</private></context>
	<context><id>456</id><name>Home</name><private>1</private></context>
	<context><id>789</id><name>Car</name><private>0</private></context>
</contexts>

Adding Contexts

Add a context using the "contexts/add.php" API call. You can access this via POST. Context names must be unique within an account. If you try to add a context that already exists, you'll get an error. Each user can have up to 1000 contexts. If you try to add more than this, you will get an error.

  • name : A text string up to 64 characters. (required)
  • private : A boolean value (0 or 1) that describes if this context can be shared. A value of 1 means that this context is private.

http://api.toodledo.com/3/contexts/add.php
	name=MyContext
	access_token=yourtoken

If the add was successful the new context will be returned.

[{"id":12345,"name":"MyContext","private":0}]

<contexts>
	<context><id>12345</id><name>MyContext</name><private>0</private></context>
</contexts>

Editing Contexts

Edit a context using the "contexts/edit.php" API call. You can access this via POST. Context names must be unique within an account. If you try to edit the context name to one that already exists, you will get an error. If you try to edit the context, but pass in the same values that already exist on the server, you will get an error. You should avoid making unnecessary edits.

  • id : The id number of the context to edit. (required)
  • name : A text string up to 64 characters. (required)
  • private : A boolean value (0 or 1) that describes if this context can be shared. A value of 1 means that this context is private.

http://api.toodledo.com/3/contexts/edit.php
	id=12345
	name=MyContext
	access_token=yourtoken

If the edit was successful the edited context will be returned.

[{"id":12345,"name":"MyContext","private":0}]

<contexts>
	<context><id>12345</id><name>MyContext</name><private>0</private></context>
</contexts>

Deleting Contexts

The "contexts/delete.php" API call will allow you to permanently delete a context. You can access this via POST. Any tasks that have this context will have their context set to "none".

  • id : The id number of the context to delete. (required)

http://api.toodledo.com/3/contexts/delete.php
	id=12345
	access_token=yourtoken

If the delete was successful you will get the following message.

{"deleted":12345}

<deleted>12345</deleted>

Error Codes

Any of the API calls can return error messages. Here is a list of the error messages that you may receive from the contexts API endpoints. If there was an error when editing or deleting a context, the id number that you attempted to edit will be included in the error's "ref" field for your reference.

  • 301 : Your context must have a name.
  • 302 : A context with that name already exists.
  • 303 : Max contexts reached (1000).
  • 304 : Empty id.
  • 305 : Invalid context.
  • 306 : Nothing was edited.


Examples:
{"errorCode":302,"errorDesc":"A context with that name already exists","ref":1234}

<error id="302" ref="1234">A context with that name already exists</error>