# Uploading attachment from blob plus parent parameter

**URL:** <https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986>\
**Category:** API & Developers\
**Created:** [7 October 2022 00:33 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986 "2022-10-07T00:33:36Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![anon69146899](https://luna1.co/8d76cd.png) [@anon69146899](https://forum.asana.com/u/anon69146899)\
**Post date:** [7 October 2022 00:33 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/1 "2022-10-07T00:33:36Z")

</div>

I’m attempting to upload an attachment - trying both as a blob or from a URL.

**Big caveat:** Docs indicate you cannot add an attachment from Google Drive. Is this true whether you read the file as a blob or get the URL? If so, that greatly hinders things.

Also, the parent parameter on an attachment. Should that be the task gid?

One error I’m receiving is:  
{“errors”:[{“message”:“You should specify one of parent”

Note: in code below, I either pass the name and URL of the image or a blob. This code indicates the former.

```auto
function asanaFileUpload(fileName, fileUrl, taskId, accessToken) {

  const attachURL = "https://app.asana.com/api/1.0/attachments";

  let attachment = {
    "data": {
      //file" : fileBlob,
      "name": fileName,
      "parent": taskId,
      "resource_subtype": "external",
      "url": fileUrl
    }
  }

  let options = {
    "method": "POST",
    "headers": {
      "Accept": "application/json",
      "Content-Type": "image/jpeg", //"multipart/form-data", //
      "Authorization": "Bearer " + accessToken
    },
    "payload": attachment //JSON.stringify({ data: attachment }
  };

  try {

    var result = UrlFetchApp.fetch(attachURL, options);
    var attachJSON = result.getContentText();
  } catch (e) {
    Logger.log(e);
    return null;
  } finally {

    return JSON.parse(attachJSON).data;
  }

}

```

---

<div class="post-metadata">

**Author:** ![anon69146899](https://luna1.co/8d76cd.png) [@anon69146899](https://forum.asana.com/u/anon69146899)\
**Post date:** [7 October 2022 00:48 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/2 "2022-10-07T00:48:40Z")

</div>

Add: Searching for “You should specify one of parent” returns no results. 😢

---

<div class="post-metadata">

**Author:** ![Jonas\_O](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jonas_o/32/12844_2.png) [@Jonas\_O](https://forum.asana.com/u/Jonas_O)\
**Post date:** [7 October 2022 09:26 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/3 "2022-10-07T09:26:54Z")

</div>

Try this url instead.

```auto
const attachURL = `https://app.asana.com/api/1.0/tasks/${taskId}/attachments`

```

---

<div class="post-metadata">

**Author:** ![anon69146899](https://luna1.co/8d76cd.png) [@anon69146899](https://forum.asana.com/u/anon69146899)\
**Post date:** [7 October 2022 14:51 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/4 "2022-10-07T14:51:17Z")

</div>

I saw that URL in the documentation somewhere and could not find it again. Do you have a link for that documentation?

---

<div class="post-metadata">

**Author:** ![anon69146899](https://luna1.co/8d76cd.png) [@anon69146899](https://forum.asana.com/u/anon69146899)\
**Post date:** [7 October 2022 15:32 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/5 "2022-10-07T15:32:37Z")

</div>

That worked to create a linked attachment using the code below. How can I get it to upload the file to Asana. The image location, due to user/data sensitivity, cannot be unrestricted. The task is private to the person it is assigned to and the customer/department wants to image uploaded into Asana.

This worked - again - to create a linked attachments.

```auto
function asanaFileUpload(fileName, fileUrl, fileBlob, taskId, accessToken) {

  let attachURL = `https://app.asana.com/api/1.0/tasks/${taskId}/attachments`; 

  let attachment = {
      "name": fileName,
      "resource_subtype": "external",
      "url": fileUrl
    }

  let options = {
    "method": "POST",
    "headers": {
      "Accept": "application/json",
      "Content-Type": "image/jpeg",
      "Authorization": "Bearer " + accessToken      
    },
    "payload": JSON.stringify({ data: attachment })
  };

  try {

    var result = UrlFetchApp.fetch(attachURL, options);
    var attachJSON = result.getContentText();
  } catch (e) {
    Logger.log(e);
    return null;
  } finally {

    return JSON.parse(attachJSON).data;
  }

}

```

---

<div class="post-metadata">

**Author:** ![anon69146899](https://luna1.co/8d76cd.png) [@anon69146899](https://forum.asana.com/u/anon69146899)\
**Post date:** [7 October 2022 18:03 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/6 "2022-10-07T18:03:07Z")

</div>

This is what worked. Image uploads correctly and is visible in the task.

Note: This is Google Apps Script

```auto
function testFileUpload() {
  const taskId = "[ENTER YOUR TASK ID]";
  const accessToken = "#/########"; //your access token
  const file = DriveApp.getFileById([ENTER AN IMAGE (JPG) GOOGLE DRIVE ID]);
  const fileName = file.getName(); //unneeded
  const fileURL = file.getUrl(); //unneeded
  const fileBlob = file.getBlob();
  const asanaResponse = asanaFileUpload(fileBlob, taskId, accessToken);
  Logger.log(JSON.stringify(asanaResponse,null,4));

}

function asanaFileUpload(fileBlob, taskId, accessToken) {

  let attachURL = `https://app.asana.com/api/1.0/tasks/${taskId}/attachments`; //"https://app.asana.com/api/1.0/attachments";

  let formData = {
       'file' : fileBlob
    }

  let options = {
    'method': 'POST',
    headers: {
      "Authorization": "Bearer " + accessToken      
    },
    'payload': formData
  };

  try {

    var result = UrlFetchApp.fetch(attachURL, options);
    var attachJSON = result.getContentText();
  } catch (e) {
    Logger.log(e);
    return null;
  } finally {

    return JSON.parse(attachJSON).data;
  }

}

```

---

<div class="post-metadata">

**Author:** ![Jonas\_O](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/jonas_o/32/12844_2.png) [@Jonas\_O](https://forum.asana.com/u/Jonas_O)\
**Post date:** [10 October 2022 07:42 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/7 "2022-10-10T07:42:18Z")

</div>

Nice that you got it working! Haha sorry i cant find the url in the documentation. I wonder if i found it on the old documentation. Thats the url i use for uploads. 😄

---

<div class="post-metadata">

**Author:** ![George\_Zeidan](https://luna1.co/8d76cd.png) [@George\_Zeidan](https://forum.asana.com/u/George_Zeidan)\
**Post date:** [29 August 2023 04:35 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/8 "2023-08-29T04:35:35Z")

</div>

Hi

I am using Power Automate to attach files to a task in Asana. I managed to get the API working using a URL and a file name with resouce\_subtype set to external.

My only issue is that the images do not render in the Task.

Any idea what the issue could be as you managed to get the images rendering as per your thread above?

---

<div class="post-metadata">

**Author:** ![system](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/system/32/276370_2.png) [@system](https://forum.asana.com/u/system)\
**Post date:** [30 May 2025 18:55 UTC](https://forum.asana.com/t/uploading-attachment-from-blob-plus-parent-parameter/212986/9 "2025-05-30T18:55:06Z")

</div>


