GithubHelp home page GithubHelp logo

asana / php-asana Goto Github PK

View Code? Open in Web Editor NEW
135.0 232.0 57.0 334 KB

Official PHP client library for the Asana API v1

License: MIT License

Makefile 0.09% PHP 98.34% JavaScript 0.08% Mustache 0.77% EJS 0.72%

php-asana's Introduction

Asana PHP API

Build Status Packagist Version

Official PHP client library for the Asana API v1

Installation

Composer

If you use Composer to manage dependencies you can include the "asana/asana" package as a depedency.

{
    "require": {
        "asana/asana": "^1.0.6"
    }
}

Alternatively you can specify the version as dev-master to get the latest master branch in GitHub.

Local

If you have downloaded this repository to the "php-asana" directory, for example, you can run composer install within "php-asana" then include the following lines at the top of a PHP file (in the same directory) to begin using it:

<?php
require 'php-asana/vendor/autoload.php';

Test

After running composer install run the tests using:

./vendor/bin/phpunit --configuration tests/phpunit.xml

You can also run the phpcs linter:

./vendor/bin/phpcs --standard=PSR2 --extensions=php src tests

Authentication

Personal Access Token

Create a client using a personal access token:

<?php
$client = Asana\Client::accessToken('ASANA_PERSONAL_ACCESS_TOKEN');

OAuth 2

Asana supports OAuth 2. asana handles some of the details of the OAuth flow for you.

Create a client using your OAuth Client ID and secret:

<?php
$client = Asana\Client::oauth(array(
    'client_id'     => 'ASANA_CLIENT_ID',
    'client_secret' => 'ASANA_CLIENT_SECRET',
    'redirect_uri'  => 'https://yourapp.com/auth/asana/callback',
));

Redirect the user to the authorization URL obtained from the client's session object:

<?php
$url = $client->dispatcher->authorizationUrl();

authorizationUrl takes an optional state parameter, passed by reference, which will be set to a random number if null, or passed through if not null:

<?php
$state = null;
$url = $client->dispatcher->authorizationUrl($state);
// $state will be a random number

Or:

<?php
$state = 'foo';
$url = $client->dispatcher->authorizationUrl($state);
// $state will still be foo

When the user is redirected back to your callback, check the state URL parameter matches, then pass the code parameter to obtain a bearer token:

<?php
if ($_GET['state'] == $state) {
  $token = $client->dispatcher->fetchToken($_GET['code']);
  // ...
} else {
  // error! possible CSRF attack
}

For webservers, it is common practice to store the state in a secure-only, http-only cookie so that it will automatically be sent by the browser in the callback.

Note: if you're writing a non-browser-based application (e.x. a command line tool) you can use the special redirect URI urn:ietf:wg:oauth:2.0:oob to prompt the user to copy and paste the code into the application.

Usage

The client's methods are divided into several resources: attachments, events, projects, stories, tags, tasks, teams, users, and workspaces.

Methods that return a single object return that object directly:

<?php
$me = $client->users->getUser("me");
echo "Hello " . $me->name;

$workspaceGid = $me->workspaces[0]->gid;
$project = $client->projects->createProjectForWorkspace($workspaceGid, array('name' => 'new project'));
echo "Created project with gid: " . $project->gid;

Methods that return multiple items (e.x. getTasks, getProjects, getPortfolios, etc.) return an items iterator by default. See the "Collections" section

Options

Various options can be set globally on the Client.DEFAULTS object, per-client on client.options, or per-request as additional named arguments. For example:

<?php
// global:
Asana\Client::$DEFAULTS['page_size'] = 1000;

// per-client:
$client->options['page_size'] = 1000;

// per-request:
$client->tasks->getTasks(array('project' => 1234), array('page_size' => 1000));

Available options

  • base_url (default: "https://app.asana.com/api/1.0"): API endpoint base URL to connect to
  • max_retries (default: 5): number to times to retry if API rate limit is reached or a server error occures. Rate limit retries delay until the rate limit expires, server errors exponentially backoff starting with a 1 second delay.
  • full_payload (default: false): return the entire JSON response instead of the 'data' propery (default for collection methods and events.get)
  • fields and expand: array of field names to include in the response, or sub-objects to expand in the response. For example array('fields' => array('followers', 'assignee')). See API documentation

