The Checkvist Inbox and Some API Scripts

Page content

I find myself using Checkvist more every day (Previous Post). I’m constantly surprised by how well it works. I’ve been happily using it for most of my outlining. Recently I started to use it as a sort of Inbox for everything that is not a task. This role was previously filled by Dropbox plain text files but I wanted to try something new to alleviate some problems associated with my large collection of notes.1 I created a single Checkvist list named “Inbox” and I throw ideas, questions, blog post topics, etc. into it.

I’ve also been exploring the Checkvist API with the help of their support group. They offered up a basic shell script to add an item to a list. I’ve modified it and also turned it into a Python script.

Each script requires three pieces of information: the user email address (user_id), the API key (api_key), and the list id (inbox_list_id).

To get the API key, visit Accout page for your profile. Click the “View/Update remote OpenAPI key” link and copy it out.

To get the list ID, visit any Checkvist list and copy it from the end of the URL.

From the Terminal

This shell script allows me to add a new item to my Checkvist inbox from the terminal. Don’t forget to make the script executable by chmod 755 myScriptPath.sh

:::bash
#!/bin/bash
user_id='myUserName'
api_key='myPassword'
inbox_list_id='154929'
echo -e '\033[47;31m' # Set colors
echo "$*"
tput sgr0 # Reset terminal colors

# Authorization:
auth_token=`curl -d "username=$user_id&remote_key=$api_key" https://checkvist.com/auth/login.json`
auth_token=${auth_token:1:12}

#echo $auth_token

# Create new task via import API:
curl -d "token=${auth_token}&import_content=$*" http://checkvist.com/checklists/$inbox_list_id/import.xml

This is run from the Terminal with an argument that is the text to add to the inbox.

From iOS

Below is the same thing but written as a Python script. It accepts a command line argument as the item to add to the inbox.

:::Python
import urllib, urllib2, sys

user_id = 'myUserName'
api_key = 'myPassword'
inbox_list_id = '154929'
auth_url = 'https://checkvist.com/auth/login.json'
connect_url = 'http://checkvist.com/checklists/' + inbox_list_id + '/import.xml'

# Join all of the Args together into one string
task_text = ' '.join(sys.argv[1:])
print task_text

# Get the temporary authorization token
token_data = urllib.urlencode({'username':user_id, 'remote_key':api_key})
req = urllib2.Request(auth_url, token_data)
fd = urllib2.urlopen(req)
auth_token = fd.read(1024)
auth_token = auth_token.replace('"', '').strip()

# Assemble the POST values to submit a new task
values = {'token': auth_token, 'import_content': task_text}
task_data = urllib.urlencode(values)
td = urllib2.urlopen(connect_url, task_data)

print td.read(1024)

And what is this good for? Glad you asked. I added this script to Pythonista (Recent Post) and created a LaunchCenter shortcut to launch it with some parameters.

Here’s the LaunchCenter URL:

pythonista://inboxTask?action=run&args=[prompt]

To use this, I open LaunchCenter and trigger the action. I add some text and send it. Pythonista does all of the work.

From Keyboard Maestro

Of course, I made a Keyboard Maestro macro for this too. Here’s the macro:

This is the code detail for the “Excute Shell Script” step. I really just added in the lines to grab the KM variable:

:::Bash
#!/usr/bin/env python 
import urllib, urllib2, sys,os
task_text = os.getenv('KMVAR_Inbox')
user_id = 'myUserName'
api_key = 'myPassword'
inbox_list_id = '154929'
auth_url = 'https://checkvist.com/auth/login.json'
connect_url = 'http://checkvist.com/checklists/' + inbox_list_id + '/import.xml'

# Get the temporary authorization token
token_data = urllib.urlencode({'username':user_id, 'remote_key':api_key})
req = urllib2.Request(auth_url, token_data)
fd = urllib2.urlopen(req)
auth_token = fd.read(1024)
auth_token = auth_token.replace('"', '').strip()

# Assemble the POST values to submit a new task
values = {'token': auth_token, 'import_content': task_text}
task_data = urllib.urlencode(values)
td = urllib2.urlopen(connect_url, task_data)

print td.read(1024)

I trigger the macro to get a short text input panel. If the post is successful then I get a Growl notification of success. If it fails, then I get an alert window.

All of these funnel silently into Checkvist which I use on my Mac through Fluid or Safari.2

Yeah, good API’s are nice.


  1. I have thousands of notes in a single Dropbox directory. This kills most Dropbox based note editors. Even very good editors like Notesy will occasionally crash while refreshing. ↩︎

  2. I have a Checkvist Pro account which lets me customize the interface. Looks nice, right? ↩︎