Try using the Wunderlist API in Python

I tried to touch the API of Wunderlist, which is famous as a task management application, in Python. The API Document is also well written, so I think it's an easy-to-use API. OAuth2 is used for authentication.

1. Preparation

The minimum requirement is to have your own Wunderlist account. First, log in to the following page using your account. https://developer.wunderlist.com/

Then click REGISTER YOUR APP スクリーンショット 2015-11-13 15.17.05.png

The registration screen will appear, so enter the required information and click SAVE. You can change it later, but you must enter the NAME, APP URL, and AUTH CALLBACK URL. スクリーンショット 2015-11-13 15.21.26.png

Then you can get the CLIENT ID and CLIENT SECRET. スクリーンショット 2015-11-13 15.21.52.png

This time, for the sake of simplicity, get an ACCESS TOKEN for your account. Click CREATE ACCESS TOKEN. スクリーンショット 2015-11-13 15.32.46.png

You need two things, CLIENT ID and ACCESS TOKEN, to get your account information. Now that we have the necessary information, let's get the user information immediately.

I used a library called Requests-Oauthlib for oauth2 authentication. Authentication details can be found here (https://developer.wunderlist.com/documentation/concepts/authorization). Add X-Client-ID and X-Access-Token to the requested header information and it's OK.


from requests_oauthlib import OAuth2Session
import json

client_id = "YOUR CLIENT ID"
access_token = "YOUR ACCESS TOKEN"
url = "https://a.wunderlist.com/api/v1/user"
params = {}

wunderlist = OAuth2Session()
wunderlist.headers['X-Client-ID'] = client_id
wunderlist.headers['X-Access-Token'] = access_token
req = wunderlist.get(url, params=params)

if req.status_code == 200:
    user = json.loads(req.text)
    print user['name']
else:
    print ("Error: %d" % req.status_code)

Did you see your username safely?

2. Touch the API

Try to get a list of lists

https://developer.wunderlist.com/documentation/endpoints/list

Change url

url = "https://a.wunderlist.com/api/v1/lists"

The id in the list is used to CRUD the task.

req = wunderlist.get(url, params=params)

if req.status_code == 200:
    lists = json.loads(req.text)
    for list in lists:
        print list["id"], list["title"].encode('utf-8')
else:
    print ("Error: %d" % req.status_code)

b. Create a task

Change the url and params. By the way, it seems that toilet paper is often written on the shopping list. (There is no doubt that it is information from the person at the head office.)

url = "https://a.wunderlist.com/api/v1/tasks"
params = {
    "list_id": "Shopping list ID", #integer
    "title": "Toilet Paper", #string
}

This time it's POST instead of GET. The status_code also changes.

req = wunderlist.post(url, json=params)

if req.status_code == 201:
    print "New task was successfully created."
else:
    print ("Error: %d" % req.status_code)

Look at your Wunderlist and it's okay if you have added toilet paper to your shopping list.

c. Complete the task

This is a task update. Let's say you bought the toilet paper you just added.

Change the url and params.

url = "https://a.wunderlist.com/api/v1/tasks/"
params = {
    "revision": 1, #Basically 1 is okay
    "completed": True,
}
task_id = "Toilet paper ID"
url += task_id

We use a function called PATCH.

req = wunderlist.patch(url, json=params)

if req.status_code == 200:
    print "Task was successfully completed."
else:
    print ("Error: %d" % req.status_code)

Check Wunderlist to make sure the toilet paper task is complete.

The ids for tasks and lists can be seen at a glance by looking at the url in the web version of Wunderlist.

Recommended Posts

Try using the Wunderlist API in Python
Try using the Kraken API in Python
Try using the BitFlyer Ligntning API in Python
Try using the DropBox Core API in Python
Tweet using the Twitter API in Python
Try hitting the YouTube API in Python
Try using the Twitter API
Try using the Twitter API
Try using the PeeringDB 2.0 API
Try using ChatWork API and Qiita API in Python
Initial settings when using the foursquare API in python
Using the National Diet Library Search API in Python
Getting the arXiv API in Python
Hit the Sesami API in Python
Try using Pleasant's API (python / FastAPI)
Try using LevelDB in Python (plyvel)
Hit the web API in Python
Try using Python argparse's action API
Try using the Python Cmd module
Access the Twitter API in Python
Try using Leap Motion in Python
Mouse operation using Windows API in Python
Try using the HL band in order
Get Youtube data in Python using Youtube Data API
Quickly try Microsoft's Face API in Python
Try hitting the Spotify API in Django.
Regularly upload files to Google Drive using the Google Drive API in Python
Try using FireBase Cloud Firestore in Python for the time being
Evernote API in Python
Try gRPC in Python
C API in Python 3
Try 9 slices in Python
Try using Tweepy [Python2.7]
[Cloudian # 7] Try deleting the bucket in Python (boto3)
Python: Try using the UI on Pythonista 3 on iPad
Get image URL using Flickr API in Python
Try using the Python web framework Tornado Part 1
Tips for hitting the ATND API in Python
Let's judge emotions using Emotion API in Python
Pre-process the index in Python using Solr's ScriptUpdateProcessor
Try using the collections module (ChainMap) of python3
Try using the Python web framework Tornado Part 2
Try implementing the Monte Carlo method in Python
Hit the Firebase Dynamic Links API in Python
Try accessing the YQL API directly from Python 3
Hit Mastodon's API in Python
Upload JPG file using Google Drive API in Python
[Python] Try using Tkinter's canvas
Download the file in Python
[Unity (C #), Python] Try running Python code in Unity using IronPython
Find the difference in Python
[AWS IoT] Register things in AWS IoT using the AWS IoT Python SDK
Try using Kubernetes Client -Python-
Determine the threshold using the P tile method in python
Get LEAD data using Marketo's REST API in Python
Try LINE Notify in Python
Send and receive Gmail via the Gmail API using Python
Try to delete tweets in bulk using Twitter API
OpenVINO using Inference Engine Python API in PC environment
Try implementing Yubaba in Python 3
Blender Python API in Houdini (Python 3)