Coder Social home page Coder Social logo

asana-api-php-class's Introduction

Asana API PHP class

A dependency free, lightweight PHP class that acts as wrapper for Asana API.
Lets make things fast and easy! :)

Installing

Choose your favourite flavour

  • Download the php class from Github.
  • Or use Packagist PHP package manager.

Finally require the asana.php file.

Working with the class

First declare the asana class

$asana = new Asana([
    'personalAccessToken' => 'GET_IT_FROM_ASANA'
]);

Optionally you can pass an accessToken instead of a personalAccessToken if you use OAuth. Read Using Asana Oauth Tokens below for more info.

Creating a task

$asana->createTask([
   'workspace' => '176825', // Workspace ID
   'name' => 'Hello World!', // Name of task
   'assignee' => '[email protected]', // Assign task to...
   'followers' => ['3714136', '5900783'] // We add some followers to the task... (this time by ID)
]);

Creating a task for another assignee than yourself will mark the task as private by default. This results in the task not being available for modification through the API anymore. Take a look at the API Reference for more fields of the Task you can directly pass to createTask.

Adding task to project

$asana->addProjectToTask('THIS_TASK_ID_PLEASE', 'TO_THIS_COOL_PROJECT_ID');

Commenting on a task

$asana->commentOnTask('MY_BEAUTIFUL_TASK_ID', 'Please please! Don\'t assign me this task!');

Getting projects in all workspaces

$asana->getProjects();

Updating project info

$asana->updateProject('COOL_PROJECT_ID', [
    'name' => 'This is a new cool project!',
    'notes' => 'At first, it wasn\'t cool, but after this name change, it is!'
]);

Do more

There are a lot more methods to do almost everything with asana.

See the examples inside examples folder, read the comments on the class file for class magic and read Asana API documentation if you want to be a master.

If a method returned some data, you can always retrieve it by calling.

$asana->getData();

If you miss some functionality, open a pull request and it will be merged as soon as possible.

Enjoy ;D

Using Asana OAuth tokens

To use this API, you can also create an App on Asana to get an oAuth access token, then include the class:

require_once('asana-oauth.php');

Declare the oAuth class as:

$asanaAuth = new AsanaAuth('YOUR_APP_ID', 'YOUR_APP_SECRET', 'CALLBACK_URL');
$url = $asanaAuth->getAuthorizeUrl();

Where YOUR_APP_ID, YOUR_APP_SECRET and CALLBACK_URL you get from your App's details on Asana. Now, redirect the browser to the result held by $url. The user will be asked to login & accept your app, after which the browser will be returned to the CALLBACK_URL, which should process the result:

$code = $_GET['code'];
$asanaAuth->getAccessToken($code);

And you will receive an object with the access token and a refresh token The token expires after one hour so you can refresh it doing the following:

$asanaAuth->refreshAccessToken('ACCESS_TOKEN');

For a more detailes instructions on how to make oauth work check the example in examples/oauth.php

Author

Twitter: @ajimix

GitHub: github.com/ajimix

Contributors: view contributors

Copyright and license

Copyright 2022 Ajimix

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this work except in compliance with the License. You may obtain a copy of the License in the LICENSE file, or at:

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

asana-api-php-class's People

Contributors

airesvsg avatar ajimix avatar eflage avatar ehlovader avatar frankcrissalem avatar gvlasov avatar helmo avatar igorhim avatar javifr avatar jeff-greco avatar jorgetutor avatar ltk avatar mnunes01 avatar mroach avatar nickbreslin avatar robinbullocks4rb avatar rvanlaak avatar sammythesm avatar shagshag avatar sikker avatar stephen304 avatar vdespa-collab avatar xbakesx avatar zeeshanyshaikh avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

asana-api-php-class's Issues

Thank you!

Hello ajimix! Thank you for Asana API PHP Class! Can you add function to your example.php which add task to specify project?

P.S: Sorry for my bad english!

Line Breaks in Notes

Maybe I'm doing something wrong, but I can't seem to get line breaks to show up in the notes of tasks.

