createTask() public method

For assign or remove the task to a project, use the addProjectToTask and removeProjectToTask.
public createTask ( array $data, array $opts = [] ) : string
$data array Array of data for the task following the Asana API documentation. Example: array( "workspace" => "1768", "name" => "Hello World!", "notes" => "This is a task for testing the Asana API :)", "assignee" => "176822166183", "followers" => array( "37136", "59083" ) )
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null
Ejemplo n.º 1
0
 # task notes
 $tasknotes = "Intern: " . $document->internal_party;
 $tasknotes .= "\n";
 $tasknotes .= "Kommentar: " . $document->comment;
 $tasknotes .= "\n\n";
 $tasknotes .= $filepath;
 # Asana implementation
 require_once dirname(__FILE__) . '/php-asana-api/asana.php';
 # API key, workspace and project
 $asana = new Asana(array('apiKey' => ASANA_APIKEY));
 # workspace 'xxx'
 $workspaceId = $document->asana_workspace_id;
 # project 'xxx'
 $projectId = $document->asana_project_id;
 # create the task
 $result = $asana->createTask(array('workspace' => $workspaceId, 'name' => $taskname, 'notes' => $tasknotes, 'assignee' => $asana_owner, 'followers' => $asana_follower));
 // success is 201
 if ($asana->responseCode != '201' || is_null($result)) {
     $asana_message = 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
     $asana_error = true;
 }
 if (!$asana_error) {
     $resultJson = json_decode($result);
     # get the task id
     $taskId = $resultJson->data->id;
     # add the task to the project
     $result = $asana->addProjectToTask($taskId, $projectId);
     if ($asana->responseCode != '200') {
         $asana_message = 'Error while assigning project to task: ' . $asana->responseCode;
         $asana_error = true;
     }
Ejemplo n.º 2
0
<?php

require_once '../asana.php';
// See class comments and Asana API for full info
$asana = new Asana(array('apiKey' => 'XXXXXXXXXXXXXXXXXXX'));
// Your API Key, you can get it in Asana
$workspaceId = 'XXXXXXXXXXXXXXXXXXX';
// The workspace where we want to create our task, take a look at getWorkspaces() method.
// First we create the task
$result = $asana->createTask(array('workspace' => $workspaceId, 'name' => 'Hello World!', 'assignee' => '*****@*****.**'));
// As Asana API documentation says, when a task is created, 201 response code is sent back so...
if ($asana->responseCode != '201' || is_null($result)) {
    echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
    return;
}
$resultJson = json_decode($result);
$taskId = $resultJson->data->id;
// Here we have the id of the task that have been created
Ejemplo n.º 3
0
 /**
  * Function retrieves upcoming IPOs by scraping data from asx pages
  * It then compares existing records against the new records and updates the DB accordingly
  */
 private function update()
 {
     /** @var Model[] $companyData */
     $modelArray = $this->scrapeData();
     $persister = new \Persister\Company($this->db);
     // fetch all existing records out of the db - Normally I would keep this in memcache or similar
     // but memcached does not want to work on this windows environ and im not going to burn any more time
     // trying to make it comply
     $existingData = $persister->getAll();
     // for each of the models
     foreach ($modelArray as $model) {
         // if the record does not exist in the old data add it
         if (!array_key_exists($model->proposedCode, $existingData)) {
             $persister->save($model);
             // OK we have a new record. throw  a task at Asana
             if (!isset($asana)) {
                 $asana = new \Asana(array('accessToken' => ASANA_TOKEN));
             }
             $asana->createTask(array('workspace' => ASANA_WORKSPACE, 'assignee' => ASANA_ASIGNEE, 'projects' => array(ASANA_PROJECT_ID), 'name' => $model->company . " ({$model->proposedCode})", 'notes' => $model->contact));
         } else {
             $oldModel = $existingData[$model->proposedCode];
             // shove comment from old model into scraped data - yeah this is a hack, but im past looking for elegant solutions
             $model->comment = $oldModel->comment;
             if ($model->hash() === $oldModel->hash()) {
                 // no change required just unset from existing records
                 unset($existingData[$model->proposedCode]);
             } else {
                 // model needs updating cos data has changed
                 $persister->update($model);
                 unset($existingData[$model->proposedCode]);
             }
         }
         $retArray[] = $model->toArray();
     }
     // anything left in existing records? nuke them because they are no longer valid
     foreach ($existingData as $oldData) {
         $persister->delete($oldData->proposedCode);
     }
     echo json_encode($retArray);
 }