Replace() Error Using set_parent_for_task

Hi! I’m attempting to leverage the set_parent_for_task function in order to duplicate a subtask from one task to another. In an ideal world, I would just create the subtask fresh, but the subtask relies on recurring daily which I can’t access through the API. Here’s my python code:

result = client.tasks.duplicate_task(templatesubtask, {‘include’:[“assignee”,“subtasks”,“projects”,“dependencies”,“dates”,“parent”], ‘name’:‘Walk or Play Yard Time’}, opt_pretty=True)

api_response = client.tasks.set_parent_for_task({‘data’: {‘parent’:parent_gid, ‘insert_before’: None}}, result[‘new_task’][‘gid’], opt_pretty=True)

And here’s the error:

Traceback (most recent call last):
File “C:\Users\admin\Documents\fcasasana\dupliatetest.py”, line 268, in
api_response = client.tasks.set_parent_for_task({‘parent’:parent_gid, ‘insert_before’: None}, result[‘new_task’][‘gid’], opt_pretty=True)
File “C:\Users\admin\anaconda3\lib\site-packages\asana\resources\gen\tasks.py”, line 427, in set_parent_for_task
path = “/tasks/{task_gid}/setParent”.replace(“{task_gid}”, task_gid)
TypeError: replace() argument 2 must be str, not dict

For reference, this works fine if I do it through the “Try It” on Asana’s developer documentation site, so I’m assuming my syntax is the issue versus the tasks themselves. Thanks in advance! And if someone tells me that recurring subtasks is in the works through the API, I would be forever grateful!

Are you sur templatesubtask is a string?

Hi @Clare_Specht,

I think you are looking at the wrong sample code. It looks like you are trying to make the request with the syntax of the new python client library (v5.X.X).

Judging from your code, you are using our python client library version v3.X.X. To make a request to our Set the parent of a task endpoint with the python-asana library version 3.X.X you can do the following:

import asana

client = asana.Client.access_token("<YOUR_ASANA_PERSONAL_ACCESS_TOKEN>")
task_gid = "<TASK_GID>"
result = client.tasks.set_parent_for_task(task_gid, {'parent': '<PARENT_GID>'})

Notice that the task_gid comes first then the request body

This is what the function looks like for this method in our python-asana v3.2.2

TIP: To look at the sample code for the old client library use the drop down in the developer docs and select on “PYTHON-SDK-V3”


If you are interested in trying our python-asana v5.X.X client library, here would be how you would make that request:

import asana
from asana.rest import ApiException
from pprint import pprint

configuration = asana.Configuration()
configuration.access_token = "<YOUR_PERSONAL_ACCESS_TOKEN>"
api_client = asana.ApiClient(configuration)

# create an instance of the API class
tasks_api_instance = asana.TasksApi(api_client)
body = {"data": {"parent": "<PARENT_GID>"}}
task_gid = "<TASK_GID>"
opts = {}

try:
    # Set the parent of a task
    api_response = tasks_api_instance.set_parent_for_task(body, task_gid, opts)
    pprint(api_response)
except ApiException as e:
    print("Exception when calling TasksApi->set_parent_for_task: %s\n" % e)

2 Likes

That did it! I didn’t realize there were differences between python versions. That dropdown should save me a lot of headache moving forward. Thank you!

Cool. Glad to that this solved your issue and apologies for the confusion. We plan on outlining this more when we write our migration guide for users who like to migrate from python-asana v3.X.X to v5.X.X.

@John_Vu can perhaps weigh in but I don’t think API support for recurring tasks is currently on their roadmap for the near future.

I don’t think we currently support it. cc: @John_Baldo

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