Asana Webhooks for task creation

Hi, i am trying to create a webhook that activates when a new task is created, i already create the webhook, but when a create a task it won’t activate, i don’t need a full solution, i just need to someone to point me in the right way.

Did you fully read Build an app with Asana?

Especially
When a webhook is created, we will send a test POST to the target with an X-Hook-Secret header as described in the Resthooks Security documentation. The target must respond with a 200 OK and a matching X-Hook-Secret header to confirm that this webhook subscription is indeed expected.

1 Like

@Bastien_Siebman

When I tried to create the webhook after creation of task I got 2 WebHooks. Can you please tell me that why I got 2 webhooks ?

So you receive the same callback twice after every task update?

Yeah. Every time I get multiple webhook with same response for one task creation. Also I found new issue that when I add any task in asana than in webhook I am not getting any events that relates with “task added”. I only get “task changed”. Can you please suggest me that what should I do with webhook and what is the ideal way to use webhook ?

Re. the multiple webhooks issue - do the multiple webhooks on the same task have the same timestamp or different timestamps? If the timestamps are different, that’s probably expected behavior - see Webhooks, duplicate events - #7 by Jeff_Schneider.

@Phil_Seeman I have checked the events and they are seems like same time stamp and I have also added new task in the project but it was giving last added task web hooks not the current added. Can you please let me know why it behaves like this ?

Can you post a couple of representative samples of what you’re getting back?

@Phil_Seeman Even in latest one, after creating webhook for project, I can get response for the first task only. When I add second task than I did not get the response. I can get response of first task only. This thing I have to do all the time to get new task from asana I have to delete the webhook.

I just tested again and I can create several tasks in a project and I receive a webhook for each, not just the first one.

The only thing I can think of is, are you returning an “OK” (200) response when you receive a webhook, and also are you adding an an “X-Hook-Signature” header in your response with the X-Hook-Signature value that you received in the webhook? I’m not actually sure whether setting that header is necessary or not, but I do it and my webhooks are working properly.

Here I am returning like this :

$xHookSecret = $this->request->getHeaderLine(‘X-Hook-Secret’);
if ($xHookSecret) {
header('X-Hook-Secret: ’ . $xHookSecret);
header(“HTTP/1.1 200 OK”);
exit;
}

Please let me know if it is wrong.

X-Hook-Secret is only used when initially creating the webhook, so your code is good for that scenario. But after the webhook is successfully created and you receive webhook messages, each of those contains an X-Hook-Signature header and you should return that value and 200 just like you’re returning X-Hook-Secret and 200 in the initial webhook creation.

So you are trying to say that in every response , I need to send X-Hook-Signature back to asana as resposne when I get webhook of task creation ?

You definitely need to send back a 200/OK from every webhook you receive. The official webhook documentation doesn’t say you need to send back the X-Hook-Signature as well, but someone here on the forum said you did, so I do, and my webhooks are working properly. Not sure I tried without the X-Hook-Signature but add it and see if that helps you.

@Hardik just a 200 response to inform asana that you received the webhook. As @Phil_Seeman mentioned, if you not respond with 200 Asana will keep trying post you the same events.

Hello,

Here I have received multiple webhooks for the same event not two or third time but multiple times and I have checked the X-Hook-Signature and all the time its the same. How can I check my response that I am giving to asana because in my code I have put error log and its an empty. So Is there any way to check response that we give it to asana.

Also in my local machine I recieve only one time while on server I get multiple times so I can’t understand the issue. If you have idea than please help me.

Webhooks that I received:
1.
{“events”:[{“resource”:705160141637192,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:02:18.446Z”,“parent”:null},{“resource”:705160445261410,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:02:12.792Z”,“parent”:705160141637192},{“resource”:705160445261412,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:02:18.457Z”,“parent”:705160141637192},{“resource”:653571698704031,“user”:46483660361160,“type”:“project”,“action”:“changed”,“created_at”:“2018-06-11T02:03:04.336Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“added”,“created_at”:“2018-06-11T02:03:04.317Z”,“parent”:653571698704031},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:05.750Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:06.018Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:06.333Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:08.325Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:08.954Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:09.552Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:10.158Z”,“parent”:null},{“resource”:705160445261413,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:03:04.320Z”,“parent”:705160141637193},{“resource”:705160445261413,“user”:46483660361160,“type”:“story”,“action”:“removed”,“created_at”:“2018-06-11T02:03:05.685Z”,“parent”:705160141637193},{“resource”:705160445261415,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:03:05.752Z”,“parent”:705160141637193},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:11.496Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:12.584Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:15.049Z”,“parent”:null},{“resource”:705160445261417,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:03:15.061Z”,“parent”:705160141637193},{“resource”:705160141637192,“user”:46483660361160,“type”:“task”,“action”:“deleted”,“created_at”:“2018-06-11T02:03:58.611Z”,“parent”:null},{“resource”:705160141637192,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:58.620Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“deleted”,“created_at”:“2018-06-11T02:04:02.239Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:04:02.246Z”,“parent”:null},{“resource”:705135298928102,“user”:46483660361160,“type”:“task”,“action”:“deleted”,“created_at”:“2018-06-11T02:04:07.253Z”,“parent”:null}]}

{“events”:[{“resource”:705160141637192,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:02:18.446Z”,“parent”:null},{“resource”:705160445261410,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:02:12.792Z”,“parent”:705160141637192},{“resource”:705160445261412,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:02:18.457Z”,“parent”:705160141637192},{“resource”:653571698704031,“user”:46483660361160,“type”:“project”,“action”:“changed”,“created_at”:“2018-06-11T02:03:04.336Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“added”,“created_at”:“2018-06-11T02:03:04.317Z”,“parent”:653571698704031},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:05.750Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:06.018Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:06.333Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:08.325Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:08.954Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:09.552Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:10.158Z”,“parent”:null},{“resource”:705160445261413,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:03:04.320Z”,“parent”:705160141637193},{“resource”:705160445261413,“user”:46483660361160,“type”:“story”,“action”:“removed”,“created_at”:“2018-06-11T02:03:05.685Z”,“parent”:705160141637193},{“resource”:705160445261415,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:03:05.752Z”,“parent”:705160141637193},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:11.496Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:12.584Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:15.049Z”,“parent”:null},{“resource”:705160445261417,“user”:46483660361160,“type”:“story”,“action”:“added”,“created_at”:“2018-06-11T02:03:15.061Z”,“parent”:705160141637193},{“resource”:705160141637192,“user”:46483660361160,“type”:“task”,“action”:“deleted”,“created_at”:“2018-06-11T02:03:58.611Z”,“parent”:null},{“resource”:705160141637192,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:03:58.620Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“deleted”,“created_at”:“2018-06-11T02:04:02.239Z”,“parent”:null},{“resource”:705160141637193,“user”:46483660361160,“type”:“task”,“action”:“changed”,“created_at”:“2018-06-11T02:04:02.246Z”,“parent”:null},{“resource”:705135298928102,“user”:46483660361160,“type”:“task”,“action”:“deleted”,“created_at”:“2018-06-11T02:04:07.253Z”,“parent”:null}]}

And my response to Asana is as below:

header('X-Hook-Signature: ’ . $xHookSignature);
header(“HTTP/1.1 200 OK”);
exit;

Please let me know I I am doing any wrong here.

Thanks
Hardik Patel

is it a must? or the webhook won’t be created?

I guess yes, this is what the documentation says.