Download multiple documents

Hello,

I’m new to n8n so this may be something I’m just overlooking. I’m trying to build a workflow that will use an API call to get information about documents attached to a case. I then want to loop through the information that comes back and download each document. I can succesfully download the first document but anything after that does not work. Here is the layout that I have so far:

I can see the individual items in the Item Lists node and they look right. In the Download Docs (http node) I have it setup with a response format of File, I set the url to https://siteurl/{{$json[“files”][“url”]}}. This should dynamically set the url to the download url for each document (at least that is what I think it should do).

In the Binary Property field I have something similar. The value is {{$json[“files”][“name”]}} which I think should dynamically set the name of the file as well. When I run the process and look at the binary files in the final step there are two files created, the first one is named properly and the file is what I’m expecting. The second document is named the same as the first and the data is not correct.
The incoming data has JSON that looks like this

[
  {
    "files": {
      "name": "Squirrel-UpdateSelf.log",
      "size": 264,
      "url": "/...url/Download?data={'CaRelDocsId':10715}",
      "deleteUrl": "/...url/Delete?data={'CaRelDocId':10715}",
      "deleteType": "GET",
      "reldocsId": "10715",
      "date": "2021-10-18T13:28:39",
      "attachedBy": "KYLER",
      "thumbnailUrl": "...url/DownloadCaRelDocs?data={'CaRelDocsId':10715}",
      "taskCode": null,
      "taskDesc": null,
      "caReceiptId": null,
      "caTaskId": null,
      "caObjectId": 576,
      "LabelText": null,
      "Title": null,
      "Description": null,
      "Tags": []
    }
  },
  {
    "files": {
      "name": "Squirrel-UpdateSelf - Copy.log",
      "size": 274,
      "url": "...url/Download?data={'CaRelDocsId':10717}",
      "deleteUrl": "...url/Delete?data={'CaRelDocId':10717}",
      "deleteType": "GET",
      "reldocsId": "10717",
      "date": "2021-10-18T14:09:02",
      "attachedBy": "KYLER",
      "thumbnailUrl": "...url/DownloadCaRelDocs?data={'CaRelDocsId':10717}",
      "taskCode": null,
      "taskDesc": null,
      "caReceiptId": null,
      "caTaskId": null,
      "caObjectId": 576,
      "LabelText": null,
      "Title": null,
      "Description": null,
      "Tags": []
    }
  }
]

Is there a trick to get the http node to download multiple files like this? Do I need to use a Split In Batches node?

Thanks for your help,
Kyle

Welcome to the community @krim

The binary property name does not set the name of the file. It sets the name of the property that will hold the binary data. This is usually is called data. You can reference that binary data later in the workflow using this property.

Can you please remove the expression from the binary property and set the name to a string, for example: data.

Hi RicardoE105,

I’ve tried that but I still get the same result, first binary file is correct, second one is not. here is what it looks like:

The first file looks like this:

And the second file should look almost identical but instead it looks like this:

I did make some progress adding a loop and a split in batches. Now I can get each individual file I just need to email them or zip them and then email.

If I’m on the wrong path please let me know.

Thanks

The split batches node should not be needed there. n8n automatically does the iteration behind the scenes. That is quite weird. Assuming that the second file has the same data that the first file, it should work as expected.

Are you 100% sure that the second file has the same information as the first file? Can you double-check that?

Yeah, it’s the same file. I made a copy of the first file, appended - Copy to the file name and added the word Copy to the end of the text file. When I first added the split batches node I noticed the note saying probably wasn’t needed so I deleted it and tried to get it without but I could never get anything but the first file to work unless I specifically asked for position [1].

Can I see the output of the item list node?

Sure thing. There are two items in the output. Here is the output:

[
  {
    "files": {
      "name": "Squirrel-UpdateSelf.log",
      "size": 264,
      "url": "/...Download?data={'CaRelDocsId':10715}",
      "deleteUrl": "/.../Delete?data={'CaRelDocId':10715}",
      "deleteType": "GET",
      "reldocsId": "10715",
      "date": "2021-10-18T13:28:39",
      "attachedBy": "KYLER",
      "thumbnailUrl": ".../DownloadCaRelDocs?data={'CaRelDocsId':10715}",
      "taskCode": null,
      "taskDesc": null,
      "caReceiptId": null,
      "caTaskId": null,
      "caObjectId": 576,
      "LabelText": null,
      "Title": null,
      "Description": null,
      "Tags": []
    }
  },
  {
    "files": {
      "name": "Squirrel-UpdateSelf - Copy.log",
      "size": 274,
      "url": ".../Download?data={'CaRelDocsId':10717}",
      "deleteUrl": "/.../Delete?data={'CaRelDocId':10717}",
      "deleteType": "GET",
      "reldocsId": "10717",
      "date": "2021-10-18T14:09:02",
      "attachedBy": "KYLER",
      "thumbnailUrl": "/.../DownloadCaRelDocs?data={'CaRelDocsId':10717}",
      "taskCode": null,
      "taskDesc": null,
      "caReceiptId": null,
      "caTaskId": null,
      "caObjectId": 576,
      "LabelText": null,
      "Title": null,
      "Description": null,
      "Tags": []
    }
  }
]

I was able to get a workflow to do what I needed to but did have to use a split in batches node. I’d love to figure out what I’ve done wrong so I won’t need to do that for other workflows.

Thanks for your help looking at this.

Kyle