Collections (methods returning an array as it's 'data' property):

  • iterator_type (default: "items"): specifies which type of iterator (or not) to return. Valid values are "items" and null.
  • item_limit (default: null): limits the total number of items of a collection to return (spanning multiple requests in the case of an iterator).
  • page_size (default: 50): limits the number of items per page to fetch at a time.
  • offset: offset token returned by previous calls to the same method (in response->next_page->offset)

Events:

  • poll_interval (default: 5): polling interval for getting new events via events->getNext and events->getIterator
  • sync: sync token returned by previous calls to events->get (in response->sync)

Asana Change Warnings

You will receive warning logs if performing requests that may be affected by a deprecation. The warning contains a link that explains the deprecation.

If you receive one of these warnings, you should:

Read about the deprecation. Resolve sections of your code that would be affected by the deprecation. Add the deprecation flag to your "asana-enable" header. You can place it on the client for all requests, or place it on a single request.

$client = Asana\Client::accessToken('ASANA_PERSONAL_ACCESS_TOKEN', 
    array('headers' => array('asana-disable' => 'string_ids')))

or

$client = Asana\Client::accessToken('ASANA_PERSONAL_ACCESS_TOKEN', 
    array('headers' => array('asana-enable' => 'string_ids,new_sections')))

If you would rather suppress these warnings, you can set

$client = Asana\Client::accessToken('ASANA_PERSONAL_ACCESS_TOKEN', 
    array('log_asana_change_warnings' => false))

Collections

Items Iterator

By default, methods that return a collection of objects return an item iterator:

<?php
$workspaces = $client->workspaces->getWorkspaces();
foreach ($workspaces as $workspace) {
    var_dump($workspace);
}

Internally the iterator may make multiple HTTP requests, with the number of requested results per page being controlled by the page_size option.

Raw API

You can also use the raw API to fetch a page at a time:

<?php
$offset = null;
while (true) {
    $page = $client->workspaces->getWorkspaces(null, array('offset' => $offset, 'iterator_type' => null, 'page_size' => 2));
    var_dump($page);
    if (isset($page->next_page)) {
        $offset = $page->next_page->offset;
    } else {
        break;
    }
}

Contributing

Feel free to fork and submit pull requests for the code! Please follow the existing code as an example of style and make sure that all your code passes lint and tests.

To develop:

  • git clone [email protected]:Asana/php-asana.git
  • composer install
  • phpunit --configuration tests/phpunit.xml

Code generation

The specific Asana resource classes in the Gen folder (Tag, Workspace, Task, etc) are generated code, hence they shouldn't be modified by hand.

Deployment

Repo Owners Only. Take the following steps to issue a new release of the library.

  1. Merge in the desired changes into the master branch and commit them.
  2. Clone the repo, work on master.
  3. Bump the package version in the VERSION file to indicate the semantic version change.
  4. Update the README.md package depedency version in the "Installation" section
  5. Commit the change.
  6. Tag the commit with v plus the same version number you set in the file. git tag v1.2.3
  7. Push changes to origin, including tags: git push origin master --tags
  8. Log into packagist.org and click on the update button

The rest is automatically done by Composer / Packagist. Visit the asana package to verify the package was published.

NOTE: If the package did not update on Packagist, log into Packagist and click on the update button to manually update the package

php-asana's People

Contributors

adamhopkinson avatar agnoster avatar asanabot avatar aw-asana avatar chalda-pnuzig avatar epelz avatar eugenefvdm avatar gbinow avatar joetrollo avatar jv-asana avatar marcogallotta avatar markchua avatar nonotest avatar praecipula avatar rossgrambo-zz avatar slobak avatar theaeolianmachine avatar thedom avatar themy3 avatar tlrobinson avatar xeroxer 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  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

php-asana's Issues

PHPCS Lint Test in README Fail

Hey, Asana team!

Minor irony but setting things up as shown in the README:

$ composer install
$ ./vendor/bin/phpunit --configuration tests/phpunit.xml
$ ./vendor/bin/phpcs --standard=PSR2 --extensions=php src tests

Actually produces a bunch of errors and warnings when PHPCS checks the test cases. These appear to be stylistic constraints like character counts, but I was wondering if I could submit a pull request with these things cleaned up.

I'm not sure if these were left in to demonstrate that the linter works or for some reason that escapes me, but I wouldn't be surprised if someone got confused and thought there were legitimate build errors because of these.

I understand this is a very low priority issue :)

