Something wrong with create webhook, please help

Hi Asana,

I’m new in webhooks generally.

I have problem with CreateWebhook, i tried install Asan php sdk to Lumen framework (installed okay).
Token created in console (created app and there created token) - looks ok

Did this steps:

$client = Client::accessToken(‘token’);
$result = $client->webhooks->createWebhook([
‘resourse’ => ‘xxxxx’, //project_id got from url “app.asana .com/0/xxxxx/list”
‘target’ => ‘mydomain/api/tasks’
],
[‘opt_pretty’ => ‘true’]
);
But each time got error “Invalid Request”

For this start to checking/debug Requests inside SDK how it works and found answer on request “this message (“You should specify one of resource”)”

Also tried using just Curl also problem
curl -H "Authorization: Bearer xxxxxxxxxxtoken
-X POST https://app.asana.com/api/1.0/webhooks
-d “resource=project_id”
-d “target=mydomian/api/tasks”

Error is:
“message”: “The remote server which is intended to receive the webhook responded with an incorrect status code: 405”

What i need from webhooks

  • Asana calls our system via webhook using “skinny” events (see Asana API docs).
  • These events are put into a queue (a table you will create).
  • We then pull the details (projects/tasks/assignments/status) of those queued skinny events using Asana REST API.
  • Data is stored in the database.
  • Events are CRUD on projects, tasks, users, etc.

What is wrong, what i do wrong, please help me with this…

p.s. sorry for my english

Thank you,
Taras

Hi,

In the documentation, did you read the part about the handshake mechanism? Your server might not be answering properly to the handshake Asana sends.

Hello Bastien_Siebman,

Thank you for answer, sorry for long response.
How I can check handshake mechanism from my server?
Can you give some link to doc, will be good with some example?

Thank you,
Taras

Here you go the official doc on handshake

I found info that need send Hook-Secret back

I did it like that ( but i think request don’t come here and lost somewhere with error 405)
“The remote server which is intended to receive the webhook responded with an incorrect status code: 405”

Maybe you give some advice about error 405?

$headers = apache_request_headers();

    // if headers contain X-Hook-Secret, we need to answer with 200

    if (array_key_exists('X-Hook-Secret', $headers)) {

        $xHookSecret = $headers['X-Hook-Secret'];

        // header needs to be resent

        header('X-Hook-Secret: ' . $xHookSecret);

        header("HTTP/1.1 200 OK");

        exit;

    }

Did you try contacting your own server using Postman for example?

Hi Guys,

Sorry for delay, was some problems.

Yes tried with postman, same error 405
What means 405?

In right side you can see full request

It looks like your own server answered 405 to Asana when they tried to initiate the discussion. Correct @Phil_Seeman ?

@Phil_Seeman
@Bastien_Siebman

Guys help me please :slight_smile: any exampels or like this will be good

I don’t have any example. Did you fully read the documentation?

Yes, I concur with @Bastien_Siebman.

When you initiate the webhook creation request, Asana sends a handshake request to your designated endpoint (in your case, that’s the asana.truetime.app… URL). It seems that endpoint is not set up to be able to properly handle that request and so your server sends back a 405 response.

The HyperText Transfer Protocol (HTTP) 405 Method Not Allowed response status code indicates that the server knows the request method, but the target resource doesn’t support this method.

I don’t code in PHP so I’m afraid I don’t have any specific example code I could supply you with.

1 Like

Hi Guys,

Yes you are right problem was with server. Thank you for help.

Other question: I just added new task and assign new guy to this task. But webhook returned me 4 objects (also new task id not there, new task id is 1201860296330111 but not in this list).
Can you help me understand how i should understand what was change and waht request send to API for get more details.
I mean did two things but returned 4 objects.

Thank you very much

