Connecting the API to a form

Hi there.

I am new here so still trying to get everything correct and understanding how this API works.

My work:
We are working on a form for one department. The form should have a a few things to fill out, and when they submit the form it should be put into a section in Asana that we have set in the back-end.

Can anyone give a PHP/Curl or JavaScript example of how they would connect this so that when a department here fills in the form, the connection goes through and the information is pushed to Asana?

I am getting a few connection failures and it looks like I need to log into Asana to get a new token every time, but the people who are gonna fill out the form should not log into Asana, they should just submit the form and everything should go from there.

Thanks in advance.

Hi @Joakim_Paulsen,

First question: is there a good reason why you can’t use an Asana form for your scenario? That would eliminate having to use the API altogether.

If you do have to use an external form and then create the task via the API, consider using a Personal Access Token - it’s much simpler authentication method if you’re only needing to always authenticate to the same single Asana account.

Hi there Phil.

I have not seen the Asana form and not seen how it works.
The form I am creating has a few conditions in regards of what you pick and what is gonna be showin if “this” and “that” is picked and selected.

I will take a look at the Personal Access Token and see how that one works.

FYI Asana forms support this type of conditional branching if you have a Business or Enterprise subscription.

Thank you Phil, I will take a look at this.

I have now done a little testing by just trying to get a project created at my workspace.

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

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

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

            echo "Hello " . $me->name;

            $project = $client->projects->createProjectForWorkspace($workspaceGid, array(
                'name'  => 'Form project'

            echo "Created project with gid: " . $project->gid;

This is the code I try to run.
In localhost I get http errors, so I tried on my server that is running https, but i get a 500 Internal Server error:

Internal Server Error
Transferred38,40 KB (38,23 KB size)
Referrer Policystrict-origin-when-cross-origin

I am following this: GitHub - Asana/php-asana: Official PHP client library for the Asana API v1

Are you able to give a little hint on where I am doing this wrong?

I’m afraid I don’t know PHP to help out here.

@Bastien_Siebman you know some PHP I think?

Does the getUser at least works or nothing works?

Hi there.

I could get information but not post anything.
But I got it working eventually with Curl.

1 Like