Thanks!

Example Test Response:

FILE: .../php-asana/tests/Asana/Resources/WebhooksTest.php
--------------------------------------------------------------------------------
FOUND 1 ERROR(S) AND 1 WARNING(S) AFFECTING 2 LINE(S)
--------------------------------------------------------------------------------
 37 | WARNING | Line exceeds 120 characters; contains 142 characters
 41 | ERROR   | Line indented incorrectly; expected at least 12 spaces, found
    |         | 10
--------------------------------------------------------------------------------

Some fields does not work.

Hi,

I've been working with asana-php last week, and i need to get from my tasks some fields, that seems your api doesn't returning. for example. GET request on html_text on stories, did not return anything. Same as GET request preview_url & download_url at attachments.

At attachments, the function for returning attachments is

public function showAttachments($task)
{
        $attachments = $this->client->attachments->findByTask($task, [
            'fields' => [
                'name', 'view_url'
            ]
        ]);

        return $attachments;
}

and it returns following object

object(stdClass)#839 (2) { ["id"]=> int(698381732394846) ["name"]=> string(26) "Demo 05.06.2018 15:57.html" }

Thank you for quick reply.

Cannot access data block on token exchange

When a code is exchanged for a token the API responds with the authentication data as well as a data block that contains some key data on the logged in user. This data is not accessible through the client.

┆Issue is synchronized with this Asana task

Asana-Enable header still returns deprecation warning

I received a deprecation error:

ASANA Create: This request is affected by the "new_user_task_lists" deprecation. Please visit this url for more info: https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828

Adding "new_user_task_lists" to your "Asana-Enable" or "Asana-Disable" header will opt in/out to this deprecation and suppress this warning."

Link here.

I am adding the headers to our oauth initialization, as well as the createInWorkspace call; however, it doesn't seem to be honoring the headers. The only way I can get the deprecation warning off is to hide the logging.

Here is the code we are using to add a task to Asana:

$options = [
	'headers' => [
		// Tried each of these, none of these work
		'asana-enable' => 'new_user_task_list',
		'asana-disable' => 'new_user_task_list',
		'Asana-Enable' => 'new_user_task_list',
		'Asana-Disable' => 'new_user_task_list',
	],
	// 'log_asana_change_warnings' => false,
];

$connection = AsanaClient::oauth([
						'client_id'		=> config('integration.asana.key'),
						'client_secret'	=> config('integration.asana.secret'),
						'token'			=> $this->settings['token'],
						'access_token'	=> $this->settings['token'],
						'refresh_token'	=> $this->settings['refresh_token'] ?? null,
						'redirect_uri'  => config('integration.oauth_callback_uri'),
					], $options);

try {

	$attributes = [
		'name'			=> 'PL# title',
		'html_notes'	=> '<body>whole bunch of HTML</body>',
		'projects'		=> [
			$projectId,
		],
	];

	$this->output = $connection->tasks->createInWorkspace($this->integration['data']['workspace'], $attributes, $options);
} catch (\Exception $e) {

	$this->error = [
		'code' => $e->getCode(),
		'reason' => 'ASANA Create: ' . $e->getMessage(),
		'error' => $e->getPrevious(),
	];

	return $this->error();

}

Wasn't sure if this is something more on the Asana side, or in the package. Any thoughts on how best to address this?

Client.php does not return a full response object

Expected Behavior

The Client.php returns a full response object, with headers

Actual Behavior

The Client.php returns only the body of the response object

This response headers are important since the response is expected to include a Retry-After header in the event of a rate limit exception, according to the documentation

https://asana.com/developers/documentation/getting-started/rate-limits

Steps to Reproduce the Problem

  1. make a request
  2. include array('full_payload'=>TRUE) in the options
  3. only the body of the message is returned
    Client.php ~:84
                if ($options['full_payload']) {
                    return $response->body;
                } else {
                    return $response->body->data;
                }

Specifications

  • Version: v0.9.1
  • Platform: Composer / Nginx
  • Subsystem: Laravel

POSIX not available on Windows enviroments

