PHP Class Asana

Read Asana API documentation for fully use this class http://developer.asana.com/documentation/ Copyright 2012 Ajimix Licensed under the Apache License 2.0 Author: Ajimix [github.com/ajimix] Version: 1.0
Mostra file Open project: ajimix/asana-api-php-class Class Usage Examples

Public Properties

Property Type Description
$advDebug
$debug
$fastAPI
$responseCode
$timeout Use Asana fast API version, currently in open beta: https://asana.com/developers/feed/asana-fast-api-open-beta

Public Methods

Method Description
__construct ( array $options ) Class constructor.
addAttachmentToTask ( string $taskId, array $data = [] ) : string Add attachment to a task
addFollowersToTask ( string $taskId, array $followerIds ) : string Adds followers to a task
addProjectToTask ( string $taskId, string $projectId, array $opts = [] ) : string Adds a project to task. If successful, will return success and an empty data block.
addTagToTask ( string $taskId, string $tagId ) : string Adds a tag to a task. If successful, will return success and an empty data block.
commentOnProject ( string $projectId, string $text = '' ) : string Adds a comment to a project The comment will be authored by the authorized user, and timestamped when the server receives the request.
commentOnTask ( string $taskId, string $text = '' ) : string Adds a comment to a task.
createProject ( array $data ) : string Function to create a project.
createSubTask ( string $parentId, array $data, array $opts = [] ) : string Creates a subtask in the parent task ID
createTag ( string $name, array $data, array $opts = [] ) : string This method creates a new tag and returns its full record.
createTask ( array $data, array $opts = [] ) : string Creates a task.
createTeam ( string $organizationId, array $data ) : string Function to create a team in an Organization.
createWebhook ( string $resourceId, string $target ) : string Creates a webhook.
deleteProject ( string $projectId ) : string Deletes a project.
deleteTask ( string $taskId ) : string Deletes a task.
deleteWebhook ( string $webhookId ) : string This method permanently removes a webhook.
getAttachment ( string $attachmentId, array $opts = [] ) : string Returns single attachment information
getData ( ) : object, Decodes the response and returns as an object, array.
getMyTeams ( string $organizationId ) : string Returns all teams the logged in user is associated with
getProject ( string $projectId, array $opts = [] ) : string Returns the full record for a single project.
getProjectSections ( string $projectId, array $opts = [] ) : string Returns the list of sections associated with the project.
getProjectStories ( string $projectId, array $opts = [] ) : string Returns the list of stories associated with the project.
getProjectTasks ( string $projectId, array $opts = [] ) : string Returns all unarchived tasks of a given project
getProjects ( boolean $archived = false, string $opt_fields = '' ) Returns the projects in all workspaces containing archived ones or not.
getProjectsForTask ( string $taskId, array $opts = [] ) : string Returns the projects associated to the task.
getProjectsInTeam ( string $teamId, boolean $archived = false, array $opts = [] ) : string Returns the projects in provided workspace containing archived ones or not.
getProjectsInWorkspace ( string $workspaceId, boolean $archived = false, array $opts = [] ) : string Returns the projects in provided workspace containing archived ones or not.
getSingleStory ( string $storyId, array $opts = [] ) : string Returns the full record for a single story.
getSubTasks ( string $taskId, array $opts = [] ) : string Returns sub-task information
getTag ( string $tagId, array $opts = [] ) : string Returns the full record for a single tag.
getTags ( ) : string Returns the full record for all tags in all workspaces.
getTask ( string $taskId, array $opts = [] ) : string Returns task information
getTaskAttachments ( string $taskId, array $opts = [] ) : string Returns task attachments information
getTaskStories ( string $taskId, array $opts = [] ) : string Returns the list of stories associated with the object.
getTaskTags ( string $taskId, array $opts = [] ) : string Returns a compact list of tags associated with the object.
getTasksByFilter ( array $filter = ['assignee' => '', 'project' => '', 'workspace' => ''], array $opts = [] ) : string Returns task by a given filter.
getTasksWithTag ( string $tagId, array $opts = [] ) : string Returns the list of all tasks with this tag. Tasks can have more than one tag at a time.
getTeamsInOrganization ( string $organizationId ) : string Returns all teams in an Organization.
getUserInfo ( string $userId = null, array $opts = [] ) : string Returns the full user record for a single user.
getUsers ( array $opts = [] ) : string Returns the user records for all users in all workspaces you have access.
getWebhook ( string $webhookId ) : string Returns the full record for the given webhook.
getWebhooks ( string $workspaceId, string $resource = null, array $opts = [] ) : string Returns the compact representation of all webhooks your app has registered for the authenticated user in the given workspace.
getWorkspaceTags ( string $workspaceId ) : string Returns tags of all workspace.
getWorkspaceTasks ( string $workspaceId, string $assignee = 'me', array $opts = [] ) : string Returns tasks of all workspace assigned to someone.
getWorkspaceTypeahead ( string $workspaceId, string $type, string $query, string $count = 1, array $opts = [] ) : string Returns search for objects from a single workspace.
getWorkspaceUsers ( string $workspaceId ) : string Returns users of all workspace.
getWorkspaces ( array $opts = [] ) : string Returns all the workspaces.
hasError ( ) : boolean Checks for errors in the response.
moveTaskWithinProject ( string $projectId, string $taskToMove, string $taskReference, boolean $insertAfter = true ) : string Moves a task within a project relative to another task. This should let you take a task and move it below or above another task as long as they are within the same project.
removeFollowersFromTask ( string $taskId, array $followerIds ) : string Removes followers from a task
removeProjectToTask ( string $taskId, string $projectId ) : string Removes project from task. If successful, will return success and an empty data block.
removeTagFromTask ( string $taskId, string $tagId ) : string Removes a tag from a task. If successful, will return success and an empty data block.
setReturnType ( integer $type ) : Asana Set the return type.
updateProject ( string $projectId, array $data ) : string This method modifies the fields of a project provided in the request, then returns the full updated record.
updateTag ( string $tagId, array $data ) : string Modifies the fields of a tag provided in the request, then returns the full updated record.
updateTask ( string $taskId, array $data ) : string Updates a task
updateTaskParent ( string $taskId, string $parentId, array $opts = [] ) : string Updated the parent from a task.
updateWorkspace ( $workspaceId, array $data = ['name' => ''] ) : string Currently the only field that can be modified for a workspace is its name (as Asana API says).

