b2_list_file_versions

Lists all of the versions of all of the files contained in one bucket, in alphabetical order by file name, and by reverse of date/time uploaded for versions of files with the same name.

This call returns at most 1000 file names per transaction, but it can be called repeatedly to scan through all of the file names in a bucket. Each time you call, it returns a "nextFileName" and "nextFileId" that can be used as the starting point for the next call.

This call supports the same options for matching a file name prefix and for grouping files into folders as b2_list_file_names. See that page for more details.

Request

Request HTTP Headers

Authorization

required

The account authorization token returned by b2_authorize_account.

Request HTTP Message Body Parameters

bucketId

required

The bucket to look for file names in.

startFileName

optional

The first file name to return.
If there are no files with this name, the first version of the file with the first name after the given name will be the first in the list.
If startFileId is also specified, the name-and-id pair is the starting point. If there is a file with the given name and ID, it will be first in the list. Otherwise, the first file version that comes after the given name and ID will be first in the list.

startFileId

optional

The first file ID to return. startFileName must also be provided if startFileId is specified. (See startFileName.)

maxFileCount

optional

The maximum number of files to return from this call. The default value is 100, and the maximum is 10000. Passing in 0 means to use the default of 100.
NOTE: b2_list_file_versions is a Class C transaction (see Pricing). The maximum number of files returned per transaction is 1000. If you set maxFileCount to more than 1000 and more than 1000 are returned, the call will be billed as multiple transactions, as if you had made requests in a loop asking for 1000 at a time. For example: if you set maxFileCount to 10000 and 3123 items are returned, you will be billed for 4 Class C transactions.

prefix

optional

Files returned will be limited to those with the given prefix. Defaults to the empty string, which matches all files.

delimiter

optional

Files returned will be limited to those within the top folder, or any one subfolder. Defaults to NULL. Folder names will also be returned. The delimiter character will be used to "break" file names into folders.

Response

Response HTTP Status 200

List of file names as JSON:

files

An array of objects, each one describing one file. (See below.)

nextFileName

What to pass in to startFileName for the next search to continue where this one left off, or null if there are no more files. Note this this may not be the name of an actual file, but using it is guaranteed to find the next file version in the bucket.

nextFileId

What to pass in to startFileId for the next search to continue where this one left off, or null if there are no more files. Note this this may not be the ID of an actual file, but using it is guaranteed to find the next file version in the bucket.

And each of the files is:

fileId

The unique identifier for this version of this file. Used with b2_get_file_info, b2_download_file_by_id, and b2_delete_file_version. Not returned for "folder".

fileName

The name of this file, which can be used with b2_download_file_by_name. Not returned for "folder".

contentLength

When the action is "upload", the number of bytes stored in the file. When the action is "hide", this version of the file has no data, and the value is 0. When the action is "start", the value is 0, even if there have been parts uploaded; it will become non-zero only when the large file is finished. Not returned for "folder".

contentType

The MIME type of the file. Not returned for "folder".

contentSha1

The SHA1 of the data that you provided when uploading the file. Not returned for "folder".

fileInfo

A JSON object with the file info you supplied when uploading the file. Example:

{
    "src_last_modified_millis": "1456275056"
}
Not returned for "folder".

action

One of "start", "upload", "hide", or other values added in the future. "start" means that a large file has been started, but not finished or canceled. "upload" means a file that was uploaded to B2 Cloud Storage. "hide" means a file version marking the file as hidden, so that it will not show up in b2_list_file_names. Folder entries are "folder".

size

Deprecated. Same as contentLength. Not returned for "folder".

uploadTimestamp

This is a UTC time when this file was uploaded. It is a base 10 number of milliseconds since midnight, January 1, 1970 UTC. This fits in a 64 bit integer such as the type "long" in the programming language Java. It is intended to be compatible with Java's time long. For example, it can be passed directly into the java call Date.setTime(long time). Not returned for "folder".

Response Errors

If possible the server will return a JSON error structure. Errors include:

status

code

message

400

invalid_bucket_id

Invalid bucketId: <bucketId>

400

out_of_range

maxFileCount out of range: <maxFileCount>

400

invalid_file_id

When startFileId is specified startFileName must also be specified

400

invalid_file_id

Invalid startFileId: <startFileId>

400

bad_request

File names must contain at least one character

400

bad_request

File names in UTF8 must be no more than 1000 bytes

400

bad_request

File names must not start with '/'

400

bad_request

File names must not end with '/'

400

bad_request

File names must not contain '\'

400

bad_request

File names must not contain DELETE

400

bad_request

File names must not contain '//'

400

bad_request

Wrong host name for request

400

bad_request

Prefix must not start with delimiter

400

bad_request

Prefix must be 1 or more characters long

