Sample Python code to query Wunderlist API
Update: Wunderlist is no more - it got acquired by Microsoft :( The domain is also broken but I’ll leave the code here for funzies.
So I’ve been working on a simple application at home, part of which I want a list of items, which I want to be able to control from Wunderlist. As a relative novice to Python, I was looking around for some pre-built library that I could just plug in to my existing code. A few things do exist - there’s some sample code at Github and there’s even a basic API wrapper called wunderpy2.
This would be great if you’re doing some complicated full integration in to a publically consumable app. However, in each case, for my needs, both seemed like overkill or unnecessarily complicated - I just wanted to query a Wunderlist list and get the items.
So here follows a short (and very basic) tutorial for what is actually a relatively simple process using the python requests library and the json interpreter.
- Install requests. You could use pip but I prefer apt-get. The requests page has options on this.
- Go to Wunderlist and login. Find the list you will want to access in your code. Click on it. Make a note of that last integer - this is the ID of your list.
- Head over to the API / developer site. Create a new app. Give it a title and a description. For the URL fields (auth and callback) just put anything in.
- When that’s done, on the success screen, click the ‘Create access token’ button. Make a note of the ‘Access Token’ and ‘Client ID’ values.
- Use the code below. Put it in a file (e.g., wunder.py)
- At your terminal, type ‘python wunder.py’. This should now connect to Wunderlist and print out the titles of every item in your list.
Obviously this is sample code only - there is no error checking or robustness of any sort in this so if you do plan to use in a quasi-production environment, then you will want to beef it up.
Leave a comment if this helps you!
import requests import json access_token = 'your wunderlist access token' client_id = 'your client id' list_id = 'your list id' headers={'X-Access-Token': access_token, 'X-Client-ID': client_id, 'Content-Type' : 'application/json'} print("Querying Wunderlist...") f = requests.get('https://a.wunderlist.com/api/v1/tasks', headers=headers, params={'list_id': list_id}) print("Done! Code: %s") %(f.status_code) j = json.loads(f.text) for i in j: print i['title']