Skip to content

Instantly share code, notes, and snippets.

@deepakjois
Last active September 9, 2026 12:37
Show Gist options
  • Select an option

  • Save deepakjois/c3a3298f2a58c95f2c36cfcbf40b2ad5 to your computer and use it in GitHub Desktop.

Select an option

Save deepakjois/c3a3298f2a58c95f2c36cfcbf40b2ad5 to your computer and use it in GitHub Desktop.
Add a Todoist task due today (token via TODOIST_API_TOKEN env var)

add-todoist-task

Small shell script that adds a task to Todoist (due today by default) via the Todoist REST API v1.

Usage

TODOIST_API_TOKEN=<your-token> ./add_todoist_task.sh "Buy milk"
TODOIST_API_TOKEN=<your-token> ./add_todoist_task.sh "Call accountant" "tomorrow"
#!/usr/bin/env bash
# add_todoist_task.sh - Add a task to Todoist due today.
#
# Usage:
# TODOIST_API_TOKEN=<token> ./add_todoist_task.sh "Buy milk"
# TODOIST_API_TOKEN=<token> ./add_todoist_task.sh "Call accountant" "tomorrow"
#
# The token is read from the TODOIST_API_TOKEN environment variable.
# Never hard-code the token in this file or commit it anywhere.
# Get a token at https://todoist.com/app/settings/integrations/developer
set -euo pipefail
TASK_TEXT="${1:?usage: $0 <task text> [due string, default: today]}"
DUE_STRING="${2:-today}"
if [[ -z "${TODOIST_API_TOKEN:-}" ]]; then
echo "error: TODOIST_API_TOKEN environment variable is not set" >&2
exit 1
fi
curl -fsS -X POST "https://api.todoist.com/api/v1/tasks" \
-H "Authorization: Bearer ${TODOIST_API_TOKEN}" \
-H "Content-Type: application/json" \
-H "X-Request-Id: $(cat /proc/sys/kernel/random/uuid 2>/dev/null || uuidgen)" \
-d "$(jq -cn --arg content "$TASK_TEXT" --arg due "$DUE_STRING" \
'{content: $content, due_string: $due}')"
echo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment