Download ZIP Archive

Guides Downloads Download ZIP Archive
Edit this page

Download ZIP Archive

To download all files in a folder or an entire folder structure, you have to create and download a ZIP archive.

Create a ZIP Archive

First, you need to create a ZIP archive containing the files or the folder structure. You can include up to 10,000 file and folder IDs unless you reach the account’s upload limit.

cURL
curl -i -X POST "https://api.box.com/2.0/zip_downloads" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -d '{
       "download_file_name": "January Financials",
       "items": [
         {
           "type": "file",
           "id": "12345"
         },
         {
           "type": "file",
           "id": "34325"
         },
         {
           "type": "folder",
           "id": "45678"
         }
       ]
     }'
TypeScript Gen
await client.zipDownloads.createZipDownload({
  items: [
    {
      id: file1.id,
      type: 'file' as ZipDownloadRequestItemsTypeField,
    } satisfies ZipDownloadRequestItemsField,
    {
      id: file2.id,
      type: 'file' as ZipDownloadRequestItemsTypeField,
    } satisfies ZipDownloadRequestItemsField,
    {
      id: folder1.id,
      type: 'folder' as ZipDownloadRequestItemsTypeField,
    } satisfies ZipDownloadRequestItemsField,
  ],
  downloadFileName: 'zip',
} satisfies ZipDownloadRequest);
Python Gen
client.zip_downloads.create_zip_download(
    [
        CreateZipDownloadItems(id=file_1.id, type=DownloadZipItemsTypeField.FILE),
        CreateZipDownloadItems(id=file_2.id, type=DownloadZipItemsTypeField.FILE),
        CreateZipDownloadItems(id=folder_1.id, type=DownloadZipItemsTypeField.FOLDER),
    ],
    download_file_name="zip",
)
.NET Gen
await client.ZipDownloads.CreateZipDownloadAsync(requestBody: new ZipDownloadRequest(items: Array.AsReadOnly(new [] {new ZipDownloadRequestItemsField(id: file1.Id, type: ZipDownloadRequestItemsTypeField.File),new ZipDownloadRequestItemsField(id: file2.Id, type: ZipDownloadRequestItemsTypeField.File),new ZipDownloadRequestItemsField(id: folder1.Id, type: ZipDownloadRequestItemsTypeField.Folder)})) { DownloadFileName = "zip" });
Java
ArrayList<BoxZipItem> items = new ArrayList<BoxZipItem>();
BoxZipItem file = new BoxZipItem("file", "12345");
BoxZipItem folder = new BoxZipItem("folder", "156472");
items.add(file);
items.add(folder);
BoxZip zip = new BoxZip(api);
BoxZipInfo zipInfo = zip.create("Awesome Zip File", items);
Node
var name = 'test',
items = [
	{
		type: 'file',
		id: '466239504569'
	},
	{
		type: 'folder',
		id: '466239504580'
	}
];
client.files.createZip(name, items)
	.then(zip => {
		/* zip -> {
				"download_url": "https://api.box.com/2.0/zip_downloads/124hfiowk3fa8kmrwh/content",
				"status_url": "https://api.box.com/2.0/zip_downloads/124hfiowk3fa8kmrwh/status",
				"expires_at": "2018-04-25T11:00:18-07:00",
				"name_conflicts": [
					[
						{
							"id": "100",
							"type": "file",
							"original_name": "salary.pdf",
							"download_name": "aqc823.pdf"
						},
						{
							"id": "200",
							"type": "file",
							"original_name": "salary.pdf",
							"download_name": "aci23s.pdf"
						}
					],
					[
						{
							"id": "1000",
							"type": "folder",
							"original_name": "employees",
							"download_name": "3d366a_employees"
						},
						{
							"id": "2000",
							"type": "folder",
							"original_name": "employees",
							"download_name": "3aa6a7_employees"
						}
					]
				]
			}
		*/
	});

The response will look similar to the following:

{
  "download_url": "https://dl.boxcloud.com/2.0/zip_downloads/25gvaXcIE4QJlinNiw2oHAQ==ZFs3Q2Xpd7pKBz7OyzXNrUaoW3aJxQRN5znAvyM-KpdEEPdWcQDKU-Dl85Ew/content",
  "status_url": "https://api.box.com/2.0/zip_downloads/25gvaXcIE4QJlinNiw2oHAQ==ZFs3Q2Xpd7pKBz7OyzXNrUaoW3aJxQRN5znAvyM-KpdEEPdWcQDKU-Dl85Ew/status",
  "expires_at": "2023-02-28T10:23:54Z",
  "name_conflicts": []
}