Private Methods

Method Description
askAsana ( string $url, string $data = null, integer $method = ASANA_METHOD_GET ) : string This function communicates with Asana REST API.

Method Details

__construct() public method

Class constructor.
public __construct ( array $options )
$options array Array of options containing an apiKey OR a personalAccessToken OR an accessToken. Just one of them. Can be also an string if you want to use an apiKey.

addAttachmentToTask() public method

Add attachment to a task
public addAttachmentToTask ( string $taskId, array $data = [] ) : string
$taskId string
$data array (src of file, mymetype, finalFilename) See, Uploading an attachment to a task function comments for proper parameter info.
return string JSON or null

addFollowersToTask() public method

Adds followers to a task
public addFollowersToTask ( string $taskId, array $followerIds ) : string
$taskId string
$followerIds array Array of follower ids
return string JSON or null

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

addTagToTask() public method

Adds a tag to a task. If successful, will return success and an empty data block.
public addTagToTask ( string $taskId, string $tagId ) : string
$taskId string
$tagId string
return string JSON or null

commentOnProject() public method

Adds a comment to a project The comment will be authored by the authorized user, and timestamped when the server receives the request.
public commentOnProject ( string $projectId, string $text = '' ) : string
$projectId string
$text string
return string JSON or null

commentOnTask() public method

The comment will be authored by the authorized user, and timestamped when the server receives the request.
public commentOnTask ( string $taskId, string $text = '' ) : string
$taskId string
$text string
return string JSON or null

createProject() public method

Function to create a project.
public createProject ( array $data ) : string
$data array Array of data for the project following the Asana API documentation. Example: array( "workspace" => "1768", "name" => "Foo Project!", "notes" => "This is a test project" )
return string JSON or null

createSubTask() public method

