tasks->createTask() throws exception

The following PHP method isn’t workin in my class for me even though the $workspace_id and $project_id are valid (and were obtained using the SDK connected to my Asana account).

public function handle() {

        $task = $this->asana->tasks->createTask(
                'workspace' => $workspace_id,
                'projects' => [$project_id],
                'name' => $content_story->title,
                'notes' => $content_story->description
            ['opt_pretty' => 'true']


It returns the following exception:

Asana\Errors\InvalidRequestError : Invalid Request

at /home/…/vendor/asana/asana/src/Asana/Errors/AsanaError.php:28
24| switch ($response->code) {
25| case ForbiddenError::STATUS:
26| throw new ForbiddenError($response);
27| case InvalidRequestError::STATUS:

28| throw new InvalidRequestError($response);
29| case InvalidTokenError::STATUS:
30| throw new InvalidTokenError($response);
31| case NoAuthorizationError::STATUS:
32| throw new NoAuthorizationError($response);

Exception trace:

1 Asana\Errors\AsanaError::handleErrorResponse(Object(Httpful\Response))

2 Asana\Client::request(“POST”, “/tasks”)

Not sure exactly when you tried this but the first thing to note is that Asana just went through an outage over the past few hours. It’s resolved now so I would try this again now. That may not be the cause of your issue but it’s the first thing to be suspicious of.


Here is my solution to create a Task

require 'vendor/autoload.php';

$client = Asana\Client::accessToken('INSERT ASANA ACCESS TOKEN', 
    array('headers' => array('asana-enable' => 'new_user_task_lists,new_project_templates'))); // Asana deprecation

$create_task = array(
	'name'		 => 'New test task', // Add your tasks name
	'projects'   => 'INSERT PROJECT GID',  // Add your project gid
	'workspace'  => 'INSERT WORKSPACE GID',  // Add your workspace gid
	'notes'		 => 'Here are some notes' // Add your notes here

$result = $client->tasks->createTask($create_task, array('opt_pretty' => 'true'));  // Create Task
1 Like