I've tried \n, \n\r, <br>, but they all just render as is. Any ideas? My code looks like:

  $result = $asana->createTask(array(
      'workspace' => '498346170860',
      'projects' => array('35253997924569'),
      'name' => 'Contact: '.$_GET['name'],
      'notes' => 'Contact Information:\n\r'.$_GET['name'].'\n\rPhone: '.$_GET['phone'].'\n\rEmail: '.$_GET['email'],
      'assignee' => '[email protected]'
  ));

Response time ridiculously slow on CURL execution

Hey ajimix,

Not certain this is actually on your end, but the CURL calls are taking anywhere from 1 to 4 seconds to load their return data. This is fine for small calls, but on projects where I'm loading in a lot of tasks, load times take well over 40 seconds per page load.

Any idea how we could speed this up?

Best,

Martin

Trying to get tasks filtered by today

Hey first and foremost thank you for this script and your work, it is a timesaver!

I am using your example of get-all.php and trying to filter the tasks to just be todays tasks. Below is what I have, hoping you can shed some light on it, looking at the asana class I thought I was doing everything right.

$tasks = $asana->getProjectTasks($project->id, array('assignee_status' => 'today'));

Suggested changes for usage with App access tokens

Hi!

I've made a couple of edits to the code to allow usage of the class with access tokens generated by oAuth App user logins, this prevents one from having to manually ask for the API key. Where can I push these? Not so familiar with pushing stuff to git :)

Cheers, Mike

Not working on localhost

Hey! im trying to use those examples on my localhost, but it's not working. Im getting a 500 status always...i know it's not your code but my server..but, do you have any clue about what can i do? i'd reallly appreciate it (':

Association between Teams and Tasks.

Hi,

Your project has been a time saver for me and a lot of others. Thank you for that. Your wrapper class does everything that one might need.

However, I would want to know one thing. You have written down many functions like getProjectTasks(), getTasksWithTag(), etc. where one can retrieve tasks within a particular set. But there seems to be no such function for getting tasks within Teams. By studying the data returned by Asana using your functions, there is no mention of a task belonging to a particular 'team'. Also, even when I export data as JSON through Asana's web application the teams find no mention. From what I understand, Asana itself does not provide an association between teams and tasks. Please correct me if I am wrong.

But if I am right at my conclusion, is there a workaround I could use? Teams are an important part of my data rendering and I need them to be mapped correctly in my reports that I am trying to generate from Asana. The report I want to generate would be hierarchical in nature:

Organization Team Project Task
A 1 a Task 1a
Task 2a
b Task 1b
Task 2b
2 c Task 1c
Task 2c
B 3 d Task 1d
Task 2d

Can I do something to achieve this hierarchy?

Regards,
Mayank Choudhary

Custom Fields

Anyone know how to add a custom field when creating a task?

createProject() returns 400 error

I can't get createProject() to work. I am getting the correct workspace from getWorkspaces (I know this because I can create a task), but createProject always returns 400 error. Can you provide a code sample that works?

Thanks so much for your help!

createProject() returns 400 error

Hi,
createProject method isn't working. Is there anything else that needs to be passed besides workspace,name and notes?

        $asana = new  Asana( array('apiKey' => $asana_key) );
        $project_data = array('workspace' => $workspace_id, 'name' => $project_name,'notes' =>'Project notes');

        $created_project = $asana->createProject( $project_data );

I can create a task in the same workspace successfully but creation of project in the same workspace always returns 400 error. Are there any restrictions while creating project using API key?

issues at creating new task in api

Trying to create a new task just like new-task-to-project.php
but task id is genrated EX (1.015460109095E+14) like this but new task is not adding and showing Error (while assigning project to task :404 error,).

$projectId & $taskId both are proper but no result..

`$asana->createTask(array(
    "workspace" => "99915435644125", // Workspace ID
    "name"      => "Getting all info"// Name of task
));


if ($asana->hasError()) {
    echo 'Error while project data: ' . $asana->responseCode;
    return;
  } else{
        $taskId = $asana->getData()->id; 
        echo $taskId;
        echo "<br>".$projectId."<br>";

        $asana->addProjectToTask($taskId,$projectId);
        if ($asana->hasError()) {
            echo 'Error while assigning project to task: ' . $asana->responseCode;
        } else {
            echo 'Success to add the task to a project.';
        }
}
`

