How to determine when a task changes sections?

My goal is to change the assignee of a task depending on what section the task is moved to.

Changing the assignee of the task isn’t hard. But it does not seem like there is a nice way to determine when a task changes the section it is in.

So far the best I have come up with is “stories” . Something along the lines of

For each event, if a story was added in regards to “section_changed” continue with the code. I found a post by a leader explaining what stories are. In the users eyes they are basically those comments that identify changes to the task.

I will continue to try and find a good way to approach this, but any input is welcome.

1 Like

Hi @Jeremy_Labelle,

From the code snippet in your post, I assume you’re wanting to do this programmatically using the API, not in the UI using rules? (If so, I want to move your post to the API forum section.)

1 Like

Yes I am trying to achieve this programmatically using the API. If there is a more appropriate section please move it there, thank you.

Moved!

I can offer two solutions:

  1. If you can store values on your end, then record the section for the tasks within the project. Then use a project-level webhook to capture changes on those tasks; when you get a change event, read the task, check its current section against the value in your data store to determine if it’s changed.

  2. Use the story-based approach you outlined. If you use this approach, just be cognizant of story consolidation which means you aren’t guaranteed to get every single change on a task.

2 Likes

I’ve picked this back up and I’m running into a road block. It doesn’t seem like stories reliably track section changes? At least, a section change does not hit my project level webhook, but any field updates do hit it.

I was considering tracking each sections task list and executing my logic when the list for a section changes. But I’m looking for the logic to execute the moment the task changes sections, I don’t want to periodically compare the lists.

Any other recommendations on how I can get a section change to trigger my webhook?

Two things:

  • The project-level webhook doesn’t have anything to do with the Stories object.
  • To get section changes on a project-level webhook, set a filter for those explicitly. Here is my project-level webhook in Flowsana:
    filters = new[]
    {
        new WebhookFilter { resource_type = "task", action = "added" },
        new WebhookFilter { resource_type = "task", action = "changed" },
        new WebhookFilter { resource_type = "task", action = "removed" },
        new WebhookFilter { resource_type = "section", action = "added" },
        new WebhookFilter { resource_type = "section", action = "changed" },
        new WebhookFilter { resource_type = "section", action = "removed" }
    }
1 Like

When using the filter detailed above. I get an error saying the fields cannot be null. Is that your exact filter? or do I need to declare fields being changed?

This is actually my exact C# code (the above was a bit different but functionally the same):

            var newWebhook = new AsanaProjectWebhook
            {
                resource = projectId,
                target = "https://[my endpoint]?code=[my code]&clientId=default" + "&flowsanaId=" + flowsanaUserId + "&resource=" + projectId + "&type=Project"
            };
            newWebhook.filters[0] = new WebhookFilter { resource_type = "task", action = "added" };
            newWebhook.filters[1] = new WebhookFilter { resource_type = "task", action = "changed" };
            newWebhook.filters[2] = new WebhookFilter { resource_type = "task", action = "removed" };
            newWebhook.filters[3] = new WebhookFilter { resource_type = "section", action = "added" };
            newWebhook.filters[4] = new WebhookFilter { resource_type = "section", action = "changed" };
            newWebhook.filters[5] = new WebhookFilter { resource_type = "section", action = "removed" };

            string serialized = JsonConvert.SerializeObject(newWebhook);
            serialized = "{\"data\": " + serialized + "}";
            StringContent stringContent = new StringContent(serialized);
            httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", dataService.GetOAuthToken(refreshAuthToken));
            var response = await httpClient.PostAsync("https://app.asana.com/api/1.0/webhooks", stringContent);

2 Likes

That is very helpful, I was able to establish my webhook with those filters shown above.

However, my webhook doesn’t seem to trigger for them? I’m only receiving events when fields on a task are changed, or added. Not removed.

This is what my webhook looks like getting it with a postman request, i’ve replaced my target with a placeholder. Any insight is helpful.

 "data": {
        "gid": "1209826125588615",
        "resource_type": "webhook",
        "resource": {
            "gid": "805842064117898",
            "resource_type": "project",
            "name": "Current Sprint"
        },
        "target": "https://asi.webhook.placeholder",
        "active": true,
        "is_workspace_webhook": false,
        "failure_deletion_timestamp": null,
        "created_at": "2025-03-28T13:48:08.203Z",
        "last_failure_at": null,
        "last_failure_content": "",
        "last_success_at": "2025-03-28T13:49:07.753Z",
        "delivery_retry_count": 0,
        "next_attempt_after": null,
        "filters": [
            {
                "resource_type": "task",
                "resource_subtype": null,
                "action": "added",
                "fields": null
            },
            {
                "resource_type": "task",
                "resource_subtype": null,
                "action": "changed",
                "fields": null
            },
            {
                "resource_type": "task",
                "resource_subtype": null,
                "action": "removed",
                "fields": null
            },
            {
                "resource_type": "section",
                "resource_subtype": null,
                "action": "added",
                "fields": null
            },
            {
                "resource_type": "section",
                "resource_subtype": null,
                "action": "changed",
                "fields": null
            },
            {
                "resource_type": "section",
                "resource_subtype": null,
                "action": "removed",
                "fields": null
            }
        ]
    }
}

Can you say more specifically what you mean here? Do you mean you’re blanking out the value of a custom field on a task? Or you’re removing a custom field from a project? Or…?

I mean I’m adding a value to a field, changing a value in a field with an existing value, and removing the value from a field. Not adding or removing entire fields.

Nevermind? There’s been some weird stuff going on with residual webhooks on my site. So I’m gonna chalk it up to some weird discrepancies. because with that filter you provided, I receive requests when tasks change sections.

Thank you for all your assistance!

Excellent news; glad to help!

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