Zip files with the API

On this page

Use the API to create a zip of files and folders. That zip file could then be downloaded.

The zip API command is one of 40+ commands available in the Sirv REST API.

Choose files for the zip

Before using the zip API, you might like to use the search API to identify which files to include in your zip. The search API let's you create very accurate lists of files, based on the time they were created, modified or last accessed. You can also search by file name, path, size, type, width, height or meta tags.

Alternatively, you can use the read folder API, to get a list of folder contents.

Zip API methods

There are two API methods for zips:

How to create a zip file

1. Connect to the Sirv API and get a bearer token using the standard method.

2. Use the bearer token to create a zip by submitting a POST request with v2/files/zip.

The filenames field is required and can contain up to 1000 paths. Each path should start with a forward slash. It could be a folder path /example/folder/, a partial path /my-files/abc or a full file name /my-files/abc-01.jpg. You can also exclude paths.

The zipFilename is optional and lets you set a name for the zip file.

The following Curl example will zip 2 images into a file named My-bunch-of-files.zip:

curl --request POST 
  --url https://api.sirv.com/v2/files/zip 
  --header 'Authorization: Bearer eyJhbGhOhytoGHDlqbhagGFDShdOKU' 
  --header 'Content-Type: application/json' 
  --data '{
	"filenames": ["/my-image.jpg", "/another-image.jpg"],
	"zipFilename": "My-bunch-of-files.zip"
}'

3. You will receive a JSON response - take note of its job ID, which you will need later:

{
  "id": "J8F9POmzKuRqyjAMUH1ZoEFAFsS41HeH"
}

4. The zip is now being prepared. It could take many minutes to create a zip containing many files or if there's a queue of other zip jobs waiting to be processed. Keep checking the current job status to see if the zip has been created yet. Submit a GET request v2/files/zip stating the job ID:

curl --request GET 
  --url 'https://api.sirv.com/v2/files/zip?id=J8F9POmzKuRqyjAMUH1ZoEFAFsS41HeH' 
  --header 'Authorization: Bearer eyJhbGhOhytoGHDlqbhagGFDShdOKU'

A successfully completed job will show 3 things in its response: 100(%) progress, the zip file size (bytes) and the URL to download the zip file.

Example response:

{
  "progress": 100,
  "result": [
    {
      "filename": "My-bunch-of-files.zip",
      "size": 9638475,
      "url": "https://goto.sirv.com/sgKAlzWJDlPuNJXYEMuP4P08seGIexc9"
    }
  ]
}

5. Download the ZIP file from the URL in the response. Zips will be deleted after 5 days.

Exclude file/folder

You can exclude certain files or folders by specifying their path, prefixed by a minus - character. The following example will include all items in the folder /Products/ and exclude the folder /Products/Active/:

curl --request POST 
  --url https://api.sirv.com/v2/files/zip 
  --header 'Authorization: Bearer eiDktHualktoGHDlqbhagGFDShaiGV' 
  --header 'Content-Type: application/json' 
  --data '{
    "filenames": ["/Products/", "-/Products/Active/"],
    "zipFilename": "My Sirv Export.zip"
}'

Multi-volume zips

If the total file size to be zipped is greater than 3 GB, the files will be zipped into a multi-volume zip. This is a special zip made of multiple parts.

Up to 10 volumes will be created. If more than 30 GB of data exists, each of the 10 volumes will get bigger (e.g. 160 GB of data will be split into 10 zips of about 16 GB each).

Each file that comprises a multi-volume zip will be shown in the response, for example:

{
  "progress": 100,
  "result": [
    {
      "filename": "My-bunch-of-files.z01",
      "size": 3145728,
      "url": "https://goto.sirv.com/gghklzWJDlPkNJXYEMuP4Ps8seCIejhf"
    },
    {
      "filename": "My-bunch-of-files.zip",
      "size": 9638475,
      "url": "https://goto.sirv.com/sgKAlzWJDlPuNJXYEMuP4P08seGIexc9"
    }
  ]
}

All parts need to be downloaded in full, then the master file ending .zip should be unzipped. Do not extract any of the other volumes ending .z01, .z02 etc.

Visit our article and video tutorial on how to download and unpack multi-volume zips.

Zip size limit

The total size of files to be zipped is limited. If you hit a limit, reduce the number of files that you're zipping:

Plan Limit
Enterprise 500 GB / hour
Business 100+ 100 GB / hour
Business 5 - 60 50 GB / hour
Trial 1 GB / hour
Free 1 GB / hour

Support

If you need help with the REST API, please send a message to the Sirv support team.

Was this article helpful?

Get help from a Sirv expert

help ukraine help ukraine Powered by Ukrainian determination and British ingenuity

How can you support Ukraine