Undefined variable: info in C:\wamp\www\AGA\asana\asana.php on line 875

Hi,
Your API is amazing. Thanks for sharing.
When I turned the debug mode to true in asana.php, the following error showed up:
Undefined variable: info in C:\wamp\www\AGA\asana\asana.php on line 875

$info["http_code"] variable was not available. I tried to go through all the possible places, but I couldn't find this one.
Any hints?

Best,
Akki

Can we upload attachment using this API

Hi,
Sorry ajimix! this is not an issue, this is just my request if possible. I'm new on Git and don't know where I should add request instead issue sections.

Your code is really helpful and I'm using. Now I need to add attachment to task. Is it possible to add attachment when I create new task. I see there is an option at bottom of doc page
http://developer.asana.com/documentation/

Thanks
~Anas

Asana API doesn't response

Hi.

I try to develope an app for view the tasks in a graphic but the Asana API doesn't response. I use the get-project-tasks.php example for test my server and I receive the following response:

Array
(
[url] => https://app.asana.com/api/1.0/tasks?project=14565209359219&
[content_type] =>
[http_code] => 0
[header_size] => 0
[request_size] => 0
[filetime] => -1
[ssl_verify_result] => 0
[redirect_count] => 0
[total_time] => 0
[namelookup_time] => 0.029504
[connect_time] => 0
[pretransfer_time] => 0
[size_upload] => 0
[size_download] => 0
[speed_download] => 0
[speed_upload] => 0
[download_content_length] => -1
[upload_content_length] => -1
[starttransfer_time] => 0
[redirect_time] => 0
[certinfo] => Array
(
)
)
Error while trying to connect to Asana, response code: 0

I know that probably the problem are in my server, but you have an idea about what I'm doing wrong?

I was searching information about this error code but I don't find anything.

Any help about it are welcome.

Thx.

Create new Project

Is it possible to create a new project through this API?

I modified the class and added:

public function createProject($workspaceId, $name){

    $data = array(  'name'      => $name,
                    'workspace' => $workspaceId,
                    'notes'     => 'n/a',
                    'archived'  => false
                 );

    return $this -> askAsana($this->workspaceUrl.'/'.$workspaceId.'/projects', $data, METHOD_POST);
}

but it doesn't seem to work..

getProjectTasks() returns empty if the list > 1000

Hi Adria,

I've been using your code for few weeks now and everything seemed to work well until my list got a bit out of hand. It took me a little while to troubleshoot it, but I ended up finding that if the list contains more than 1000 items, it just won't return anything.

That includes completed tasks too, so even if I have 5 items in my list but completed 996 tasks before, it would return null.

Cheers,
T.

getProjectsInWorkspace

the getProjectsInWorkspace function doesn't seem to work.

php parsing stops once it hits it.

my syntax/usage

$result = getProjectsInWorkspace($workspaceID, $archived);

create WebHook not working

Hi guys!
I have successfully used this script times before but now I need to create a webhook and it simply would not authorize me for the exact same access token I use to pull a task, which works:. SO I am able to get details on a task, but when I try to create a webhook I get a 400 error :(

Your help would be greatly appreciated, thank you!

Create Task / Update Task / Comment on task

Hello,
Thank you for sharing!

I'm trying to use functions Create Task / Update Task / Comment on task , but i have some problems.

Create Task : response code 400
Comment on task : response code 400
Update Task : response code 200 , Although the code does not make the update and returns the task , in its first status.

Sorry for my english
I would appreciate any help.
Androniki

No more api key availability

So Asana has now removed the API key ability to create tasks.

However they do have a personal token that you can have each user create and use.

Any plans to update this code so it will work again without switching to OAuth??

400 error

Hi,
I seem to be getting a 400 error when trying to use any of the create methods:

$workspaceId = '<id>'; $teamId = '<id>'; $asana->createProject([ 'name'=>'project Name', 'workspace'=>$workspaceId, 'team'=>$teamId, 'notes'=>'some notes' ]);

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.