when you try to get the system information with posix_uname(); (dispatcher.php line: 87) it cannot be run under a windows environment. This is because windows is POSIX non-compliant. So running your script on a windows server is impossible.
I have personally found away around the issue by installing a linux environment (vagrant) on my windows PC, but for others this may be unavailable option - resulting in them not being able to create apps with asana.
There is a windows alternative (probably the reason windows is non-compliant) called SUA - subsystem for unix based applications. If you change the script to check if posix_uname() is available, then you can send the system information depending on the OS (using posix_uname() for UNIX and SUA for windows).

https://en.wikipedia.org/wiki/Windows_Services_for_UNIX - helpful link I suppose
http://php.net/manual/en/intro.posix.php - php.net saying that posix does not work on windows enviroments!

sorry I couldn't be much use, but I think issue could pop-up with some users and I personally had a hard time finding a solution!

NOTE: I don't actually know what SUA is or dose, and I'm not 100% sure if you can access it through php. so my solution to fixing the script probably doesn't work.

Creation of dynamic property warnings

The package has lots of dynamic property warnings f.e.

<warning> DEPRECATED </warning> Creation of dynamic property Asana\Client::$dispatcher is deprecated in vendor/asana/asana/src/Asana/Client.php on line 45.

Adding #[\AllowDynamicProperties] on these classes could solve this.

Does this still work?

Does this project still work? I am getting errors. Firstly,
$workspaceId = $me->workspaces[0]->id;
becomes
$workspaceId = $me->workspaces[0]->gid;

Then after that, creating the project using your example results in:

PHP Fatal error:  Uncaught Asana\Errors\InvalidRequestError: Invalid Request in /home/pi/Scripts/Asana/php-asana/src/Asana/Errors/AsanaError.php:28
Stack trace:
#0 /home/pi/Scripts/Asana/php-asana/src/Asana/Client.php(98): Asana\Errors\AsanaError::handleErrorResponse(Object(Httpful\Response))
#1 /home/pi/Scripts/Asana/php-asana/src/Asana/Client.php(247): Asana\Client->request('POST', '/workspaces/121...', Array)
#2 /home/pi/Scripts/Asana/php-asana/src/Asana/Resources/Gen/ProjectsBase.php(58): Asana\Client->post('/workspaces/121...', Array, Array)
#3 /home/pi/Scripts/Asana/move_due_tasks_to_today.php(17): Asana\Resources\Gen\ProjectsBase->createInWorkspace('123456789', Array)
#4 {main}
  thrown in /home/pi/Scripts/Asana/php-asana/src/Asana/Errors/AsanaError.php on line 28

Do I persevere and try to address the issues or is this project dead?

Thanks

Task Custom Fields Aren’t Returning

Hi!

I’m pulling tasks from a project using: client->projects->tasks()

It’s returning all (i think all) information, but not any custom field values. Here’s an example response:

assignee: Object
assignee_status:"inbox"
completed:false
completed_at:null
created_at:"2017-01-04T18:49:02.960Z"
due_at:null
due_on:"2017-03-15"
followers:Array[2]
hearted:false
hearts:Array[0]
id:237992700337136
memberships:Array[1]
modified_at:"2017-01-27T13:48:46.879Z"
name:"Detailer/Fabricator Relationship"
notes:"text..."
num_hearts:0
parent:null
projects:Array[1]
subtasks:Array[16]
tags:Array[1]

runnig 0.5.5 of the SDK.

Thanks!

┆Issue is synchronized with this Asana task

PHP Client sdk: workspace.typeahead marked as deprecated. Suggested replacement function doesn't exist

Simple issue, the Asana developer docs suggest using $client->typeahead->typeaheadForWorkspace for typeahead queries. However, this function and in addition the $client->typeahead class don't appear to exist as of the 0.10.8 release which is the latest at the time of writing.

In the PHP Client the typeahead feature is still avaiable via $client->workspaces->typeahead, however the function is marked as deprecated with a suggestion to use the above methods instead. See the examples here:

https://developers.asana.com/docs/get-objects-via-typeahead

Get tasks by name

Hello, I'm trying to use php-asana to add comments to an asana task.
I get the tasks from a project but i want to get them by task 'name' is there a way to acheive this?

Code:

$tasks = $asana_client->tasks->findByProject('project_id', array('name' => 'task_name'));
foreach ($tasks as $task) {
	var_dump($task);
}

