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'],
      },
    ],
  });
1 Like

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

@pedro_Botsaris , Thank you for sharing. Do you have any way to monitor only some custom fields but not all the custom_fields.

No, this isn’t available in the API.

1 Like

Hi there, super new to the whole webhook world, but I am trying to create a webhook for my asana portfolio and I am getting stuck on what the “Resource Type” and “Resource Subtype” should be. I want to pull project data such as plans vs actual end date.

Hopefully that makes sense.

Any ideas?

Thank you!

Alex

Hi @alex59,

I haven’t personally done anything with portfolios yet, but according to the API docs, a webhook on a portfolio will only get you events when a portfolio is added or deleted, so that won’t help in your case.

I think instead what you may need to do is use the portfolio_membership endpoint to get a list of the projects in your desired portfolio, then set a workspace webhook on the containing workspace which will get you events when any of the projects in that workspace change, and when you get a project event, see if the project is in the desired portfolio using the list you got from the membership call. I know that seems kind of inefficient but I’m not sure there’s another way to get what you want.

@Frederic_Malenfant @Bastien_Siebman @JFrentz you guys have any other thoughts on this?

1 Like