Invalid Request when following php-asana example

When trying to create a project following the ‘create-project-and-stream-events’ php example, the script runs fine until getting to the part of creating the project, at which point I get a Fatal error.

Fatal error: Uncaught Asana\Errors\InvalidRequestError: Invalid Request in /Users/Lee/Desktop/asana/php-asana/src/Asana/Errors/AsanaError.php:28

I’ve also tried creating an array of data in line with what the docs suggest you should submit when making a project and I get the same response. I’m sure its just a syntax/data issue but if someone could point me in the right direction that would be great

Did you try editing the lib and printing the actual error?

1 Like

I hadn’t thought of that. I’m now seeing ‘Sync token invalid or too old’ as my error message

That’s progress. Does the example include how to get the token? Or maybe you were supposed to use your Personal Access Token?

I can’t see any mention of a sync token so I’m a bit lost here. It does have me use my own personal access token yes.

If you wanted to see the code its here php-asana/example-create-project-and-stream-events.php at master · Asana/php-asana · GitHub I’m not sure if you would be able to see anything blatantly wrong.

It seems like all of the GET requests work just fine and then as soon as the script tries to submit some data to create a project, it causes that error.

That error is related to Events, not creating a project, so it’s occurring in the last section of the code, below the project creation code.

Is the project getting created? If so, then as I say, you’ll need to focus on the Events code below it. (I don’t know PHP or the PHP Asana client so afraid I can’t be of additional help there.)

If it’s not getting created, then I predict there is another error you’re not seeing, relating to the project creation and occurring before you get the “sync token” error.

Hey Phil,

That error remains even when I remove the events related code below. The project is also not being created. Very weird… Do you know if there is anyone on the forums who has used the php client a lot and would be available for me to rack their brains? The php-asana docs make it seem like it should be extremely straightforward to create a project via the api but clearly im missing something

That is very weird. @Ross_Grambo can you help out here at all?

Can you try:

<?php

require_once __DIR__ . '/../vendor/autoload.php'; // Autoload files using Composer autoload

use Asana\Client;

$client = Client::accessToken("{PAT}");

$project = $client->projects->createProjectForWorkspace("123456789", array('name' => 'Test Project', 'team' => '1234567890'));
var_dump($project);

The above works for me ^

1 Like

Hey, with a bit of tinkering I managed to create a project with this. Thanks very much for the help!

That’s excellent news! Would you be willing to share your working code here? I’m sure it could benefit others looking for a similar solution.

1 Like

Working code for PHP client:

<?php

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

use Asana\Client;

$ASANA_ACCESS_TOKEN = '{token}';

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

$me = $client->users->getUser("me");

$workspaceGid = $me->workspaces[0]->gid;

;

$project = $client->projects->createProjectForWorkspace($workspaceGid, array('name' => 'Test Project', 'team' => 'team_id'));

// var_dump($project);
3 Likes