Asana Post Task API - Not a valid image asset id after uploading attachments

Hello,

I am attempting to create an integration of our application (Castofly) with Asana. The goal is to create a task in Asana from our application using the post task API and include HTML content in the description of the task. Although, I am getting an error when trying to include inline images. Here is what I am doing:

  1. Posting a task to Asana
    const data = {
    name: title,
    projects: [project],
    workspace: workspace,
    assignee: assignee,
    };

    const published_task_response = await requestWithRetry({
    method: “post”,
    url: ASANA_TASK_URL,
    mode: “cors”,
    headers: {
    “Accept”: “application/json”,
    “Content-Type”: “application/json”,
    “Authorization”: Bearer ${token},
    },
    data: { data },
    });

  2. Uploading images as attachments to the Asana task.

const data = {
resource_subtype: “external”,
parent: project_gid,
url: imgUrl,
name: castofly_image_attachment_${index + 1},
};

const upload_attachment_response = await requestWithRetry({
  url: ASANA_ATTACHMENTS_URL,
  method: "POST",
  headers: {
    Authorization: `Bearer ${token}`,
  },
  data: { data },
});
  1. After uploading the attachments, I also verify that the attachment has been successfully uploaded to Asana.

  2. After that, I run an update task to include the attachments as inline images:
    const update_task_response = await requestWithRetry({
    url: ${ASANA_TASK_URL}/${task_gid},
    method: “put”,
    mode: “cors”,
    headers: {
    “Authorization”: Bearer ${token},
    “Content-Type”: “application/json”,
    },
    data: { data: { html_notes: body } },
    });

Here is an example of what body is for html_notes:

test for asana

1. Exploring Folder Contents

Open the folder to view its contents and manage your files.
  1. After running the update task API, I get this error: errors: [
    {
    error: ‘reasoned_xml_parsing_error’,
    message: “XML is invalid: Not a valid image asset id: ‘1208868781493200’”
    }
    ]

You didn’t show us the contents of the variable body so we can’t check its exact syntax, but did you format it as specified in the API docs here? In particular, did you use this syntax: <img data-asana-gid="1234">?

Hello Phil,

Yes, we formatted it as specified in the API docs. In our JavaScript code, we have it written like this: <img data-asana-gid="${asana_gids[gidIndex]}" alt="${gidIndex}">

where asana_gids[gidIndex] is a gid of an attachment.

Here is an example of our body (I removed < and > tags to avoid turning it into html in this comment):

|body||h1|test for asana|/h1||h2|1. Exploring Folder Contents|/h2|Open the folder to view its contents and manage your files.|img data-asana-gid=“1208868781493200” alt=“castofly_image_attachment_1”||h2|2. Feedback Button Highlight|/h2|Click on the Feedback button to provide your input or suggestions.|img data-asana-gid=“1208868781267381” alt=“castofly_image_attachment_2”||h2|3. palette

Branding|/h2||img data-asana-gid=“1208868701177510” alt=“castofly_image_attachment_3”||a href=“https://www.castofly.com” rel=“noreferrer” target=“_blank”|Powered by |strong|Castofly|/strong||/a||/body|

@Castofly I played around with this and here are my findings:

  • An attachment with a resource_subtype of external can’t be attached as an inline image. When uploading the attachment, omit the resource_subtype parameter and it will be set to the default value of asana. If you do this, then the inline attach syntax will work.
  • This means that you can’t use the url syntax as the source of the attachment. You have to upload it using the file parameter.

I don’t know why it works this way but this is what I found that works.

@John_Vu @AndrewWong maybe you have some additional insights/clarifications/corrections on my findings here?

1 Like