Help with Webhooks filters

Hi there,

I’m new to all of this so I apologize if my question is too obvious!

I’m looking to create a webhook while applying filters but I am not 100% sure how to pass the filter options. I’m in node.js using the asana-node wrappers.

const asana = require('asana');

I am successfully getting a handshake and a stream of events but I can never create the webhook with filters. Should I pass the filter as opt_fields? Can someone help me getting the syntax right here?

await client.webhooks.create(resourceId, callbackURL);

Also, are teams and/or workspace available for webhooks? It would be great to get updates on high-level stuff such as when a project is added to a workspace, team, or portfolio for example.

Thanks in advance!

Pedro

Hi Pedro,

I might be wrong, and @Phil_Seeman the webhook expert will correct me, but I believe you need to create a webhook on some objects (like a project or a task) and then it is up to you to filter events on your side… So you’ll receive a s**t load of events and then you do the filtering in your server.

Ah, I was hoping that I could limit the amount of data that my server is receiving.

Any chance for webhooks for team, portfolios, or workspace?

In the API documentation they mention a filtering though :slight_smile:

This can be a lot of data, some of which might not be relevant to a particular integration, so Asana’s webhooks have a filtering feature which allows integrations to specify only the types of changes that they care about. By specifying the list of WebhookFilters on webhook creation an integration can select just the subset of events it wants to receive. When filters are specified on the webhook events will only be delivered if they pass any of the filters specified when creating the webhook.

Yes I just saw! Never used it, @Phil_Seeman will be able to help.

And you can see there that there are webhooks for team, portfolios and workspaces.

I figure it out! I want to learn more about the top-level scope webhooks.

await client.webhooks.create(resourceId, callbackUrl, {
    filters: [
      {
        resource_type: 'task',
        action: 'changed',
        fields: ['custom_fields'],
      },
    ],
  });

When I try to establish a webhook a high scope resource such as team, portifolio or workspace I get a Error: Forbidden.

Do I need to pass a specific filter to be able to access these resources? All I need is to know when a project is created within a portfolio or team.

Cheers,

Yes, exactly correct! The API team is concerned that a high-level webhook with no filter would produce a potential avalanche of events (and a drag on the system), so to prevent that, above a project, you have to include one of these filters, by my understanding:

It sounds like you can just use

"resource_type": "project", "action": "added"

3 Likes

thanks, @Phil_Seeman, that was incredibly helpful.

I’m experimenting with webhook on Portfolios. When filtering by "resource_type": "project", "action": "added" I noticed that I also get an " action: added" event whenever I remove a project from a portfolio.

I just wanted to put this out there for future implementation for the API. Should I start a new topic about this?

I would definitely recommend that - it sounds like a bug to me. (But put it in this section, not the Report a Bug section, as the Asana API team just monitors this section.)

Thanks Phil. I might make some more testing though. It could be a delayed event.

1 Like