Download ZIP Archive
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 -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"
}
]
}'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);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",
)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" });try await client.zipDownloads.createZipDownload(requestBody: ZipDownloadRequest(items: [ZipDownloadRequestItemsField(id: file1.id, type: ZipDownloadRequestItemsTypeField.file), ZipDownloadRequestItemsField(id: file2.id, type: ZipDownloadRequestItemsTypeField.file), ZipDownloadRequestItemsField(id: folder1.id, type: ZipDownloadRequestItemsTypeField.folder)], downloadFileName: "zip"))client.getZipDownloads().createZipDownload(new ZipDownloadRequest.Builder(Arrays.asList(new ZipDownloadRequestItemsField(ZipDownloadRequestItemsTypeField.FILE, file1.getId()), new ZipDownloadRequestItemsField(ZipDownloadRequestItemsTypeField.FILE, file2.getId()), new ZipDownloadRequestItemsField(ZipDownloadRequestItemsTypeField.FOLDER, folder1.getId()))).downloadFileName("zip").build())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" });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);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 files
Place the download ID in the file location URL as in the sample below to point to the right files.
curl -L GET "https://dl.boxcloud.com/2.0/zip_downloads/29l00nfxDyHOt7RphI9zT_w==nDnZEDjY2S8iEWWCHEEiptFxwoWojjlibZjJ6geuE5xnXENDTPxzgbks_yY=/content" \
-H "authorization: Bearer <ACCESS_TOKEN>" \
-o sample_curl.zipawait client.zipDownloads.getZipDownloadContent(zipDownload.downloadUrl!);client.zip_downloads.get_zip_download_content(zip_download.download_url)await client.ZipDownloads.GetZipDownloadContentAsync(downloadUrl: NullableUtils.Unwrap(zipDownload.DownloadUrl));try await client.zipDownloads.getZipDownloadContent(downloadUrl: zipDownload.downloadUrl!, downloadDestinationUrl: URL(path: destinationPathString))client.getZipDownloads().getZipDownloadContent(zipDownload.getDownloadUrl())await client.ZipDownloads.GetZipDownloadContentAsync(downloadUrl: NullableUtils.Unwrap(zipDownload.DownloadUrl));await client.zipDownloads.getZipDownloadContent(zipDownload.downloadUrl!);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 -i -X GET "https://api.box.com/2.0/zip_downloads/29l00nfxDyHOt7RphI9zT_w==nDnZEDjY2S8iEWWCHEEiptFxwoWojjlibZjJ6geuE5xnXENDTPxzgbks_yY=/status" \
-H "authorization: Bearer <ACCESS_TOKEN>"await client.zipDownloads.getZipDownloadStatus(zipDownload.statusUrl!);client.zip_downloads.get_zip_download_status(zip_download.status_url)await client.ZipDownloads.GetZipDownloadStatusAsync(statusUrl: NullableUtils.Unwrap(zipDownload.StatusUrl));try await client.zipDownloads.getZipDownloadStatus(statusUrl: zipDownload.statusUrl!)client.getZipDownloads().getZipDownloadStatus(zipDownload.getStatusUrl())await client.ZipDownloads.GetZipDownloadStatusAsync(statusUrl: NullableUtils.Unwrap(zipDownload.StatusUrl));await client.zipDownloads.getZipDownloadStatus(zipDownload.statusUrl!);