PHP code example of cpnporg / todoist-php

1. Go to this page and download the library: Download cpnporg/todoist-php 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/ */

    

cpnporg / todoist-php example snippets


$todoist = new Todoist\Todoist($token);
$tasks = $todoist->getTasks();
$projects = $todoist->getProjects();

foreach ($todoist->getTasks()->filterByProject('Project Name') as $task) {
  // $task is now an array derived from Todoist JSON.
}

// Filter tasks by project name or ID.
$tasks = $tasks->filterByProject('Project Name');
$tasks = $tasks->filterByProject($project_id);

// Filter tasks by regular expression.
$tasks = $tasks->filterByContentPreg('/regex for task content/');

// Manipulate task content by prepending or appending parent task content.
$tasks = $tasks->applyParentTasks(array(
  // 'prepend' or 'append' parent content
  // default: prepend
  'apply' => 'prepend',
  
  // Strip content 'pre', 'post' or other from parent task with a colon before adding it.
  // default: '' (do not strip colon content from parent)
  'strip_colon' => 'post',
  
  // Configure the delimiter to use between task and parent task content.
  // default: ': '
  'delimiter' => ': ',

  // Only apply the parent to short tasks (NULL = apply to all)
  // default: NULL
  'strlen_max' => 5,
));

$source_todoist = Todoist::factory($source_token);
$source_projects = $source_todoist->getProjects();

try {
  $todoist = Todoist::factory($token);
  $todoist->useCommandQueue(TRUE);
  $projects = &$todoist->getProjects();
  $projects->syncOrderIndent($source_projects, 'top');
  $todoist->flushCommandQueue();
} catch (\Exception $e) {
  echo "Error: " . $e->getMessage() . "\n";
}