Getting multiple events in webhook payload

Hello! I created a webhook for a project in a workspace using this req body:

{
    "data": {
        "resource": "<resource_gid>",
        "filters": [
            {
                "resource_type": "workspace_membership",
                "action": "added"
            },
            {
                "resource_type": "workspace_membership",
                "action": "removed"
            },
            {
                "resource_type": "team_membership",
                "action": "added"
            },
            {
                "resource_type": "team_membership",
                "action": "removed"
            },
            {
                "resource_type": "project",
                "action": "added"
            },
            {
                "resource_type": "project",
                "action": "removed"
            },
            {
                "resource_type": "project",
                "action": "changed"
            },
            {
                "resource_type": "project",
                "action": "deleted"
            },
            {
                "resource_type": "project",
                "action": "undeleted"
            }
        ],
        "target": "<target_url>"
    }
}

I’m currently testing the webhook by adding project to a workspace. I noticed there’s multiple events being returned in the webhook response:

{
  "events": [
    {
      "user": {
        "gid": "<gid>",
        "resource_type": "user"
      },
      "created_at": "2024-12-03T18:29:50.851Z",
      "action": "added",
      "resource": {
        "gid": "<gid>",
        "resource_type": "project"
      },
      "parent": {
        "gid": "<gid>",
        "resource_type": "team"
      }
    },
    {
      "user": {
        "gid": "<gid>",
        "resource_type": "user"
      },
      "created_at": "2024-12-03T18:29:50.852Z",
      "action": "added",
      "resource": {
        "gid": "<gid>",
        "resource_type": "project"
      },
      "parent": {
        "gid": "<gid>",
        "resource_type": "workspace"
      }
    }
  ]
}

Why is there 2 events being returned other than just 1?

In addition, since these events are not consolidated, because the response returns 2 events this is causing us to make redundant API calls to FETCH project details from Asana. @Phil_Seeman

Hi @User_1 ,

It’s not uncommon for Asana webhooks to report on multiple events that occur on the same resource.

In your case, the key is in looking at the parent data: the first event is reporting that the project was added to a particular team, the second that it was added to a particular workspace.

You’ll have to account for this in your code. For example, in this case you might want to check the parent’s resource_type and ignore it if it equals “team”.

1 Like

Amazing! Thank you so much @Phil_Seeman !

1 Like

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