This gets me all the tasks in the project, I don't know if adding the name as a parameter works or is it just ignoring it.

Also is there a documentation for this library?

for each on client->projects->getProjects() return error

What I want: Get all my project.

What I have try:
I get an error (I have multiple project):

$asana_client = Client::accessToken(env('ASANA_PERSONAL_ACCESS_TOKEN'));

$projects = $asana_client->projects->getProjects();

foreach ($projects as $project) {
	dump($project);
}

Environment: I am using laravel 9 which use php 8.0.13

PS:
This works:

$asana_client = Client::accessToken(env('ASANA_PERSONAL_ACCESS_TOKEN'));

$projects = $projects = $asana_client->get('/projects', []);

foreach ($projects as $project) {
	dump($project);
}

OAuthDispatcher expirationTimeSeconds cannot be automatically set

Hello Everyone,

In the OAuthDispatcher, the expirationTimeSeconds can only be set calling the setExpiresInSeconds directly from an outside source.

Currently, to make Asana refresh the token through the refreshAccessToken (called from authenticate), the expiration must be set manually.

Would it be possible to pass the expiration time in the constructor as an additional option? This would allow the dispatcher to correctly refresh the token when needed?

This could be achieved by allowing an option and setting the expirationTimeSeconds in the constructor, similar to this

$this->expirationTimeSeconds = isset($options['expiration']) ? time() + $options['expiration'] : null;

If this is an acceptable solution, I would be happy to provide a pull request.

Exception should be more detailed

Currently we have to jump inside the Exception response's body to uncover what happened on an AsanaError. This is, to say the least, counter-productive. Details should be given on a specific and clear exception field, or even inside its message.

Unable to get updated sync token from CollectionPageIterator

