Asana::createTask PHP Method

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
    public function createTask($data, array $opts = array())
    {
        $data = array('data' => $data);
        $data = json_encode($data);
        $options = http_build_query($opts);
        return $this->askAsana($this->taskUrl . '?' . $options, $data, ASANA_METHOD_POST);
    }

Usage Example

 # 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;
     }
All Usage Examples Of Asana::createTask