Getting an error when trying to create a webhook via API for a workspace

Trying to create a webhook via API (POST Establish a webhook endpoint) for a Workspace based on added, changed, and removed actions. I’m met with a 400 error and am unsure what’s causing it.

request body:

{
  "resource": "1174208460831550",
  "filters": [
    {
      "resource_type": "workspace",
      "action": "added"
    },
    {
      "resource_type": "workspace",
      "action": "changed"
    },
    {
      "resource_type": "workspace",
      "action": "removed"
    }
  ]
}

the error message I’m getting 400:

{
  "errors": [
    {
      "message": "Could not interpret {\"data\": {\"resource\": \"1174208460831550\", \"filters\": [{\"resource_type\": \"workspace\", \"action\": \"added\"}, {\"resource_type\": \"workspace\", \"action\": \"changed\"}, {\"resource_type\": \"workspace\", \"action\": \"removed\"}]}} as an identifier in {\"data\": {\"resource\": \"1174208460831550\", \"filters\": [{\"resource_type\": \"workspace\", \"action\": \"added\"}, {\"resource_type\": \"workspace\", \"action\": \"removed\"}]}}.",
      "help": "For more information on API status codes and how to handle them, read the docs on errors: https://developers.asana.com/docs/errors"
    }
  ]
}```

Hi @User_1,

If you’re trying to create a webhook to capture when a workspace is added/changed/removed, that’s not supported by the Asana API.

If you’re trying to capture when a project is added/changed/removed within a workspace, then the resource_type in the filter needs to be project, not workspace.

Also, you’re missing the data wrapper around the request:

{
  "data": {
      "resource": "1174208460831550",
      "filters": [
        {
          "resource_type": "workspace",
          "action": "added"
        },
        {
          "resource_type": "workspace",
          "action": "changed"
        },
        {
          "resource_type": "workspace",
          "action": "removed"
        }
      ]
  }
}

Does this info help?

Perfect! Thank you so much @Phil_Seeman for the quick response! Do you happen to know if trying to capture when users and teams have been added/changed/removed within a workspace is possible?

2 Likes

Teams should be possible, though I don’t think I’ve tried it.

Users per se isn’t available but Workspace memberships should be, which is basically the same thing.

Thank you so much for the help here @Phil_Seeman ! Currently trying to create a webhook for Teams in a workspace, but I seem to be getting the same error as before. Here’s the request body:

{"data": {"resource": "12345678", "filters": [{"resource_type": "team", "action": "added"}, {"resource_type": "team", "action": "changed"}, {"resource_type": "team", "action": "removed"}]}}

error message:

{"errors": [{"message": "Could not interpret {\"data\": {\"resource\": \"1203803514816598\", \"filters\": [{\"resource_type\": \"team\", \"action\": \"added\"}, {\"resource_type\": \"team\", \"action\": \"changed\"}, {\"resource_type\": \"team\", \"action\": \"removed\"}]}} as an identifier in {\"data\": {\"resource\": \"1203803514816598\", \"filters\": [{\"resource_type\": \"team\", \"action\": \"added\"}, {\"resource_type\": \"team\", \"action\": \"changed\"}, {\"resource_type\": \"team\", \"action\": \"removed\"}]}}.", "help": "For more information on API status codes and how to handle them, read the docs on errors: https://developers.asana.com/docs/errors"}]}

Not sure what could be causing this error.

Fixed it! I wasn’t passing in the content-type header!

Is there documentation on whitelisted filters for certain objects or does the “'added”, “changed”, “removed” apply to them all?

Tried making a webhook for users in a workspace with this request body (resource is the gid of a user in workspace):

{"data": {"resource": "12345678", "target": "<target_uri>", "filters": [{"resource_type": "team", "action": "added"}, {"resource_type": "team", "action": "changed"}, {"resource_type": "team", "action": "removed"}]}}

and getting this error response:

{"errors": [{"error": "invalid_filters_for_larger_scoped_webhooks", "message": "Webhooks for larger scoped resources must have at least one filter and all filters must be in our whitelist.", "user_message": "Webhooks for larger scoped resources must have at least one filter and all filters must be in our whitelist.", "help": "For more information on API status codes and how to handle them, read the docs on errors: https://developers.asana.com/docs/errors"}]}

am I setting the resource incorrectly @Phil_Seeman ?

I’m confused - did you post the wrong screenshot in your last post above? It shows teams but you mentioned users?

Sorry, meant to say team

Were you able to get teams added/changed/removed working or no? You said “fixed it” but then mentioned getting an error.

FWIW I don’t believe teams is supported for workspace-level webhooks; I had forgotten about this thread:

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