400

bad_request

Delimiter must be within acceptable list

401

missing_auth_token

Authorization token is missing

401

expired_auth_token

Authorization token has expired

401

bad_auth_token

Invalid authorization token

401

bad_auth_token

Authorization token for wrong cluster

503

bad_request

Timed out while iterating and skipping files

Sample Code

Code

curl \
    -H 'Authorization: ACCOUNT_AUTHORIZATION_TOKEN' \
    -d '{"bucketId": "BUCKET_ID"} \
    https://apiNNN.backblazeb2.com/b2api/v1/b2_list_file_versions

Output

{
  "files": [
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886245_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/hello.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    },
    {
      "action": "hide",
      "contentLength": 0,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232323_c100_v0009990_t0005",
      "fileName": "files/world.txt",
      "size": 0,
      "uploadTimestamp": 1439162603000
    },
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886246_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/world.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    }
  ],
  "nextFileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232316_c100_v0009990_t0003",
  "nextFileName": "files/world.txt"
}

Code

import java.io.*;
import java.util.*;
import javax.json.*;
import java.net.HttpURLConnection;
import java.net.URL;

String apiUrl = ""; // Provided by b2_authorize_account
String accountAuthorizationToken = ""; // Provided by b2_authorize_account
String bucketId = ""; // The ID of the bucket you are querying
HttpURLConnection connection = null;
String postParams = "{\"bucketId\":\"" + bucketId + "\"}";
byte postData[] = postParams.getBytes(StandardCharsets.UTF_8);
try {
    URL url = new URL(apiUrl + "/b2api/v1/b2_list_file_versions");
    connection = (HttpURLConnection)url.openConnection();
    connection.setRequestMethod("POST");
    connection.setRequestProperty("Authorization", accountAuthorizationToken);
    connection.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
    connection.setRequestProperty("charset", "utf-8");
    connection.setRequestProperty("Content-Length", Integer.toString(postData.length));
    connection.setDoOutput(true);
    DataOutputStream writer = new DataOutputStream(connection.getOutputStream());
    writer.write(postData);
    String jsonResponse = myInputStreamReader(connection.getInputStream());
    System.out.println(jsonResponse);
} catch (Exception e) {
    e.printStackTrace();
} finally {
    connection.disconnect();
}

static public String myInputStreamReader(InputStream in) throws IOException {
    InputStreamReader reader = new InputStreamReader(in);
    StringBuilder sb = new StringBuilder();
    int c = reader.read();
    while (c != -1) {
        sb.append((char)c);
        c = reader.read();
    }
    reader.close();
    return sb.toString();
}

Output

{
  "files": [
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886245_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/hello.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    },
    {
      "action": "hide",
      "contentLength": 0,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232323_c100_v0009990_t0005",
      "fileName": "files/world.txt",
      "size": 0,
      "uploadTimestamp": 1439162603000
    },
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886246_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/world.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    }
  ],
  "nextFileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232316_c100_v0009990_t0003",
  "nextFileName": "files/world.txt"
}

Code

import json
import urllib2

api_url = "" # Provided by b2_authorize_account
account_authorization_token = "" # Provided by b2_authorize_account
bucket_id = "" # The ID of the bucket you are querying
request = urllib2.Request(
	'%s/b2api/v1/b2_list_file_versions' % api_url,
	json.dumps({ 'bucketId' : bucket_id }),
	headers = { 'Authorization': account_authorization_token }
	)
response = urllib2.urlopen(request)
response_data = json.loads(response.read())
response.close()

Output

{
  "files": [
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886245_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/hello.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    },
    {
      "action": "hide",
      "contentLength": 0,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232323_c100_v0009990_t0005",
      "fileName": "files/world.txt",
      "size": 0,
      "uploadTimestamp": 1439162603000
    },
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886246_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/world.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    }
  ],
  "nextFileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232316_c100_v0009990_t0003",
  "nextFileName": "files/world.txt"
}

Code

import Foundation

let apiUrl = "" // Provided by b2_authorize_account
let accountAuthorizationToken = "" // Provided by b2_authorize_account
let bucketId = "" // The ID of the bucket you are querying
let session = NSURLSession.sharedSession()
let request = NSMutableURLRequest(URL:NSURL(string: "\(apiUrl)")!.URLByAppendingPathComponent("/b2api/v1/b2_list_file_versions"))
request.HTTPMethod = "POST"
request.addValue(accountAuthorizationToken, forHTTPHeaderField: "Authorization")
request.HTTPBody = "{\"bucketId\":\"\(bucketId)\"}".dataUsingEncoding(NSUTF8StringEncoding, allowLossyConversion: false)
let task = session.dataTaskWithRequest(request, completionHandler:{ (data: NSData!, response: NSURLResponse!, error: NSError!) -> Void in
    if data != nil {
        let json = NSString(data: data, encoding:NSUTF8StringEncoding)
    }
})
task.resume()