The standard response from a getEvents request is a CollectionPageIterator however this does not handle the persistence of the sync token received from the API and it is therefore not possible to persist this value easily, without dropping the iterator (and it's helper methods) entirely.

A potential solution to this would be to update the CollectionPageIterator code to:

class CollectionPageIterator extends PageIterator
{
    public $sync = null;

    protected function getInitial()
    {
        return $this->client->get($this->path, $this->query, $this->options);
    }

    protected function getNext()
    {
        $this->options['offset'] = $this->continuation->offset;
        return $this->client->get($this->path, $this->query, $this->options);
    }

    protected function getContinuation($result)
    {
        if ($result->sync ?? null) {
            $this->sync = $result->sync;
        }

        return isset($result->next_page) ? $result->next_page : null;
    }
}

Then when making a request a user can do this:

$pageIterator = $client->events->getEvents(['resource' => 'resource-gid', 'sync' => 'my-sync-token'], ['iterator_type' => 'pages']);
$items = iterator_to_array($pageIterator->items());
$sync = $pageIterator->sync;
// Persist sync token for later use.

There is of course a better approach than this, but a simple quick fix for anyone looking the above should work!

API Keys deprecated.

On https://asana.com/developers/documentation/getting-started/auth you state:
"API Key (Deprecated) The API key has been deprecated in favor of OAuth 2.0."

However, in the readme.md file it just says that asana supports OAuth 2.
"Asana supports OAuth 2. asana handles some of the details of the OAuth flow for you."

I think you should specify that API keys are deprecated and OAuth 2 should be used instead.

Thanks.

Getting tasks by Project ID and filtering by Tag or Section

I'm trying to find out how I can get a certain set of tasks within a project. I've tried using sections and tags, but for some reason I'm not able to filter down properly.

This is what my request url looks like when I try to get all tasks, then filter by project and tag.
https://app.asana.com/api/1.0/tasks?limit=50&project=708311468785908&tag=716726489964039

Which returns this error:
Must specify exactly one of project, tag, or assignee + workspace

I've also tried getting all tasks within a project, then filter by tag. Same error as above.
https://app.asana.com/api/1.0/projects/708311468785908/tasks?limit=50&tag=716726489964039

It doesn't seem like it's currently possible to filter the response. Is it all or nothing? What am I missing? I can get this done by getting all tasks in a project, then looping through each to get their membership associations, but that's a pretty expensive query...

PHP 8.1 Deprecated warnings

Hi there,
We receive few deprecated warnings using PHP8.1.

Return type of Asana\Iterator\PageIterator::current() should either be compatible with Iterator::current(): mixed, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice.

Return type of Asana\Iterator\ItemIterator::valid() should either be compatible with Iterator::valid(): bool, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice.

Return type of Httpful\Response\Headers::count() should either be compatible with Countable::count(): int, or the #[\ReturnTypeWillChange] attribute should be used to temporarily suppress the notice.

Can you tell me when this issue can be solved?

Add Attachment to Task

Looks like the Underlying Asana API has changed and the method this repo uses no longer works.

504 Gateway timeout - on large subtasks

When a parent task has lots of subtasks (5000+) and try to create a new subtask we receive a 504 gateway timeout intermittently from the API - is there a way of getting around this?

bigint id is converted to float (in PHP < 7)

Hi,

Example of issue:
Lets assume Asana API returns this JSON:
{"id":103000832048915,"created_at":"2016-03-21T11:52:56.019Z","modified_at":"2016-03-23T15:33:03.876Z","name":"Test","notes":"Test","completed":false,"completed_at":null,"due_on":"2016-04-25","due_at":null,"workspace":{"id":11111111111111},"parent":null}

So id is 103000832048915, and it doesn't fit 32-bit int.
That's why PHP < 7 converts it to float(1.0300083204892E+14).
This breaks ID, it isn't valid anymore.

In PHP 7 it is decoded as int(103000832048915)

There are exists special json_decode parameter JSON_BIGINT_AS_STRING (for fix in PHP < 7)
However, nategood/httpful has rejected pull request (nategood/httpful#189) that would make possible using this json_decode option in Asana/php-asana.

Best regards, Alexander.

Events

Hi all,

I have issues with events:

$events = $api->events->getEvents(['resource' => $pojectId]);

returns null

when I try:

$events = $api->events->getIterator(['resource' => $pojectId]));
foreach ($events as $event) {
var_dump($event);
}

when it tries to iterate iterator fails with InvalidTokenError (code: 500)

can you help, please

Unable to use project templates

Hi there,

I am using the latest version of this library (0.10.8), however I am getting an error when trying to load a project template:

Undefined property: Asana\Client::$projecttemplates

My code is quite simple:

$client->projecttemplates->getProjectTemplate('xxxxxxxxxxx')

It doesn't look like project template support was fully added in the latest update?

Unable to connect: 35 SSL connect error

Hello guys.
We're assembling a simple page with a list of our planned tasks so our users can follow our schedule.
We were able to successfully use Asana API from localhost (no https).
But when we try to use it from our production environment (https) we get the following error:

Unable to connect to "https://app.asana.com/api/1.0/projects?limit=50&opt_fields=name%2Carchived&workspace=15777648238435": 35 SSL connect error

Would you have any clue about this?
Thank you very much :)

┆Issue is synchronized with this Asana task

Get tasks from active Project

Hello, I'm writing a script that every night goes to Asana and get the tasks from active project. I'm trying to get stats with other software to create a Balance Score card, but Asana does not give all details that I want.
Just want to know what we have done in a certain period.

This is my code related with Asana:

`
$asana = new Asana(array('personalAccessToken' => $asana_token)); // Create a personal access token in Asana or use OAuth

try
{
$asana->getProjects();
if ($asana->hasError()) {
echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
return;
}

// $asana->getData() contains an object in json with all projects
foreach ($asana->getData() as $project) {
echo 'Project ID: ' . $project->id . ' is ' . $project->name . '\n' . PHP_EOL;

 $asana->getProjectTasks($project->id);
 if ($asana->hasError()) {
 echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;
 return;
 }
 foreach ($asana->getData() as $task) {

$asana->getTask($task->id);
 $task_detail = $asana->getData();

//var_dump($task_detail);
 if(!empty($task_detail->assignee->name)) $assignee = $task_detail->assignee->name; else $assignee = '';
 } // asana task

}
}
`

┆Issue is synchronized with this Asana task

Is it possible to use styling in the note call

I want to maintain the styling of the notes in my issues.
According to the official API documentation this should be possible.

https://asana.com/developers/documentation/getting-started/rich-text

But when I try its not working with this PHP API. I also tried to use html_notes instead notes but this is not available (anymore).

Here an example what I try to do:

