I have a problem with writing an inline images to task description via API, it uploads it with 0 width and height

Hi community
we are writing an inline image (after uploading the attachment) using these instructions

and we are getting in an Asana picture with 0 width, so it’s there but it’s invisible

here I recorded the screen to show it:

This is the code how we do this:
$attachment_html = ‘’;

Please assist

this is the code how we do this:

$attachment_html = '<img data-asana-gid="' . 
$attachment->gid . '">';

we tried different code, like

$attachment_html = '<img data-asana-gid="' . $attachment->gid . '" width="100%">';

additionally, we tried different options in the code, like


but the same result always

Please advise how to solve this!!!

Hi @Igor2!

I’ve tested the following and it behaves the same as attaching an image to a task’s description/notes in the UI. The img tag should include the following (replacing the {} placeholders with your own values).

<img src="{ attachment.view_url }" 
  alt="{ attachment.name }" 
  data-asana-gid="{ attachment.gid }" 
  data-src-width="{ width }" 
  data-src-height="{ height }" 
  data-thumbnail-height="{ thumbnail-height }"
  data-thumbnail-width="{ thumbnail-width }"
  style="display:block;max-width:100%;margin-left:auto;margin-right:auto" />

Hope this helps!

1 Like

Hi David, we tested exactly as you told, and the same result … I’ve attached PHP side and asana HTML from the browser code inspector

Please advice!!!

Looking at your source, it doesn’t appear that you are setting the src property of the <img>. You will want to set the src to the attachment’s view_url property. In your code, it might like something like:

  src="' . $attachment->view_url . '"

Let me know if that works!

  1. Fix for $attachment->view_url:

Our current implementation cannot use the fix src="' . $attachment->view_url . '" because our attachment object does not have view_url. We need your support in this matter to understand possible solutions for this.

    1. Problem with the Asana library version:
      We are using the Asana (GitHub - Asana/php-asana: Official PHP client library for the Asana API v1) library version 0.10.8 for integration, and it works correctly. However, when we update it to version 1.0.6, issues arise with creating attachments for tasks.

The release notes on GitHub (Releases · Asana/php-asana · GitHub) indicate that in version 1.0.0, the creation of attachments for tasks was removed. Could you please what to use instead of it or how we can do inline insert writing on a new version of the library?

so there is no method

We can stay on version 0.10.8, but we need to know if there is a way to correctly display the picture inline in the task description.

After you create the attachment, try using the returned GID to fetch the attachment details (e.g. findById). Does that include the view_url?

It appear the createAttachmentForTask function was replaced with a more generic createAttachmentForObject. It should accomplish the same thing.

Make sure the tag in your HTML for Asana includes a width attribute (e.g., ) to ensure the image displays correctly. Adjust the width value as necessary to ensure visibility within Asana.