Creates a subtask in the parent task ID
public createSubTask ( string $parentId, array $data, array $opts = [] ) : string
$parentId string The id of the parent task.
$data array Array of data for the task following the Asana API documentation. Example: array( "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

createTag() public method

This method creates a new tag and returns its full record.
public createTag ( string $name, array $data, array $opts = [] ) : string
$name string Tag name
$data array An array containing either workspace or organization and the id. Example: array("workspace" => "3242349871");
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

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

createTeam() public method

Function to create a team in an Organization.
public createTeam ( string $organizationId, array $data ) : string
$organizationId string
$data array Array of data for the task following the Asana API documentation. Example: array("name" => "Team Name")
return string JSON or null

createWebhook() public method

Creates a webhook.
public createWebhook ( string $resourceId, string $target ) : string
$resourceId string A resource ID to subscribe to. The resource can be a task or project.
$target string The URL to receive the HTTP POST.
return string JSON or null

deleteProject() public method

Deletes a project.
public deleteProject ( string $projectId ) : string
$projectId string
return string Empty if success

deleteTask() public method

Deletes a task.
public deleteTask ( string $taskId ) : string
$taskId string
return string Empty if success

deleteWebhook() public method

This method permanently removes a webhook.
public deleteWebhook ( string $webhookId ) : string
$webhookId string The webhook to delete.
return string JSON or null

getAttachment() public method

Returns single attachment information
public getAttachment ( string $attachmentId, array $opts = [] ) : string
$attachmentId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getData() public method

Decodes the response and returns as an object, array.
public getData ( ) : object,
return object,

getMyTeams() public method

Returns all teams the logged in user is associated with
public getMyTeams ( string $organizationId ) : string
$organizationId string
return string JSON or null

getProject() public method

Returns the full record for a single project.
public getProject ( string $projectId, array $opts = [] ) : string
$projectId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getProjectSections() public method

Sections are tasks whose names end with a colon character : . For instance sections will be included in query results for tasks and be represented with the same fields. The memberships property of a task contains the project/section pairs a task belongs to when applicable.
public getProjectSections ( string $projectId, array $opts = [] ) : string
$projectId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getProjectStories() public method

As usual with queries, stories are returned in compact form. However, the compact form for stories contains more information by default than just the ID. There is presently no way to get a filtered set of stories.
public getProjectStories ( string $projectId, array $opts = [] ) : string
$projectId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getProjectTasks() public method

Returns all unarchived tasks of a given project
public getProjectTasks ( string $projectId, array $opts = [] ) : string
$projectId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getProjects() public method

Returns the projects in all workspaces containing archived ones or not.
public getProjects ( boolean $archived = false, string $opt_fields = '' )
$archived boolean Return archived projects or not
$opt_fields string Return results with optional parameters

getProjectsForTask() public method

Returns the projects associated to the task.
public getProjectsForTask ( string $taskId, array $opts = [] ) : string
$taskId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getProjectsInTeam() public method

Returns the projects in provided workspace containing archived ones or not.
public getProjectsInTeam ( string $teamId, boolean $archived = false, array $opts = [] ) : string
$teamId string
$archived boolean Return archived projects or not
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getProjectsInWorkspace() public method

Returns the projects in provided workspace containing archived ones or not.
public getProjectsInWorkspace ( string $workspaceId, boolean $archived = false, array $opts = [] ) : string
$workspaceId string
$archived boolean Return archived projects or not
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getSingleStory() public method

Returns the full record for a single story.
public getSingleStory ( string $storyId, array $opts = [] ) : string
$storyId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getSubTasks() public method

Returns sub-task information
public getSubTasks ( string $taskId, array $opts = [] ) : string
$taskId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getTag() public method

Returns the full record for a single tag.
public getTag ( string $tagId, array $opts = [] ) : string
$tagId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getTags() public method

Returns the full record for all tags in all workspaces.
public getTags ( ) : string
return string JSON or null

getTask() public method

Returns task information
public getTask ( string $taskId, array $opts = [] ) : string
$taskId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getTaskAttachments() public method

Returns task attachments information
public getTaskAttachments ( string $taskId, array $opts = [] ) : string
$taskId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getTaskStories() public method

As usual with queries, stories are returned in compact form. However, the compact form for stories contains more information by default than just the ID. There is presently no way to get a filtered set of stories.
public getTaskStories ( string $taskId, array $opts = [] ) : string
$taskId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getTaskTags() public method

Returns a compact list of tags associated with the object.
public getTaskTags ( string $taskId, array $opts = [] ) : string
$taskId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getTasksByFilter() public method

For now (limited by Asana API), you may limit your query either to a specific project or to an assignee and workspace NOTE: As Asana API says, if you filter by assignee, you MUST specify a workspaceId and viceversa.
public getTasksByFilter ( array $filter = ['assignee' => '', 'project' => '', 'workspace' => ''], array $opts = [] ) : string
$filter array The filter with optional values. array( "assignee" => "", "project" => 0, "workspace" => 0 )
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getTasksWithTag() public method

Returns the list of all tasks with this tag. Tasks can have more than one tag at a time.
public getTasksWithTag ( string $tagId, array $opts = [] ) : string
$tagId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getTeamsInOrganization() public method

Returns all teams in an Organization.
public getTeamsInOrganization ( string $organizationId ) : string
$organizationId string
return string JSON or null

getUserInfo() public method

Call it without parameters to get the users info of the owner of the API key.
public getUserInfo ( string $userId = null, array $opts = [] ) : string
$userId string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getUsers() public method

Returns the user records for all users in all workspaces you have access.
public getUsers ( array $opts = [] ) : string
$opts array Array of options to pass to the API (@see https://asana.com/developers/api-reference/users) Example: Returning additional fields with 'opt_fields' getUsers(['opt_fields' => 'name,email,photo,workspaces'])
return string JSON or null

getWebhook() public method

Returns the full record for the given webhook.
public getWebhook ( string $webhookId ) : string
$webhookId string The webhook to get.
return string JSON or null

getWebhooks() public method

Returns the compact representation of all webhooks your app has registered for the authenticated user in the given workspace.
public getWebhooks ( string $workspaceId, string $resource = null, array $opts = [] ) : string
$workspaceId string The workspace to query for webhooks in.
$resource string Optional: Only return webhooks for the given resource.
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getWorkspaceTags() public method

Returns tags of all workspace.
public getWorkspaceTags ( string $workspaceId ) : string
$workspaceId string The id of the workspace
return string JSON or null

getWorkspaceTasks() public method

Note: As Asana API says, you must specify an assignee when querying for workspace tasks.
public getWorkspaceTasks ( string $workspaceId, string $assignee = 'me', array $opts = [] ) : string
$workspaceId string The id of the workspace
$assignee string Can be "me" or user ID
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getWorkspaceTypeahead() public method

Returns search for objects from a single workspace.
public getWorkspaceTypeahead ( string $workspaceId, string $type, string $query, string $count = 1, array $opts = [] ) : string
$workspaceId string The id of the workspace
$type string The type of object to look up. You can choose from one of the following: project, user, task, and tag. Note that unlike other endpoints, the types listed here are in singular form. Using multiple types is not yet supported.
$query string The value to look up
$count string The number of results to return with a minimum of 1 and a maximum of 100. The default is 1 if this parameter is omitted. If there are fewer results found than requested, all will be returned
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

getWorkspaceUsers() public method

Returns users of all workspace.
public getWorkspaceUsers ( string $workspaceId ) : string
$workspaceId string The id of the workspace
return string JSON or null

getWorkspaces() public method

Returns all the workspaces.
public getWorkspaces ( array $opts = [] ) : string
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

hasError() public method

Checks for errors in the response.
public hasError ( ) : boolean
return boolean

moveTaskWithinProject() public method

Moves a task within a project relative to another task. This should let you take a task and move it below or above another task as long as they are within the same project.
public moveTaskWithinProject ( string $projectId, string $taskToMove, string $taskReference, boolean $insertAfter = true ) : string
$projectId string the project $taskReference is in and optionally $taskToMove is already in ($taskToMove will be added to the project if it's not already there)
$taskToMove string the task that will be moved (and possibly added to $projectId
$taskReference string the task that indicates a position for $taskToMove
$insertAfter boolean true to insert after $taskReference, false to insert before
return string JSON or null

removeFollowersFromTask() public method

Removes followers from a task
public removeFollowersFromTask ( string $taskId, array $followerIds ) : string
$taskId string
$followerIds array Array of follower ids
return string JSON or null

removeProjectToTask() public method

Removes project from task. If successful, will return success and an empty data block.
public removeProjectToTask ( string $taskId, string $projectId ) : string
$taskId string
$projectId string
return string JSON or null

removeTagFromTask() public method

Removes a tag from a task. If successful, will return success and an empty data block.
public removeTagFromTask ( string $taskId, string $tagId ) : string
$taskId string
$tagId string
return string JSON or null

setReturnType() public method

Set the return type.
public setReturnType ( integer $type ) : Asana
$type integer Return type defined in the constants.
return Asana

updateProject() public method

This method modifies the fields of a project provided in the request, then returns the full updated record.
public updateProject ( string $projectId, array $data ) : string
$projectId string
$data array An array containing fields to update, see Asana API if needed. Example: array("name" => "Test", "notes" => "It's a test project");
return string JSON or null

updateTag() public method

Modifies the fields of a tag provided in the request, then returns the full updated record.
public updateTag ( string $tagId, array $data ) : string
$tagId string
$data array An array containing fields to update, see Asana API if needed. Example: array("name" => "Test", "notes" => "It's a test tag");
return string JSON or null

updateTask() public method

Updates a task
public updateTask ( string $taskId, array $data ) : string
$taskId string
$data array See, createTask function comments for proper parameter info.
return string JSON or null

updateTaskParent() public method

Updated the parent from a task.
public updateTaskParent ( string $taskId, string $parentId, array $opts = [] ) : string
$taskId string The task to update
$parentId string The id of the new parent task.
$opts array Array of options to pass (@see https://asana.com/developers/documentation/getting-started/input-output-options)
return string JSON or null

updateWorkspace() public method

This method returns the complete updated workspace record.
public updateWorkspace ( $workspaceId, array $data = ['name' => ''] ) : string
$data array Example: array("name" => "Test");
return string JSON or null

Property Details

$advDebug public_oe property

public $advDebug

$debug public_oe property

public $debug

$fastAPI public_oe property

public $fastAPI

$responseCode public_oe property

public $responseCode

$timeout public_oe property

Use Asana fast API version, currently in open beta: https://asana.com/developers/feed/asana-fast-api-open-beta
public $timeout