Webhook Creation Failure

Hello,

I am using following body for creating a new webhook but got the error: No matching route for request.

Body:
{
“data”: {
“target”: “Target URL”,
“resource”: “Project ID”,
“filters”: [
{
“action”: “changed”,
“resource_type”: “task”,
“resource_subtype”: “default_task”,
“fields”: “status”
}
]
}
}

Any help is greatly appreciated.

Hi @Yashwanth_Chakka and welcome!

This means that the URL you’re using for your endpoint is invalid; it doesn’t have anything to do with the body. Please post the URL you’re calling or the code you’re using to make the call - something that shows us the endpoint you’re trying to call.

I think you’re showing what you put for “Target”. I’m referring to the endpoint you tried to call in the Asana API to create the webhook.

It should be:
https://app.asana.com/api/1.0/webhooks

as shown here: Establish a webhook

Phil i realized there is a whitespace in URL. AFter i fixed it, i am getting a new error: The remote server which is intended to receive the webhook did not respond with the handshake secret…

I do see an attemp being made to hit my endpoint as i can see in the telemetry. But the JSON body is empty. Not sure if i have an control over this.

Yeah, the body they send back isn’t actually empty; it has an X-Hook-Secret value in it. You have to send that value back to them within a few milliseconds in order to establish the webhook. There’s no way around that requirement, I’m afraid.

Thanks Phil for being patient with me.
I did find the x-hook-secret in the header and i was able to parse it and extract it.
I made a Post request to https://app.asana.com/api/1.0/webhooks with header
Content-Type application/json
Authorization Bearer **************
X-Hook-Secret parsed text

Body is {} (empty no data)

I got 400 error You should specify one of resource

Your response is greatly appreciated

In my code and the the Asana client libraries, they send a specific response to the incoming webhook. I don’t think that’s what’s happening in your code but hard to tell as I can’t see the actual code.

I’m going to defer to the Asana support team here for further guidance. @John_Vu @AndrewWong could you perhaps help?

Phil, with no activity or no one responding, i feel like closing this thread and re-opening a new thread with targeted webhook question.

Thanks for the help

Hi @anon2981095,

The reason why you received the message: “The remote server which is intended to receive the webhook did not respond with the handshake secret.” is because your webhook server did not return a response with a 200 status code and a x-hook-secret in the request header.

See our example webhook code

Particularly this part when you make a POST /webooks call to our Establish a webhook endpoint Asana will make a POST call to your provided TARGET_URL with an empty response body and a header in the response that contains the x-hook-secret. Your app will need to store this x-hook-secret and also send a 200 status code back to Asana with that x-hook-secret in the response header.

This diagram in our developer docs shows how this flow works.

I think the reason why you are running into errors because you are making a:

I made a Post request to https://app.asana.com/api/1.0/webhooks with header
Content-Type application/json
Authorization Bearer **************
X-Hook-Secret parsed text

You shouldn’t need to make a post request you just need to respond to the initial POST request Asana sends to your webhook server’s target URL with a 200 status and the x-hook-secret in the response header i.e. this part in our example webhook code

1 Like

Thanks John. That really helped me. I was able to create a new webhook for a status field.

One last question: I want to create the webhook on trigger of a field near to projects. Its out of box field (not custom field). I m not sure how to find the schema name of this field.

Attaching image.

image

@anon2981095,

What you’re showing is not a custom field, it’s a section.

It’s not possible to set a webhook that triggers only when a task moves to one specific section; you’ll need to set a webhook on the project and when you get an event that the project changed, check the section yourself.

Thanks Phil. That makes total sense. Appreciate your patience in answering my novice questions and sorry for keep bugging you. I am new to Asana and learning stuff on building integrations.

As John helped, i was able to setup webhook on update of task status and i got 201 status created. I got webhook gid. However, when i update the status of task in that project, i dont see any event getting triggered and calling my target URL.

Do u know of any ways to monitor the telemetry activity of webhook? Or any ways to debug the webhook. Or did i miss any steps in turning on or configuring webhook.

Screenshot attached of new webhokk created successfully


image

Hi @anon2981095,

