Client API Reference¶
Dida365Client¶
The main client class for interacting with the Dida365/TickTick API.
Constructor¶
def __init__(
client_id: Optional[str] = None,
client_secret: Optional[str] = None,
service_type: ServiceType = ServiceType.DIDA365,
redirect_uri: str = "http://localhost:8080/callback",
save_to_env: bool = True
)
Creates a new Dida365Client instance.
Parameter | Type | Description | Default |
---|---|---|---|
client_id |
Optional[str] |
OAuth2 client ID. Can be set via DIDA365_CLIENT_ID env var |
None |
client_secret |
Optional[str] |
OAuth2 client secret. Can be set via DIDA365_CLIENT_SECRET env var |
None |
service_type |
ServiceType |
Service type (DIDA365 or TICKTICK ) |
ServiceType.DIDA365 |
redirect_uri |
str |
OAuth2 redirect URI | "http://localhost:8080/callback" |
save_to_env |
bool |
Whether to save credentials and token to .env file |
True |
Authentication Methods¶
authenticate()¶
async def authenticate(
scope: str = "tasks:write tasks:read",
state: str = "state",
port: int = 8080
) -> TokenInfo
Complete OAuth2 authentication flow. Opens browser for user authorization.
Parameter | Type | Description | Default |
---|---|---|---|
scope |
str |
OAuth2 scopes to request | "tasks:write tasks:read" |
state |
str |
State parameter for OAuth2 flow | "state" |
port |
int |
Port for local callback server | 8080 |
Returns: TokenInfo
- Token information including access token and expiry
exchange_code()¶
Exchange authorization code for access token.
Parameter | Type | Description |
---|---|---|
code |
str |
Authorization code from OAuth2 callback |
Returns: TokenInfo
- Token information including access token and expiry
Project Methods¶
get_projects()¶
Get all projects.
Returns: List[Project]
- List of projects
get_project()¶
Get a project by ID.
Parameter | Type | Description |
---|---|---|
project_id |
str |
Project identifier |
Returns: Project
- Project details
get_project_with_data()¶
Get a project with its tasks and columns.
Parameter | Type | Description |
---|---|---|
project_id |
str |
Project identifier |
Returns: ProjectData
- Project details including tasks and columns
create_project()¶
Create a new project.
Parameter | Type | Description |
---|---|---|
project |
ProjectCreate |
Project creation model |
Returns: Project
- Created project
update_project()¶
Update an existing project.
Parameter | Type | Description |
---|---|---|
project |
ProjectUpdate |
Project update model |
Returns: Project
- Updated project
delete_project()¶
Delete a project.
Parameter | Type | Description |
---|---|---|
project_id |
str |
Project identifier |
Task Methods¶
get_task()¶
Get a task by project ID and task ID.
Parameter | Type | Description |
---|---|---|
project_id |
str |
Project identifier |
task_id |
str |
Task identifier |
Returns: Task
- Task details
create_task()¶
Create a new task.
Parameter | Type | Description |
---|---|---|
task |
TaskCreate |
Task creation model |
Returns: Task
- Created task
update_task()¶
Update an existing task.
Parameter | Type | Description |
---|---|---|
task |
TaskUpdate |
Task update model |
Returns: Task
- Updated task
complete_task()¶
Mark a task as completed.
Parameter | Type | Description |
---|---|---|
project_id |
str |
Project identifier |
task_id |
str |
Task identifier |
delete_task()¶
Delete a task.
Parameter | Type | Description |
---|---|---|
project_id |
str |
Project identifier |
task_id |
str |
Task identifier |
Error Handling¶
All methods can raise the following exceptions:
AuthenticationError
: When authentication fails or token is invalidNotFoundError
: When requested resource is not foundValidationError
: When request data is invalidRateLimitError
: When API rate limit is exceededApiError
: For other API errors