PHP code example of buzkall / laravel-ticktick

1. Go to this page and download the library: Download buzkall/laravel-ticktick library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buzkall / laravel-ticktick example snippets


Route::get('/ticktick/auth', function () {
    $pkce = TickTick::generatePkceChallenge();
    $state = Str::random(40);

    session([
        'ticktick_state'         => $state,
        'ticktick_code_verifier' => $pkce['code_verifier'],
    ]);

    return redirect(TickTick::getAuthorizationUrl(
        state: $state,
        codeChallenge: $pkce['code_challenge'],
    ));
});

Route::get('/ticktick/callback', function (Request $request) {
    abort_unless($request->get('state') === session('ticktick_state'), 403);

    $tokenData = TickTick::getAccessTokenFromPkceCode(
        $request->get('code'),
        session('ticktick_code_verifier'),
    );

    session(['ticktick_access_token' => $tokenData['access_token']]);

    return redirect('/dashboard');
});

use Arzcode\TickTick\Facades\TickTick;

Route::get('/ticktick/auth', function () {
    $state = Str::random(40);
    session(['ticktick_state' => $state]);

    return redirect(TickTick::getAuthorizationUrl(state: $state));
});

Route::get('/ticktick/callback', function (Request $request) {
    abort_unless($request->get('state') === session('ticktick_state'), 403);

    $tokenData = TickTick::getAccessTokenFromCode($request->get('code'));

    // Persist both tokens: the access token expires, the refresh token
    // is what lets you get a new one without sending the user through
    // the authorization flow again.
    session([
        'ticktick_access_token'  => $tokenData['access_token'],
        'ticktick_refresh_token' => $tokenData['refresh_token'] ?? null,
    ]);

    return redirect('/dashboard');
});

$tokenData = TickTick::refreshAccessToken(session('ticktick_refresh_token'));

session([
    'ticktick_access_token'  => $tokenData['access_token'],
    'ticktick_refresh_token' => $tokenData['refresh_token'] ?? session('ticktick_refresh_token'),
]);

use Arzcode\TickTick\Facades\TickTick;

// Set access token (if not already set in config)
TickTick::setAccessToken(session('ticktick_access_token'));

// Get all projects
$projects = TickTick::projects()->all();

// Each project has 'id' and 'name' properties
foreach ($projects as $project) {
    echo $project['name'] . ' (ID: ' . $project['id'] . ')';
}

$project = TickTick::projects()->get($projectId);

// This returns complete project data including all tasks
$data = TickTick::projects()->getData($projectId);
$tasks = $data['tasks'];

// Get all tasks for a specific project
$tasks = TickTick::tasks()->all($projectId);

// Get tasks due today (at any time)
$todayTasks = TickTick::tasks()->today($projectId);

// Get tasks due on a specific date
$tasks = TickTick::tasks()->byDueDate($projectId, '2025-01-15');

// TickTick stores due dates in UTC. Pass a timezone to decide which
// calendar day a task belongs to; it defaults to the app timezone.
$tasks = TickTick::tasks()->today($projectId, 'Europe/Madrid');
$tasks = TickTick::tasks()->byDueDate($projectId, '2025-01-15', 'Europe/Madrid');

// Note: TickTick API doesn't support server-side filtering by date.
// These methods fetch all tasks and filter client-side.

$task = TickTick::tasks()->create([
    'title' => 'New Task',
    'content' => 'Task description',
    'projectId' => $projectId, // Required
    'priority' => 1, // 0: None, 1: Low, 3: Medium, 5: High
    'dueDate' => '2025-12-31T23:59:59+0000',
]);

$task = TickTick::tasks()->get($taskId, $projectId);

$task = TickTick::tasks()->update($taskId, $projectId, [
    'title' => 'Updated Task Title',
    'status' => 0, // 0: Normal, 1: Completed
]);

TickTick::tasks()->delete($taskId, $projectId);

TickTick::tasks()->complete($taskId, $projectId);

