Developer's API Documentation : Goals

Syncing

Syncing goals is fairly straight forward. The first thing to do is add any new goals you have created and delete any goals that you have deleted. Then, look at the "lastedit_goal" 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 goals from the server and integrate this into your local copy. This is where you would do conflict resolution if a goal was edited in both places. After this, if you have any goals that you edited, you can send these edits up to the server.

Sync Flowchart

Retrieving Goals

The "goals/get.php" API call will return a list of your goals. You can access this via GET or POST.

http://api.toodledo.com/2/goals/get.php?key=YourKey

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

JSON:
[{"id":"123","name":"Get a Raise","level":"0","archived":"1","contributes":"0","note":""},
{"id":"456","name":"Lose Weight","level":"0","archived":"0","contributes":"0","note":"hi"},
{"id":"789","name":"Exercise","level":"1","archived":"0","contributes":"456","note":""}]

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

http://api.toodledo.com/2/goals/get.php?key=YourKey;f=xml

XML:
<goals>
	<goal><id>123</id><name>Get a Raise</name><level>0</level><archived>1</archived>
	<contributes>0</contributes><note></note></goal>
	<goal><id>456</id><name>Lose Weight</name><level>0</level><archived>0</archived>
	<contributes>0</contributes><note>hi</note></goal>
	<goal><id>789</id><name>Exercise</name><level>1</level><archived>0</archived>
	<contributes>456</contributes><note></note></goal>
</goals>

The id, name, level, contributes and archived fields are described below. The note field is a read-only field that contains a text note related to this goal. It can be edited on our website only at the moment. The empty "goal" field that you may see returned via this call is deprecated and should not be used.

Adding Goals

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

  • name : A text string up to 255 characters. (required)
  • level : The integer 0, 1 or 2 specifying the level. The default is 0. (0=lifetime, 1=long-term, 2=short-term)
  • contributes : The id number for the higher level goal that this goal contributes to.

http://api.toodledo.com/2/goals/add.php?name=MyGoal;key=YourKey

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

JSON: 
[{"id":"12345","name":"MyGoal","level":"0","archived":"0","contributes":"0","note":""}]

XML: 
<goals>
	<goal><id>12345</id><name>MyGoal</name><level>0</level><archived>0</archived>
	<contributes>0</contributes><note></note></goal>
</goals>

Editing Goals

Edit a goal using the "goals/edit.php" API call. You can access this via GET or POST. Goal names must be unique within an account. If you try to edit the goal name to one that already exists, you will get an error. If you try to edit the goal, 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 goal to edit. (required)
  • name : A text string up to 255 characters.
  • level : The integer 0, 1 or 2 specifying the level. The default is 0. (0=lifetime, 1=long-term, 2=short-term)
  • contributes : The id number returned for the higher level goal that this goal contributes to.
  • archived : A boolean value (0 or 1) that describes if this goal is archived.

http://api.toodledo.com/2/goals/edit.php?id=12345;name=MyGoal;key=YourKey

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

JSON: 
[{"id":"12345","name":"MyGoal","level":"0","archived":"0","contributes":"0","note":""}]

XML: 
<goals>
	<goal><id>12345</id><name>MyGoal</name><level>0</level><archived>0</archived>
	<contributes>0</contributes><note></note></goal>
</goals>

Deleting Goals

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

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

http://api.toodledo.com/2/goals/delete.php?id=12345;key=YourKey

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

JSON: 
{"deleted":"12345"}

XML: 
<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 goals API.

  • 1 : You did not specify a key for authentication.
  • 2 : The authentication key that you provided has expired or is invalid.
  • 3 : No goal was specified. The id number is a required paramater.
  • 4 : The goal specified in your call does not exist.
  • 5 : You tried to add or edit a goal with a name that already exists.
  • 6 : The user has the maximum number of goals (500), so you can't add any more.
  • 7 : You tried to add or edit a goal without a name. A goal must have a name.
  • 8 : You tried to edit a goal with values that already exist. Nothing was changed. If you get this a lot, you are making unnecessary edits.
  • 100 : Unknown Error.
  • 500 : The Toodledo server is offline for maintenance.


Examples:
JSON:
{"errorCode":1,"errorDesc":"Empty key"}

XML:
<error id="5">A goal with that name already exists</error>