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)
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!
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:
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)
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.