// Full-text search, optionally narrowed
$tasks = TickTick::tasks()->search('quarterly report',
    projectIds: [$projectId],
    tags: ['work'],
    status: [TaskResource::STATUS_OPEN],
);

// Search by due date range only
$tasks = TickTick::tasks()->search(
    dueFrom: '2026-07-01T00:00:00+0000',
    dueTo: '2026-07-31T23:59:59+0000',
);

// Structured filter
$tasks = TickTick::tasks()->filter(
    projectIds: [$projectId],
    priority: [TaskResource::PRIORITY_MEDIUM, TaskResource::PRIORITY_HIGH],
    status: [TaskResource::STATUS_OPEN],
);

// Completed tasks in a range
$done = TickTick::tasks()->completed([$projectId],
    '2026-03-01T00:00:00+0000',
    '2026-03-09T23:59:59+0000',
);

TickTick::tasks()->moveTask($taskId, $fromProjectId, $toProjectId);

TickTick::tasks()->move([
    ['taskId' => $a, 'fromProjectId' => $p1, 'toProjectId' => $p2],
    ['taskId' => $b, 'fromProjectId' => $p1, 'toProjectId' => $p3],
]);

$comments = TickTick::tasks()->comments($taskId, $projectId);
TickTick::tasks()->addComment($taskId, $projectId, ['title' => 'Done']);
TickTick::tasks()->deleteComment($taskId, $projectId, $commentId);

$project = TickTick::projects()->create([
    'name'     => 'Work',
    'color'    => '#F18181',
    'viewMode' => 'kanban',   // list, kanban or timeline
    'kind'     => 'TASK',     // TASK or NOTE
]);

TickTick::projects()->update($projectId, ['name' => 'New name']);
TickTick::projects()->delete($projectId);

// Groups (sidebar folders)
TickTick::projectGroups()->all();
TickTick::projectGroups()->create(['name' => 'Work']);
TickTick::projectGroups()->update($groupId, ['name' => 'Personal']);
TickTick::projectGroups()->delete($groupId);

// Kanban columns
TickTick::columns()->all($projectId);
TickTick::columns()->create($projectId, ['name' => 'In progress']);
TickTick::columns()->update($projectId, $columnId, ['name' => 'Done']);

TickTick::tags()->all();
TickTick::tags()->create(['name' => 'urgent', 'label' => 'urgent']);

// Habits
TickTick::habits()->all();
TickTick::habits()->create(['name' => 'Drink water', 'goal' => 8, 'unit' => 'cups']);
TickTick::habits()->checkin($habitId, ['stamp' => 20260407, 'value' => 1, 'goal' => 8]);
TickTick::habits()->checkins([$habitId], 20260401, 20260430);

// Focus records (the API caps the range at 30 days)
TickTick::focus()->all('2026-04-01T00:00:00+0000', '2026-04-30T23:59:59+0000');
TickTick::focus()->get($focusId, FocusResource::TYPE_TIMING);
TickTick::focus()->delete($focusId, FocusResource::TYPE_POMODORO);

TickTick::countdowns()->all();

use Arzcode\TickTick\TickTick;

$ticktick = new TickTick([
    'access_token' => 'your_access_token',
    'base_url' => 'https://api.ticktick.com',
    'open_api_url' => 'https://api.ticktick.com/open/v1',
    'oauth_url' => 'https://ticktick.com',
    'timeout' => 30,
]);

$projects = $ticktick->projects()->all();

use Arzcode\TickTick\TickTick;

class TaskController extends Controller
{
    public function __construct(private TickTick $ticktick)
    {
    }

    public function index()
    {
        $projects = $this->ticktick->projects()->all();
        return view('tasks.index', compact('projects'));
    }
}

use Arzcode\TickTick\Exceptions\TickTickException;

try {
    $projects = TickTick::projects()->all();
} catch (TickTickException $e) {
    if ($e->getStatusCode() === 401) {
        // The access token expired, refresh it.
    }

    report($e->getResponseBody());
}
bash
php artisan vendor:publish --tag=ticktick-config