# Invalid JSON response from batch API request

**URL:** <https://forum.asana.com/t/invalid-json-response-from-batch-api-request/111718>\
**Category:** API & Developers\
**Created:** [24 February 2021 22:03 UTC](https://forum.asana.com/t/invalid-json-response-from-batch-api-request/111718 "2021-02-24T22:03:20Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Sam\_Weedon](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/sam_weedon/32/43756_2.png) [@Sam\_Weedon](https://forum.asana.com/u/Sam_Weedon)\
**Post date:** [24 February 2021 22:03 UTC](https://forum.asana.com/t/invalid-json-response-from-batch-api-request/111718/1 "2021-02-24T22:03:20Z")

</div>

Hi all,

I am using Google Apps Script to send a batch API request to add a story and some attachments to a task. Here is the code:

```
function add_details(asana_id, desc, files){
  var actions = []
  if(desc != ""){
    var action = {
      "data": {
        "text": desc
      },
      "method": "POST",
      "relative_path": "/tasks/" + asana_id + "/stories"
    }
    actions.push(action)
  }
  if(files.length > 0){
    for(var file_num = 0; file_num < files.length; file_num++){
      var action = {
        "data": {
          "file": files[file_num]
        },
        "method": "POST",
        "relative_path": "/tasks/" + asana_id + "/attachments"
      }
    }
    actions.push(action)
  }
  
  var url = "https://app.asana.com/api/1.0/batch"
  var headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
    "Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
  };
  var options = {
    "method": "POST",
    "headers": headers,
    "payload": {
      "actions": actions
    },
    "muteHttpExceptions": true
  };
  console.log(options.payload)
  var response = UrlFetchApp.fetch(url, options);
  var json = JSON.parse(response.getContentText());
  console.log(json)

  if(json.errors) {
    throw "There was an error adding the description"
  }
  else {
    return "Success"
  }
}

```

Here is an example of the payload JSON:

```
{ actions: 
   [ 
     {
        "data": {
          "text": "This is a test for batch API" 
        },
        "method": "POST",
        "relative_path": "/tasks/111111111111111111111/stories" 
     },
     {
        "data": {
          "file": { [file_object] }
        }, 
        "method": "POST",
        "relative_path": "/tasks/111111111111111111111/attachments"
     }
   ]
}

```

But when I send this request to Asana, I am getting an invalid JSON response, with a message saying “Could not parse request data, invalid JSON”

I’m not sure what it is that I’m missing, has anyone got any ideas?

Thanks!

---

<div class="post-metadata">

**Author:** ![Frederic\_Malenfant](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/frederic_malenfant/32/8358_2.png) [@Frederic\_Malenfant](https://forum.asana.com/u/Frederic_Malenfant)\
**Post date:** [24 February 2021 22:53 UTC](https://forum.asana.com/t/invalid-json-response-from-batch-api-request/111718/2 "2021-02-24T22:53:33Z")

</div>

You can’t POST an attachment to a task using the batch endpoint.

From the documentation:

Restrictions  
Not every endpoint can be accessed through the batch API. Specifically, the following actions cannot be taken and will result in a 400 Bad Request for that action:

Uploading attachments  
Creating, getting, or deleting organization exports  
Any SCIM operations  
Nested calls to the batch API

---

<div class="post-metadata">

**Author:** ![Sam\_Weedon](https://sea2.discourse-cdn.com/asana/user_avatar/forum.asana.com/sam_weedon/32/43756_2.png) [@Sam\_Weedon](https://forum.asana.com/u/Sam_Weedon)\
**Post date:** [24 February 2021 23:07 UTC](https://forum.asana.com/t/invalid-json-response-from-batch-api-request/111718/3 "2021-02-24T23:07:04Z")

</div>

Ah, thanks Frederic, clearly I missed that part of the docs!

---

<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:57 UTC](https://forum.asana.com/t/invalid-json-response-from-batch-api-request/111718/4 "2025-05-30T18:57:21Z")

</div>

Closed on 30 May 2025 18:57 UTC


