I’m trying to post a table to a new task but get this error. It renders when I copy paste it the HTML code into any online HTML renderer. When I remove the table and put anything else the task gets correctly created. Otherwise I get this error:
HTTP response body: b'{"errors":[{"error":"xml_parsing_error","message":"XML is invalid","help":"For more information on API status codes and how to handle them, read the docs on errors: https://developers.asana.com/docs/errors"}]}'
using this code
def main():
create_task()
def create_task():
from test_interface.helpers.asana import create_asana_task
body = "<body><table> <tr><th>h1</th><th>h2</th></tr> <tr><td>Something else here</td><td>Something here</td></tr> </table></body>"
create_asana_task(body, 'Asana Task API')
configuration = asana.Configuration()
configuration.access_token = Config.ASANA_ACCESS_TOKEN
api_client = asana.ApiClient(configuration)
def create_asana_task(task_body_html: str, subject:str, assignee_id: str = "<censored>"):
# create an instance of the API class
tasks_api_instance = asana.TasksApi(api_client)
# Dynamically set due date to today + 7 days in (yyyy-mm-ddThh:mm:ss)
due_at = (datetime.datetime.now() + datetime.timedelta(days=7)).strftime("%Y-%m-%dT%H:%M:%S") + '+0000'
body = {"data": {
"name": subject,
"html_notes": task_body_html,
"assignee": assignee_id,
"projects": [Config.ASANA_LTI_PROJECT_ID],
"due_at": due_at,
"assignee_section": "<censored>"
}} # dict | The task to create.
opts = {
'opt_fields': "actual_time_minutes,approval_status,assignee,assignee.name,assignee_section,assignee_section.name,assignee_status,completed,completed_at,completed_by,completed_by.name,created_at,created_by,custom_fields,custom_fields.asana_created_field,custom_fields.created_by,custom_fields.created_by.name,custom_fields.currency_code,custom_fields.custom_label,custom_fields.custom_label_position,custom_fields.date_value,custom_fields.date_value.date,custom_fields.date_value.date_time,custom_fields.description,custom_fields.display_value,custom_fields.enabled,custom_fields.enum_options,custom_fields.enum_options.color,custom_fields.enum_options.enabled,custom_fields.enum_options.name,custom_fields.enum_value,custom_fields.enum_value.color,custom_fields.enum_value.enabled,custom_fields.enum_value.name,custom_fields.format,custom_fields.has_notifications_enabled,custom_fields.id_prefix,custom_fields.is_formula_field,custom_fields.is_global_to_workspace,custom_fields.is_value_read_only,custom_fields.multi_enum_values,custom_fields.multi_enum_values.color,custom_fields.multi_enum_values.enabled,custom_fields.multi_enum_values.name,custom_fields.name,custom_fields.number_value,custom_fields.people_value,custom_fields.people_value.name,custom_fields.precision,custom_fields.representation_type,custom_fields.resource_subtype,custom_fields.text_value,custom_fields.type,dependencies,dependents,due_at,due_on,external,external.data,followers,followers.name,hearted,hearts,hearts.user,hearts.user.name,html_notes,is_rendered_as_separator,liked,likes,likes.user,likes.user.name,memberships,memberships.project,memberships.project.name,memberships.section,memberships.section.name,modified_at,name,notes,num_hearts,num_likes,num_subtasks,parent,parent.created_by,parent.name,parent.resource_subtype,permalink_url,projects,projects.name,resource_subtype,start_at,start_on,tags,tags.name,workspace,workspace.name", # list[str] | This endpoint returns a compact resource, which excludes some properties by default. To include those optional properties, set this query parameter to a comma-separated list of the properties you wish to include.
}
# Create a task
api_response = tasks_api_instance.create_task(body, opts)
return api_response
That’s why I came to the conclusion that it is not possible to create tasks with tables through the Asana API. I get an error saying the html_text with the html table is invalid.