Our webhooks can be tricky to work with. My recommendation on learning how to establish the right webhook with filters that you want is to first establish a webhook with no filters at all then perform an action on a resource and observe what events you get. Then use this information from the events to create your filter(s).

Let’s take your ask for example: “when i update the status of task in that project, i don’t see any event getting triggered and calling my target URL”

Step 1: Establish a webhook with no filters and observe the events
EX: Webhook Request Body → this is basically saying give me all events that happen within a project (since tasks are a part of a project you will get events about tasks, the project itself, etc…)

{
  "data": {
    "resource": "<YOUR_PROJECT_GID>",
    "target": "<YOUR_TARGET_URL>"
  }
}

Step 2: Trigger something in that resource. Since we established a webhook to watch events that happen in a project resource we can try to mark a task as complete and seeing what events are being sent to your webhook server.
EX: Result

[
  {
    user: { gid: '<USER_GID>', resource_type: 'user' },
    created_at: '2023-09-06T17:07:12.000Z',
    action: 'changed',
    parent: null,
    change: { field: 'modified_at', action: 'changed' },
    resource: { gid: '<PROJECT_GID>', resource_type: 'project' }
  },
  {
    user: { gid: '<USER_GID>', resource_type: 'user' },
    created_at: '2023-09-06T17:07:11.913Z',
    action: 'changed',
    resource: {
      gid: '<TASK_GID>',
      resource_type: 'task',
      resource_subtype: 'default_task'
    },
    parent: null,
    change: { field: 'completed', action: 'changed' }
  },
  {
    user: { gid: '<USER_GID>', resource_type: 'user' },
    created_at: '2023-09-06T17:07:11.913Z',
    action: 'changed',
    resource: {
      gid: '<TASK_GID>',
      resource_type: 'task',
      resource_subtype: 'default_task'
    },
    parent: null,
    change: { field: 'completed_at', action: 'changed' }
  },
  {
    user: { gid: '<USER_GID>', resource_type: 'user' },
    created_at: '2023-09-06T17:07:12.003Z',
    action: 'added',
    resource: {
      gid: '<STORY_GID>',
      resource_type: 'story',
      resource_subtype: 'marked_complete'
    },
    parent: {
      gid: '<TASK_GID>',
      resource_type: 'task',
      resource_subtype: 'default_task'
    }
  }
]

Step 3: Pick out the event that you are interested in. In this case since we want to receive events about task being marked complete we probably want to look at:

  {
    user: { gid: '<USER_GID>', resource_type: 'user' },
    created_at: '2023-09-06T17:07:11.913Z',
    action: 'changed',
    resource: {
      gid: '<TASK_GID>',
      resource_type: 'task',
      resource_subtype: 'default_task'
    },
    parent: null,
    change: { field: 'completed', action: 'changed' }
  }

Step 4: Take this information and establish a new webhook just to filter for the event that you are interested in
EX: New webhook request body

{
  "data": {
    "resource": "<YOUR_PROJECT_GID>",
    "target": "<YOUR_WEBHOOK_URL>",
    "filters": [
      {
        "resource_type": "task",
        "action": "changed",
        "fields": [
            "completed"
        ]
      }
    ]
  }
}

Step 5: Test out the new webhook to see if the filter works → Mark another task as complete and see what event you get
EX: Response

[
  {
    user: { gid: '<USER_GID>', resource_type: 'user' },
    created_at: '2023-09-06T17:22:50.727Z',
    action: 'changed',
    resource: {
      gid: '<TASK_GID>',
      resource_type: 'task',
      resource_subtype: 'default_task'
    },
    parent: null,
    change: { field: 'completed', action: 'changed' }
  }
]

NOTE: this TIP doesn’t really work for higher level webhooks since we will force you to provide a filter when you try to establish a webhook at a higher level EX: → if you provide a WORKSPACE_GID as a value for resource when establishing a webhook we will ask that you provide a filter → in this case you might want to use this trick at a lower level to observe changes to a lower level resource than apply it to the workspace resource.

  • EX: If I want to get events about project name changes in a portfolio (we consider portfolios higher level webhook) I can do step 1 but for resource provide a PROJECT_GID → change name of project → look at event → go back and establish webhook with resource value as PORTFOLIO_GID → add filters about project name changes that I saw in the previous step.
2 Likes

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.