# Update tasks
$myTask = $client->tasks->update(111111, array(
    "name" => " Updated:demo task created at " . date('m/d/Y h:i:s a'),
    "notes"  => "This is some <strong>nice</strong> description /n /n And a blank line below it"
));

$client->tags->getTags() throwing an InvalidRequestError

Theclient->tags->getTags()function should return a collection however in the request it is failing and throwing an InvalidRequestError.

This error is only thrown if I were to execute iterator_to_array.

Example to replicate:

        $client = Client::accessToken($api_token);

        $existingAsanaTags = iterator_to_array($client->tags->getTags(), true);

        print_r($existingAsanaTags);

Not sure what the Asana API is messing up in the URI as it appears to be calling a 'GET' to /tags and I am also using iterator_to_array($client->tasks->getTasksForProject($project_id), true); with no issues.

Error on createTask

Hi!
I am trying to create a task and I am getting an error:

array_search() expects parameter 2 to be array, null given
/vendor/asana/asana/src/Asana/Client.php(333)  

Here is my code:

$args = array(
    'name'      => $this->task_data['title'],
    'notes'     => $this->task_data['description'],
    'assignee'  => $this->task_data['gid'],
    'followers' => array( $this->task_data['gid'] ),
    'due_on'    => $this->task_data['dueon'],
    'workspace' => $this->task_data['workspace']
);

if ( !empty( $this->task_data['project'] ) ) {
    $args['projects'] = array( $this->task_data['project'] );
}

$task = $this->asana->tasks->createTask( $args );

What am I doing wrong?

'headers' config is replaced by automatically-generated request 'headers'

I'm setting Asana\Client like this:

$options = [
    'headers' => [
        'asana-enable' => 'string_ids'
    ]
];
$client = AsanaClient::accessToken('***', $options);

But when I'm trying to post a comment to a task like this:

$gid = '1136900226906650';
$r = $client->addComment($gid, [
    'text' => 'test comment',
]);

The headers from client config are replaced during a simple merge with automatically generated content-type header from request: https://github.com/Asana/php-asana/blob/master/src/Asana/Client.php#L232-L245

There should be a recursive merge in https://github.com/Asana/php-asana/blob/master/src/Asana/Client.php#L83

P.S. Asana version is 0.9.0

GET TASK - missing field start_on in response!!

getting a task data, the field start_on is missing! is possibile to retrieve it? is very important in order to manage tasks using client! I also tried the CURL GET call but that parameter is missing there too!!

Invalid Request On findAll Users Method

Hi,

When I try to load all Organization users (no params), I get an error message. This simple code below returns "Invalid Request". Also, adding the code in try/catch with the Exception \Asana\Errors\AsanaError does not catch anything.

$result = $asanaClient->users->findAll(); // HTTP ERROR 500

But, when I try the code I have a successful return.

$result = $asanaClient->users->findAll(['workspace' => '1200-fake']); // Success load

Well, I contoured it in my code to leave the option of getting all users (first option). But, my question is; have any option that I need to add to the findAll() method to get all organization users?

createTask not working after user-task-list update

Hi,

Since Asana started rolling out this update (https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828) I get an exception back when creating a new task.

The exception: This request is affected by the "new_user_task_lists" deprecation. Please visit this url for more info: https://forum.asana.com/t/update-on-our-planned-api-changes-to-user-task-lists-a-k-a-my-tasks/103828 Adding "new_user_task_lists" to your "Asana-Enable" or "Asana-Disable" header will opt in/out to this deprecation and suppress this warning.

The task is created, so i'm guessing the api redirects to the get endpoint with some wrong parameters?

The params we currently use for the createTask call (might be that one of the params is the cause?)

$task = $this->asana->tasks->createTask([
                'assignee' => ...,
                'assignee_status' => 'today',
                'due_on' => now()->addDay()->toDateString(),
                'name' => ...,
                'projects' => [...],
                'notes' => ...,
        ]);

Would love to help, but currently have no clue on where to start.

get user team not working with limit param

This is get my team list url and the result is ok
https://app.asana.com/api/1.0/users/me/teams?organization=167784858458

but when I get my teams with some limit, like this url
https://app.asana.com/api/1.0/users/me/teams?organization=167784858458&limit=50
the output the whole organisation teams not only mine

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.