Table into API created task or comment

I’m trying by any means to create new tasks WITH tables through the API whenever my Python Django project says there is a problem on our private website.

I’ve tried posting a table through a task comment (aka Story) which simply fails to render the HTML table and instead . I’ve tried posting the table to a new task description, which returns an invalid XML error and doesn’t create a task so long as I’m trying to put an html table into the data:{html_text:“”} attribute of the API call. [Rich text](https://rich text documentation)

What is currently a possible way to create tasks with tables through the API? Can I use Task Templates and if so how? Or how can I create tasks with filled custom fields? The documentation at https://developers.asana.com/ is very unclear.

@Sander_Buruma - welcome to the forum! Although the rich text documentation only calls out tables in project briefs, I just tested and you can actually write them to the description of tasks or in comments (stories) as well.

When creating or updating either a task or a comment, pass your table HTML in the html_notes field of your request body. I’ve just tested this and it worked as expected (with the caveat that you’re only passing in a simple table and not trying to do a lot of styling or anything). I haven’t tried passing in a table with thead/tfoot (only standard rows).

RE: your other questions

  • You have to set up task templates in the Asana UI and can then instantiate them via the API.
  • You can create tasks with custom fields pre-filled by calling the previously referenced createTasks endpoint and passing it custom field data as documented in the dev docs.

I generally think Asana’s docs are quite good (other than the rich text oversight). @John_Baldo - sorry if you’re not the right person to ping, but could you/someone confirm that the rich text documentation for tables is outdated?

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.

@Sander_Buruma - could you try changing your th tags to td? I think it doesn’t support table headers.

That works, thank you so much. That was so confusing. I hadn’t even thought that was the problem because there was no mention of it and table header tags have always been standard in every table I’ve ever created and seen.

1 Like

@Sander_Buruma - agreed that additional table support would be extremely helpful (table headers aren’t supported in the UI either, to my knowledge). If you feel strongly about it, consider creating a request post in the English Forum > Product Feedback channel.

In the meantime, maybe you could just bold the text in the “header” cells so at least it’s visually clear for users?

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