Building a Todoist Data Exporter with AI: A Practical Case Study?
In this post, I’ll walk you through a recent project where I collaborated with an AI assistant to build a Todoist data exporter. The goal was to pull all active and completed tasks from Todoist, export them as CSV files, and make them accessible for data analysis. This project highlights how AI can help streamline development, troubleshoot API challenges, and navigate complex documentation.
Background
Todoist is a popular task management tool with a robust API. However, exporting all data, especially completed tasks, requires a blend of Todoist’s REST and Sync APIs. This project began with a straightforward goal: create a Python script to export Todoist tasks, projects, labels, and comments to CSV files.
Initial Steps and Challenges
With the AI’s guidance, I set up a basic Python script using the todoist-api-python
library, which initially worked well for retrieving active tasks through the REST API. However, I soon encountered a challenge: the REST API doesn’t provide direct access to completed tasks. To retrieve those, I’d need to use the Sync API—a different API version with a unique endpoint for completed tasks.
Project Structure
The AI helped structure the project by organizing methods to export various data types (e.g., projects, labels, tasks). Here’s a look at the final layout:
todoist-data-exporter/
│
├── src/
│ ├── exporter.py # Main script
│ └── config.json # API token configuration
│
├── data/ # Output directory for CSVs
│
├── tests/
│ └── test_exporter.py # Unit tests
│
└── README.md # Project documentation
Integrating the Sync API for Completed Tasks
To export completed tasks, I adapted the export_tasks
method to combine two data sources: the REST API (for active tasks) and the Sync API (for completed tasks). This required pagination to handle larger datasets, as the Sync API returns completed tasks in batches.
Here’s the code snippet used to fetch completed tasks from the Sync API:
import requests
completed_task_data = []
url = "https://api.todoist.com/sync/v9/completed/get_all"
headers = {"Authorization": f"Bearer {self.api.token}"}
params = {"limit": 200, "offset": 0}
while True:
response = requests.get(url, headers=headers, params=params)
response.raise_for_status()
data = response.json()
items = data.get("items", [])
completed_task_data.extend(items)
if len(items) < 200:
break
params["offset"] += 200
This loop iterates through each batch of completed tasks, appending them to completed_task_data
until no more tasks are left.
Testing and Troubleshooting
The AI also helped me troubleshoot common API issues, like 401 Unauthorized errors, ensuring my API token was correctly authenticated in config.json
. Once the data export functioned smoothly, I could generate a tasks.csv
file containing all active and completed tasks with a single command:
python src/exporter.py --tasks
Final Thoughts
This project illustrated how AI can serve as an effective coding partner. From interpreting API documentation to writing code snippets and debugging errors, working with an AI assistant was akin to pairing with a highly knowledgeable developer.
If you’re interested in using AI for similar tasks, remember that AI can assist with everything from generating boilerplate code to designing patterns and integrating APIs. It’s a powerful tool to boost productivity and tackle technical challenges efficiently.