Output

{
  "files": [
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886245_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/hello.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    },
    {
      "action": "hide",
      "contentLength": 0,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232323_c100_v0009990_t0005",
      "fileName": "files/world.txt",
      "size": 0,
      "uploadTimestamp": 1439162603000
    },
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886246_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/world.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    }
  ],
  "nextFileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232316_c100_v0009990_t0003",
  "nextFileName": "files/world.txt"
}

Code

require 'json'
require 'net/http'

api_url = "" # Provided by b2_authorize_account
account_authorization_token = "" # Provided by b2_authorize_account
bucket_id = "" # The ID of the bucket you are querying
uri = URI("#{api_url}/b2api/v1/b2_list_file_versions")
req = Net::HTTP::Post.new(uri)
req.add_field("Authorization","#{account_authorization_token}")
req.body = "{\"bucketId\":\"#{bucket_id}\"}"
http = Net::HTTP.new(req.uri.host, req.uri.port)
http.use_ssl = (req.uri.scheme == 'https')
res = http.start {|http| http.request(req)}
case res
when Net::HTTPSuccess then
    res.body
when Net::HTTPRedirection then
    fetch(res['location'], limit - 1)
else
    res.error!
end

Output

{
  "files": [
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886245_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/hello.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    },
    {
      "action": "hide",
      "contentLength": 0,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232323_c100_v0009990_t0005",
      "fileName": "files/world.txt",
      "size": 0,
      "uploadTimestamp": 1439162603000
    },
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886246_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/world.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    }
  ],
  "nextFileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232316_c100_v0009990_t0003",
  "nextFileName": "files/world.txt"
}

Code

String apiUrl = "API_URL"; //Provided by b2_authorize_account 
String accountAuthorizationToken = "ACCOUNT_AUTHORIZATION_TOKEN"; //Provided by b2_authorize_account
String bucketId = "BUCKET_ID; //The unique bucket ID
HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(apiUrl + "/b2api/v1/b2_list_file_versions");
string body = "{\"bucketId\":\"" + bucketId + "\"}";
var data = Encoding.UTF8.GetBytes(body);
webRequest.Method = "POST";
webRequest.Headers.Add("Authorization", accountAuthorizationToken);
webRequest.ContentType = "application/json; charset=utf-8";
webRequest.ContentLength = data.Length;
using (var stream = webRequest.GetRequestStream())
{
stream.Write(data, 0, data.Length);
stream.Close();
}
WebResponse response = (HttpWebResponse)webRequest.GetResponse();
var responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
response.Close();
Console.WriteLine(responseString);

Output

{
  "files": [
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886245_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/hello.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    },
    {
      "action": "hide",
      "contentLength": 0,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232323_c100_v0009990_t0005",
      "fileName": "files/world.txt",
      "size": 0,
      "uploadTimestamp": 1439162603000
    },
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886246_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/world.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    }
  ],
  "nextFileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232316_c100_v0009990_t0003",
  "nextFileName": "files/world.txt"
}

Code

$api_url = ""; // From b2_authorize_account call
$auth_token = ""; // From b2_authorize_account call
$bucket_id = "";  // The ID of the bucket

$session = curl_init($api_url .  "/b2api/v1/b2_list_file_versions");

// Add post fields
$data = array("bucketId" => $bucket_id);
$post_fields = json_encode($data);
curl_setopt($session, CURLOPT_POSTFIELDS, $post_fields); 

// Add headers
$headers = array();
$headers[] = "Authorization: " . $auth_token;
curl_setopt($session, CURLOPT_HTTPHEADER, $headers); 

curl_setopt($session, CURLOPT_POST, true); // HTTP POST
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);  // Receive server response
$server_output = curl_exec($session); // Let's do this!
curl_close ($session); // Clean up
echo ($server_output); // Tell me about the rabbits, George!

Output

{
  "files": [
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886245_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/hello.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    },
    {
      "action": "hide",
      "contentLength": 0,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232323_c100_v0009990_t0005",
      "fileName": "files/world.txt",
      "size": 0,
      "uploadTimestamp": 1439162603000
    },
    {
      "action": "upload",
      "contentLength": 6,
      "fileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886246_d20150809_m232316_c100_v0009990_t0003",
      "fileName": "files/world.txt",
      "size": 6,
      "uploadTimestamp": 1439162596000
    }
  ],
  "nextFileId": "4_z27c88f1d182b150646ff0b16_f100920ddab886247_d20150809_m232316_c100_v0009990_t0003",
  "nextFileName": "files/world.txt"
}