-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #68 from nickbreslin/master
createSection() method and example
- Loading branch information
Showing
2 changed files
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
require_once('../asana.php'); | ||
|
||
// See class comments and Asana API for full info | ||
$asana = new Asana(array('personalAccessToken' => 'xxxxxxxxxxxxxxxxxxxxx')); // Create a personal access token in Asana or use OAuth | ||
|
||
$workspaceId = 'XXXXXXXXXXXXXXXXXXX'; // The workspace where we want to create our task, take a look at getWorkspaces() method. | ||
$projectId = 'XXXXXXXXXXXXXXXXXXX'; // the project id where we want to add our section, take a look at getProjects() method. | ||
|
||
// A section is a subdivision of a project that groups tasks together. | ||
// It is also just a task with a name that ends with a colon. | ||
// These are two ways to create a section, shown below. | ||
// | ||
// More about sections: https://asana.com/developers/api-reference/sections | ||
|
||
// | ||
// One method to create a section is to create a task with specific properties. | ||
// We've added a colon to the end of the task name and added a project to it's membership properties. | ||
$asana->createTask(array( | ||
'workspace' => $workspaceId, // Workspace ID | ||
'name' => 'Section created by createTask:', // Name of task | ||
'assignee' => '[email protected]', // Assign task to... | ||
"memberships" => [ | ||
[ | ||
"project" => $projectId | ||
] | ||
] | ||
)); | ||
|
||
/* | ||
// Alternatively, we can use the createSection() method. | ||
// We identify the project as the first parameter and the data for the section in an array for the second parameter. | ||
// | ||
// Note: The section name does not need to include a colon, Asana will add this when the section is created. | ||
$asana->createSection($projectId, array( | ||
'workspace' => $workspaceId, // Workspace ID | ||
'name' => 'Section created by createSection', // Name of section | ||
'assignee' => '[email protected]' // Assign task to... | ||
)); | ||
*/ | ||
|
||
|
||
// As Asana API documentation says, when a task is created, 201 response code is sent back so... | ||
if ($asana->hasError()) { | ||
echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode; | ||
return; | ||
} | ||
|
||
$result = $asana->getData(); | ||
|
||
if (isset($result->id)) { | ||
echo $result->id; // Here we have the id of the task/section that have been created | ||
} |