addProjectToTask() public method

Adds a project to task. If successful, will return success and an empty data block.
public addProjectToTask ( string $taskId, string $projectId, array $opts = [] ) : string
$taskId string
$projectId string
$opts array Array of options to pass (insert_after, insert_before, section) (@see https://asana.com/developers/api-reference/tasks#projects)
return string JSON or null
/*
 * This file is part of the Showpad PHP API connection class from Jeroen Desloovere.
 *
 * For the full copyright and license information, please view the license
 * file that was distributed with this source code.
 */
// required to load
require_once __DIR__ . '/../vendor/autoload.php';
require_once __DIR__ . '/credentials.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
$projectId = 'XXXXXXXXXXXXXXXXXXX';
// The project where we want to save our task
// First we create the task
$result = $asana->createTask(array('workspace' => $workspaceId, 'name' => 'Hello World!', 'assignee' => '*****@*****.**', 'followers' => array('XXXXX', 'XXXXXXXX')));
// 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
// Now we do another request to add the task to a project
$result = $asana->addProjectToTask($taskId, $projectId);
if ($asana->responseCode != '200') {
    echo 'Error while assigning project to task: ' . $asana->responseCode;
}