Developer's API Documentation : Locations
Syncing
Syncing locations is fairly straight forward. The first thing to do is add any new locations you have created and delete any locations that you have deleted. Then, look at the "lastedit_location" 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 locations from the server and integrate this into your local copy. This is where you would do conflict resolution if a location was edited in both places. After this, if you have any locations that you edited, you can send these edits up to the server.
Retrieving Locations
The "locations/get.php" API call will return a list of your locations with their names and id numbers. You can access this via GET or POST.
http://api.toodledo.com/2/locations/get.php?key=YourKey
This call will return a JSON encoded object that looks like this.
JSON: [{"id":"123","name":"Work","description":"123 Main Street","lat":"12.345","lon":"-45.678"}, {"id":"456","name":"Home","description":"","lat":"13.345","lon":"-42.678"}, {"id":"789","name":"Car","description":"","lat":"0.0","lon":"0.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/2/locations/get.php?key=YourKey;f=xml
XML: <locations> <location> <id>123</id><lat>12.345</lat><lon>-45.678</lon> <name>Work</name><description>123 Main Street</description> </location> <location> <id>456</id><lat>13.345</lat><lon>-42.678</lon> <name>Home</name><description></description> </location> </locations>
Adding Locations
Add a location using the "locations/add.php" API call. You can access this via GET or POST. Location names must be unique within an account. If you try to add a location that already exists, you'll get an error. Each user can have up to 500 locations. If you try to add more than this, you will get an error.
- name : A text string up to 32 characters. (required)
- description : A text string up to 255 characters used to describe the locaiton (address, phone number, hours of operation, etc). (optional)
- lat : A decimal representing the latitude. (optional)
- lon : A decimal representing the longitude. (optional)
http://api.toodledo.com/2/locations/add.php?name=MyLocation;lat=45.678; lon=-123.456;key=YourKey
If the add was successful the new location will be returned.
JSON: [{"id":"12345","name":"MyLocation","description":"","lat":"45.678","lon":"-123.456"}]
XML: <locations> <location> <id><lat>45.678</lat><lon>-123.45</lon></id> <name>MyLocation</name><description></description> </location> </locations>
Editing Locations
Edit a location using the "locations/edit.php" API call. You can access this via GET or POST. Location names must be unique within an account. If you try to edit the location name to one that already exists, you will get an error. If you try to edit the location, 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 location to edit. (required)
- name : A text string up to 32 characters. (optional)
- description : A text string up to 255 characters used to describe the locaiton (address, phone number, hours of operation, etc). (optional)
- lat : A decimal representing the latitude. (optional)
- lon : A decimal representing the longitude. (optional)
http://api.toodledo.com/2/locations/edit.php?id=12345;name=MyLocation;key=YourKey
If the edit was successful the edited location will be returned.
JSON: [{"id":"12345","name":"MyLocation","description":"","lat":"45.678","lon":"-123.456"}]
XML: <locations> <location> <id><lat>45.678</lat><lon>-123.45</lon></id> <name>MyLocation</name><description></description> </location> </locations>
Deleting Locations
The "locations/delete.php" API call will allow you to permanently delete a location. You can access this via GET or POST. Any tasks that have this location will have their location set to "none".
- id : The id number of the location to delete. (required)
http://api.toodledo.com/2/locations/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 locations API.
- 1 : You did not specify a key for authentication.
- 2 : The authentication key that you provided has expired or is invalid.
- 3 : No location was specified. The id number is a required paramater.
- 4 : The location specified in your call does not exist.
- 5 : You tried to add or edit a location with a name that already exists.
- 6 : The user has the maximum number of locations, so you can't add any more.
- 7 : You tried to add or edit a location without a name. A location must have a name.
- 8 : You tried to edit a location 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 location with that name already exists</error>