Extract the ZIP download ID

To download the ZIP archive, you need the ZIP download ID. You can find it in the response you got when you created the archive.

Go to status_url and copy the ID located betweenzip_downloads and content:

25gvaXcIE4QJlinNiw2oHAQ==ZFs3Q2Xpd7pKBz7OyzXNrUaoW3aJxQRN5znAvyM-KpdEEPdWcQDKU-Dl85Ew

Download URL is valid only for a the time specified in expires_at parameter.

Download files

Place the download ID in the file location URL as in the sample below to point to the right files.

cURL
curl -L GET "https://dl.boxcloud.com/2.0/zip_downloads/29l00nfxDyHOt7RphI9zT_w==nDnZEDjY2S8iEWWCHEEiptFxwoWojjlibZjJ6geuE5xnXENDTPxzgbks_yY=/content" \
     -H "authorization: Bearer <ACCESS_TOKEN>" \
     -o sample_curl.zip
TypeScript Gen
await client.zipDownloads.getZipDownloadContent(zipDownload.downloadUrl!);
Python Gen
client.zip_downloads.get_zip_download_content(zip_download.download_url)
.NET Gen
await client.ZipDownloads.GetZipDownloadContentAsync(downloadUrl: NullableUtils.Unwrap(zipDownload.DownloadUrl));
Java
ArrayList<BoxZipItem> items = new ArrayList<BoxZipItem>();
BoxZipItem file = new BoxZipItem("file", "12345");
BoxZipItem folder = new BoxZipItem("folder", "156472");
items.add(file);
items.add(folder);
BoxZip zip = new BoxZip(api);
FileOutputStream stream = new FileOutputStream();
BoxZipDownloadStatus zipDownloadStatus = zip.download("Another Awesome Zip File", items, stream);
stream.close();
if (zipDownloadStatus.getState() == BoxZipDownloadStatus.State.SUCCEEDED) {
    System.out.println("Zip downloaded successfully");
}
Python
name = 'test'
file = mock_client.file('466239504569')
folder = mock_client.folder('466239504580')
items = [file, folder]
output_file = open('test.zip', 'wb')
status = client.download_zip(name, items, output_file)
print(f'The status of the zip download is {status["state"]}')
.NET
BoxZipRequest request = new BoxZipRequest();
request.Name = "test";
request.Items = new List<BoxZipItemRequest>();

var file = new BoxZipRequestItem()
{
    Id = "466239504569",
    Type = BoxZipItemType.file
};
var folder = new BoxZipRequestItem()
{
    Id = "466239504580",
    Type = BoxZipItemType.folder
};
request.Items.Add(file);
request.Items.Add(folder);
Stream fs = new FileStream(@"c:\temp\MyTest.zip");

BoxZipDownloadStatus status = await _filesManager.DownloadZip(request, fs);
Node
var name = 'test',
items = [
	{
		type: 'file',
		id: '466239504569'
	},
	{
		type: 'folder',
		id: '466239504580'
	}
],
stream = new Readable();
client.files.downloadZip(name, items, stream)
	.then(status => {
		/* status -> {
				"total_file_count": 20,
				"downloaded_file_count": 10,
				"skipped_file_count": 10,
				"skipped_folder_count": 10,
				"state": "succeeded"
			}
		*/
	});

For downloads that take longer, you can monitor the download status using the status endpoint. This allows you to inspect the progress of the download as well as the number of items that might have been skipped.

cURL
curl -i -X GET "https://api.box.com/2.0/zip_downloads/29l00nfxDyHOt7RphI9zT_w==nDnZEDjY2S8iEWWCHEEiptFxwoWojjlibZjJ6geuE5xnXENDTPxzgbks_yY=/status" \
     -H "authorization: Bearer <ACCESS_TOKEN>"
TypeScript Gen
await client.zipDownloads.getZipDownloadStatus(zipDownload.statusUrl!);
Python Gen
client.zip_downloads.get_zip_download_status(zip_download.status_url)
.NET Gen
await client.ZipDownloads.GetZipDownloadStatusAsync(statusUrl: NullableUtils.Unwrap(zipDownload.StatusUrl));

If you want to use SDKs to download the contents of the folder, follow this guide.