Chat with us, powered by LiveChat

This website uses cookies

Our website, platform and/or any sub domains use cookies to understand how you use our services, and to improve both your experience and our marketing relevance.

Say hello to redesigned Cloudways, an empowering Startup Program, enhanced Staging, a new Let’s Encrypt Wildcard SSL certificate feature, and more. READ MORE

Send CloudwaysBot Notifications to Asana using Cloudways API

Updated on November 14, 2016

5 Min Read
Reading Time: 5 minutes

Bots are ideal for automating communication with customers and end users, mainly because of real time streaming of alerts and messages. Cloudways offers CloudwaysBot, a very smart assistant for servers and applications hosted on Cloudways Platform. The bot provides real time notifications that help users take actions for further optimizing servers and applications.

Send CloudwaysBot Notifications to Asana using Cloudways API

In this article I will demonstrate how to integrate CloudwaysBot and the popular task management application, Asana. Once you are done, you will be able to send CloudwaysBot notifications to Asana as a task.

Before starting, I assume that you already have an account on Cloudways. If you don’t, sign up for an account and launch your server. Next, launch your PHP application as shown in the GIF below.


Add the Application in Asana and Get Access Token

The next step of the process is to setup the application in Asana. This will generate an access token that would be used in the later cases.

Sign into Asana and click Profile > My Profile settings > Apps.

Click the Manage Developer Apps button and the heading Personal Access Tokens will appear.


Click Create New Personal Access Token. Enter a short description of the application and then click the Create button to get the access token.

Note: Save this token carefully as Asana does not display the token once created.

Add Asana PHP Wrapper Class

To use Asana API, I will use the Asana PHP wrapper class available at GitHub. This simple class was created by Adria Jimenez.

To install this class, run the following command in Composer

composer require ajimix/asana-api-php-class

The Asana API class is now ready for use. Asana has a structural approach to task management with a hierarchy of workspaces, projects, and finally, tasks. I will fetch the workspace and projects from Asana.

Add require ‘vendor/autoload.php’; in index .php and initialize Asana by providing the access token. Validate it for the success response code.

$asana = new Asana(array(

   'personalAccessToken' => 'Your access token here'


if ($asana->hasError()) {

   echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;


Get all workspaces through this line:


Now using foreach() loop, I will print all workspaces and the included projects,

foreach ($asana->getData() as $workspace) {

   echo '<h3>' . $workspace->name . '(id ' . $workspace->id . ')' . '</h3><br />' . PHP_EOL;
   $asana->getProjectsInWorkspace($workspace->id, $archived = false);

   if ($asana->hasError()) {

       echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;

   foreach ($asana->getData() as $project) {

       echo '<strong>' . $project->name . '(id ' . $project->id . ')' . '</strong><br>' . PHP_EOL;


The following is the result of this code. The image shows that I have two workspaces and one project under workspace.

I will use the workspace ID and the project ID to create a new task in the project.

Send CloudwaysBot Alerts as Tasks to Asana

To send CloudwaysBot alerts as task in Asana, I will setup a webhook in CloudwaysBot. But before that, I will add the code to get the response of the webhook.

$json = file_get_contents('php://input'); //get the webhook response

$actions = json_decode($json); //decode the task object

$text = $actions->text; //save the task in $text

This is a simple code snippet that will get the CloudwaysBot response and save it in $text.

Let’s create a task code and send this alert to the Asana Project. I will save project ID and workspace ID in variables.

$workspace = '211386399674884';

$projectId = '211814602016238';

// create the task

$result = $asana->createTask(array(

   'workspace' => '211386399674884', // Workspace ID

   'name'      => $text, // Alert

   'assignee'  => '' // Assign task to...


//check 201 response code for success

if ($asana->hasError()) {

   echo 'Error while trying to connect to Asana, response code: ' . $asana->responseCode;



$taskId = $asana->getData()->id; // Here we have the id of the task that have been created

// Now we do another request to add the task to a project

$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.';


I have created a task and get the ID of the task via `$taskId = $asana->getData()->id;` Next i have passed the $taskId and $projectId to assign the task to my particular project. Save the file now.

Setup the Webhook in CloudwaysBot

CloudwaysBot supports custom APIs and I will now create a webhook for the index.php file. I will use the the staging URL that is located in the Application Access Details tab.

Go to CloudwaysBot from the top navigation menu, click on the channels tab and then click the Add Channel button.

Select the API option from the drop down list.

Enter the complete URL of the index.php, set the Name of the channel and the status to Active.

Finally select the server and application alerts that you wish to send to Asana.

Now comes the exciting part. Click on the Save and Test channel button. The CloudwaysBot will send a test notification to the Asana project. If the notification goes through, the connection has been established.


In this article, I described how you could easily connect CloudwaysBot with Asana. This greatly streamlined project management tasks as all notifications generated by the CloudwaysBot are added as tasks to the Asana project. If you would like to contribute to the discussion or have a question, Leave a comment below!


Share your opinion in the comment section. COMMENT NOW

Shahroze Nawaz

Shahroze is a PHP Community Manager at Cloudways - A Managed PHP Hosting Platform. Besides his work life, he loves movies and travelling. You can email him at

Start Growing with Cloudways Today.

Our Clients Love us because we never compromise on these

Get Our Newsletter
Be the first to get the latest updates and tutorials.