Authorization
The Todoist API uses OAuth2 for authentication. This guide provides a quick overview of the authentication flow using our TypeScript client.
Quick Start
import {
getAuthStateParameter,
getAuthorizationUrl,
getAuthToken,
} from '@doist/todoist-api-typescript'
// 1. Generate state parameter and store it
const state = getAuthStateParameter()
// 2. Get authorization URL
const url = getAuthorizationUrl('YOUR_CLIENT_ID', ['data:read', 'task:add'], state)
// 3. Redirect user to the authorization URL
// 4. Handle OAuth callback and get code
// 5. Exchange code for token
const { accessToken } = await getAuthToken({
clientId: 'YOUR_CLIENT_ID',
clientSecret: 'YOUR_CLIENT_SECRET',
code: 'CODE_FROM_CALLBACK',
})
Using the Access Token
import { TodoistApi } from '@doist/todoist-api-typescript'
// Initialize API with access token
const api = new TodoistApi(accessToken)
// Use API methods
const task = await api.addTask({
content: 'Buy groceries',
dueString: 'tomorrow at 12:00',
priority: 4,
})
Available Functions
getAuthStateParameter()- Creates secure state parametergetAuthorizationUrl()- Generates OAuth2 authorization URLgetAuthToken()- Exchanges code for access tokenrevokeAuthToken()- Revokes an access token
Available Scopes
task:add- Only create new tasksdata:read- Read-only accessdata:read_write- Read and write accessdata:delete- Full access including deleteproject:delete- Can delete projectsbackups:read- Can read the user's list of backups without MFA
📖 For detailed implementation steps and security considerations, consult the Todoist API v1 Authorization Guide.