{
“events”: [
{
“user”: {
“gid”: “1201513736066267”,
“resource_type”: “user”
},
“created_at”: “2022-02-21T15:05:34.763Z”,
“action”: “added”,
“parent”: {
“gid”: “1201513888330921”,
“resource_type”: “project”
},
“resource”: {
“gid”: “1201855282391067”,
“resource_type”: “task”,
“resource_subtype”: “default_task”
}
},
{
“user”: {
“gid”: “1201513736066267”,
“resource_type”: “user”
},
“created_at”: “2022-02-21T15:05:35.030Z”,
“action”: “changed”,
“resource”: {
“gid”: “1201855282391067”,
“resource_type”: “task”,
“resource_subtype”: “default_task”
},
“parent”: null,
“change”: {
“field”: “followers”,
“action”: “added”,
“added_value”: {
“gid”: “1201513888300848”,
“resource_type”: “user”
}
}
},
{
“user”: {
“gid”: “1201513736066267”,
“resource_type”: “user”
},
“created_at”: “2022-02-21T15:05:35.030Z”,
“action”: “changed”,
“resource”: {
“gid”: “1201855282391067”,
“resource_type”: “task”,
“resource_subtype”: “default_task”
},
“parent”: null,
“change”: {
“field”: “assignee”,
“action”: “changed”,
“new_value”: {
“gid”: “1201513888300848”,
“resource_type”: “user”
}
}
},
{
“user”: {
“gid”: “1201513736066267”,
“resource_type”: “user”
},
“created_at”: “2022-02-21T15:05:35.046Z”,
“action”: “added”,
“resource”: {
“gid”: “1201860394847802”,
“resource_type”: “story”,
“resource_subtype”: “assigned”
},
“parent”: {
“gid”: “1201855282391067”,
“resource_type”: “task”,
“resource_subtype”: “default_task”
}
}
]
}

These events are about a different task, 1201855282391067 (are you sure 1201860296330111 is the right task ID #?). They’re telling you, in order:

  • Task 1201855282391067 was added as a new task
  • That task had a collaborator (follower) added to it (that being user 1201513736066267)
  • That task was assigned to user 1201513888300848
  • A story was added to that task, recording the task assignment

Many thanks for answer.

1201855282391067 it’s task but it was created before (yesterday).

It’s was created new task 1201860296330111 (today) and assign user (btw i think it’s not a webhook issues, maybe i just can’t understand how it work all together)

maybe you have some real examples for understand how it work or something like that.

Sorry if boring just first time woking with Asana :slight_smile:

Thank you,
Taras

HI
@Bastien_Siebman and @Phil_Seeman

How get only {“events”…} request from webhook?

For now my webhook return me full result like:

POST /api/addtasks HTTP/1.1
Accept-Encoding: identity
Authorization:
Connection: close
Content-Length: 867
Content-Type: application/json
Host: asana.truetime.app
User-Agent: Asana
X-Asana-Request-Signature: 3b84306b79be810c618fab1a82c2d026dc3af76dbabce8d7eb1b6ddb636f8841
X-Hook-Signature: 3b84306b79be810c618fab1a82c2d026dc3af76dbabce8d7eb1b6ddb636f8841
X-Https: 1

{“events”:[{“user”:{…

Thank you very much,
Taras

I’m not sure exactly what you’re asking…

The elements you show in your screenshot are HTTP headers, which are a core part of an HTTP request and response; there’s no way to not have them be there.

Okay, so how to work with json string?
How a can get it from this full response?
For me needs a json data only.

So i should somehow parse this response, remove http and get only json string?

My question how i can get only json string (http info before jdon not needed for me)

Sorry for boring

Thank you very much

That aspect of it is dependent on php which I’m afraid I don’t know so can’t help you with that, sorry.

Okay will think about this.

But to be honest very weired, Api return just json format.

But webhook return this everything, if needs only json for work with data

Hi Guys,

@Phil_Seeman @Bastien_Siebman
Can you please give doc url to handle webhook request, I mean what is story, section etc… ?

I need it to understand how to correctly check and save it to db (i mean i did one action, but webhook returned 2+ results)
Api is okay, working well, just need to understand webhook answer.

Thank you,
Taras