I have triple checked the project ID and the section ID as well but I constantly get the following error.
{"errors":[{"message":"No matching route for request","help":"For more information on API status codes and how to handle them, read the docs on errors: https://asana.com/developers/documentation/getting-started/errors"}]}
Can anyone help me with this, cant figure out what I’m doing wrong?
That error indicates not that there is an issue with the IDs you’re passing but that there is a problem with the endpoint or the syntax of the request itself. Your best best for assistance therefore is to post the actual code you’re using to make the request.
str(item) is the tasks ID, I have also tried to hardcode a specific ID into the request endpoint and the result is the same. I used this topic to help me.
@Phil_Seeman + @Bastien_Siebman - not to re-open an old thread, but wanted to have a bit of a conversation about this…
With “sections” now being so critical within Asana, I’m a bit shocked that there’s no way to update a section via the “update task” API endpoint. A section now is essentially like a custom field of sorts.
Is there any way to update a task’s section via the API along with other components (like task status/custom fields/assignee) without using an entirely different API request?
Unfortunately no. You can include a memberships property when initially creating as task and that defines the project(s) and section(s) to put that task into, But that’s only on task creation. For updating an existing task, you have to use a separate call/endpoint to move it to a different section (you can use either the POST /tasks/{task_gid}/addProject or POST /sections/{section_gid}/addTask endpoint).
Really appreciate the quick response and information, super helpful!
Gosh, I do hope they make updating it more core to the task update component with time, though I also understand it’s a bit tough as a task may contain multiple projects linked to it. It’s a tough one.
The membership bit is helpful to know re: task creation though!
At the very least, the API documentation should be updated to indicate this. There’s no indication of how you get and set sections in the places you’d expect to learn how. I’m using Ruby and there’s no code shown, you should indicate when things are not yet built or what’s going on with it in docs…
Can I ask why you’re taking that approach instead of the simpler solution - just one API call, no rules or custom fields needed - that’s described above here: Changing task section - #7 by Phil_Seeman
If anyone is interested, this can be achieved using the python API, code snippet below for implementation on a specific project:
# Initialise
api_client = authenticate_asana_client()
tasks_api_instance = asana.TasksApi(api_client)
sections_api = asana.SectionsApi(api_client)
section_id_dict = {'Section name': 'SECTION_ID'} # Lookup IDs for section of interest
project_tasks = get_all_asana_project_tasks()
# Loop though tasks in project
for task in project_tasks:
# Get task ID
task_gid = task["gid"]
# Get all details of task
task_details = tasks_api_instance.get_task(task_gid, {})
# Extract task name
full_task_name = task_details["name"]
# Extract date last modified
last_modified = task_details['modified_at']
last_modified = datetime.datetime.fromisoformat(last_modified.replace("Z", "+00:00"))
# Calculate date 3 months ago
utc = pytz.UTC # Get UTC timezone
three_months_ago = utc.localize(datetime.datetime.utcnow()) - datetime.timedelta(days=3*30)
# Select only tasks not modified in the past 3 months
if last_modified < three_months_ago:
# Loop through projects it is a member of
for project in task_details['memberships']:
# Proceed only for the 'Data Requests' project
if project['project']['name'] == 'Data Requests': # Select Data Requests
section_name = project['section']['name']
section_ID = project['section']['gid']
# If section is request, move to icebox
if section_name == 'Requests':
new_section_name = 'Icebox (Old requests)'
new_section_id = section_id_dict[new_section_name]
move_task_to_section(sections_api, task_details,
new_section_id,new_section_name)
def get_all_asana_project_tasks(
access_token="TOKEN",
project_id="PID",
):
"""
Given asana API access token and a project ID, return all tasks as a list of dicts.
"""
# Configure and authorise asana api
api_client = authenticate_asana_client(access_token)
tasks_api_instance = asana.TasksApi(api_client)
# Get all tasks from project
# Note project ID can be found in its URL
task_response = tasks_api_instance.get_tasks_for_project(project_id, {})
# Convert response into a list
all_tasks = []
for t in task_response:
all_tasks.append(t)
return all_tasks
def move_task_to_section(sections_api, task_details, new_section_id,new_section_name):
"""Move a task to a new section."""
opts = {
'body': {
'data': {
'task': task_details.get('gid')
}
}
}
sections_api.add_task_for_section(new_section_id, opts)
print(f"Moved task: {task_details['name']} to {new_section_name}")