API, custom fields interaction

Hi there,

I’m wondering if this would be possible using the API:

IF = x, THEN mark task complete


IF task is marked complete THEN = x

The reason being is that our organisation uses a specific type of project tracking, and we use custom fields to make items complete. I’d love this to be reflected in the task and vice versa.


Sorry, my syntax was lost there

IF custom_field = x THEN task = completed

IF task = completed THEN custom_field = x

Hey @Alex_Beck

Yes you are able to do this using the API. you can use webhooks to track the changes in a project and update the task accordingly.

1 Like

Great news! Thanks! Do you know of any example scripts that do something similar using custom fields. I’m still learning all this stuff.

What language do you use?

Cc. @Bastien_Siebman could you help with your program for new devs on asana api?

1 Like

I’m using Python! :slight_smile:

You are using GitHub - Asana/python-asana: Official Python client library for the Asana API v1 right? If not, you should :stuck_out_tongue: Tell us if you need more help!

1 Like

Yes, I am! I was just hoping there was an example script using webhooks around that I could learn from. :slight_smile: Not to worry, though. I’ll keep experimenting!

Do you want my code in PHP to help a little bit?

1 Like

I’d love to look at it!

Hey, @Alex_Beck,

We in Developer Relations at Asana are working on creating some example scripts over the next few months to help flesh out how some of these sorts of workflows could be made. One or more with webhooks is definitely on the radar. This script isn’t perfect (there’s some multiple-signal-asynchronous-shutdown stuff that could be better) but it’s a neatened-up iteration of a script I’ve been using for a while when people ask “What do the events for XYZ” look like.

It creates a Flask app that listens for the webhook handshake and answers it; then any incoming webhook events are logged to the command line, pretty much the minimum app that does something with webhooks :slight_smile: The basics of this are in the receive_webhook function towards the bottom of the file.

It also has some convenience around listing, creating, and deleting the webhook just to make all the params clear - most of the rest of the file. I tried to make the code somewhat readable, so I hope it’s pretty easy to follow.

It uses ngrok to avoid the “I have to have a server that is resolvable via DNS on the Internet” issue, which is fine for experimentation, but we recommend doing it “right” with your own DNS-findable server for production use, since ngrok is a “man in the middle” in this setup. This is also why it recommends using a temporary PAT which you can revoke when you’re done. I suspect ngrok will take down old connections from time to time as well, causing this to break if it’s long-running.

Cheers, and if you have any questions or suggestions for changes before we publish these generally I’d love the feedback!

Check it out on Github

1 Like