b2_list_keys
Lists application keys associated with an account.
Request
Request HTTP Headers
Authorization
required
An authorization token, obtained from
b2_authorize_account
.
The token must have the listKeys
capability.
Request HTTP Message Body Parameters
accountId
required
The ID of your account.
maxKeyCount
optional
The maximum number of keys to return in the response. Default is 100, maximum is 10000.
NOTE:
b2_list_keys
is a Class C transaction
(see Pricing).
The maximum number of keys returned per transaction is
1000. If you set maxKeyCount 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
maxKeyCount to 10000 and 3123 keys are returned, you
will be billed for 4 Class C transactions.
startApplicationKeyId
optional
The first key to return. Used when a query hits the maxKeyCount, and you want to get more. Set to the value returned as the nextApplicationKeyId in the previous query.
Response
Response HTTP Status 200
Key list as a JSON response:
keys
An array of key objects (see below).
nextApplicationKeyId
optional
Set if there are more keys beyond the ones that were returned.
Pass this value the startApplicationKeyId in the next query to continue listing keys.
Note that this value may not be a valid application key ID, but can still be
used as the starting point for the next query.
Each of the items in the array of keys:
keyName
required
The name assigned when the key was created.
applicationKeyId
required
The ID of the newly created key.
capabilities
required
A list of strings, each one naming a capability the key has.
Possibilities are:
listKeys
,
writeKeys
,
deleteKeys
,
listAllBucketNames
,
listBuckets
,
readBuckets
,
writeBuckets
,
deleteBuckets
,
readBucketRetentions
,
writeBucketRetentions
,
readBucketEncryption
,
writeBucketEncryption
,
listFiles
,
readFiles
,
shareFiles
,
writeFiles
,
deleteFiles
,
readFileLegalHolds
,
writeFileLegalHolds
,
readFileRetentions
,
writeFileRetentions
,
bypassGovernance
,
readBucketReplications
, and
writeBucketReplications
.
accountId
required
The account that this application key is for.
expirationTimestamp
optional
When present, says when this key will expire, in milliseconds since 1970.
bucketId
optional
When present, restricts access to one bucket.
namePrefix
optional
When present, restricts access to files whose names start with the prefix.
options
optional
When present and set to s3
, the key can be used to sign requests to
the S3 Compatible API.
Response Errors
Unable to return key list.
If possible the server will return a JSON error structure. Errors include:
status |
code |
description |
---|---|---|
400 |
bad_bucket_id |
The requested bucket ID does not match an existing bucket. |
400 |
bad_request |
The request had the wrong fields or illegal values. The message returned with the error will describe the problem. |
400 |
cannot_delete_non_empty_bucket |
A bucket must be empty before it can be deleted. To delete this bucket, first remove all of the files in the bucket, then try the delete operation again. |
401 |
bad_auth_token |
The auth token used is not valid. Call b2_authorize_account again to either get a new one, or an error message describing the problem. |
401 |
expired_auth_token |
The auth token used has expired. Call b2_authorize_account again to get a new one. |
401 |
unauthorized |
The auth token used is valid, but does not authorize this call with these parameters. The capabilities of an auth token are determined by the application key used with b2_authorize_account. |
403 |
transaction_cap_exceeded |
Transaction cap exceeded. To increase your cap, sign in to your B2 Cloud Storage account online. Then select the Caps & Alerts link in the B2 Cloud Storage section of the sidebar. |
Sample Code
Code
ACCOUNT_AUTHORIZATION_TOKEN = "" # Provided by b2_authorize_account
ACCOUNT_ID = "" # Provided by b2_authorize_account
API_URL = "" # Provided by b2_authorize_account
curl -H "Authorization: ${ACCOUNT_AUTHORIZATION_TOKEN}" \
"${API_URL}/b2api/v2/b2_list_keys?accountId=${ACCOUNT_ID}"
Output
{
"keys": [
{
"accountId": "12f634bf3cby",
"applicationKeyId": "00512f95cf4dcf0000000004y",
"bucketId": null,
"capabilities": [
"listKeys",
"writeKeys",
"deleteKeys",
"listBuckets",
"writeBuckets",
"deleteBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption",
"bypassGovernance",
"readBucketRetentions",
"writeBucketRetentions",
"readFileRetentions",
"writeFileRetentions",
"readFileLegalHolds",
"writeFileLegalHolds"
],
"expirationTimestamp": null,
"keyName": "all-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
},
{
"accountId": "12f634bf3cbz",
"applicationKeyId": "00512f95cf4dcf0000000004z",
"bucketId": "e1256f0973908bfc71ed0c1z",
"capabilities": [
"listAllBucketNames",
"listBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption"
],
"expirationTimestamp": null,
"keyName": "backup-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
}
],
"nextApplicationKeyId": null
}
Code
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
public class ListKeys {
public static void main(String[] args) {
String apiUrl = ""; // Provided by b2_authorize_account
String accountId = ""; // Provided by b2_authorize_account
String accountAuthorizationToken = ""; // Provided by b2_authorize_account
HttpURLConnection connection = null;
try {
URL url = new URL(apiUrl + "/b2api/v2/b2_list_keys?accountId=" + accountId);
connection = (HttpURLConnection)url.openConnection();
connection.setRequestProperty("Authorization", accountAuthorizationToken);
String jsonResponse = myInputStreamReader(connection.getInputStream());
System.out.println(jsonResponse);
} catch (Exception e) {
e.printStackTrace();
} finally {
if (connection != null) {
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
{
"keys": [
{
"accountId": "12f634bf3cby",
"applicationKeyId": "00512f95cf4dcf0000000004y",
"bucketId": null,
"capabilities": [
"listKeys",
"writeKeys",
"deleteKeys",
"listBuckets",
"writeBuckets",
"deleteBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption",
"bypassGovernance",
"readBucketRetentions",
"writeBucketRetentions",
"readFileRetentions",
"writeFileRetentions",
"readFileLegalHolds",
"writeFileLegalHolds"
],
"expirationTimestamp": null,
"keyName": "all-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
},
{
"accountId": "12f634bf3cbz",
"applicationKeyId": "00512f95cf4dcf0000000004z",
"bucketId": "e1256f0973908bfc71ed0c1z",
"capabilities": [
"listAllBucketNames",
"listBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption"
],
"expirationTimestamp": null,
"keyName": "backup-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
}
],
"nextApplicationKeyId": null
}
Code
import requests
api_url = "" # Provided by b2_authorize_account
account_id = "" # Provided by b2_authorize_account
account_authorization_token = "" # Provided by b2_authorize_account
response = requests.get(f'{api_url}/b2api/v2/b2_list_keys',
params={'accountId': account_id},
headers={'Authorization': account_authorization_token})
print(response.text)
Output
{
"keys": [
{
"accountId": "12f634bf3cby",
"applicationKeyId": "00512f95cf4dcf0000000004y",
"bucketId": null,
"capabilities": [
"listKeys",
"writeKeys",
"deleteKeys",
"listBuckets",
"writeBuckets",
"deleteBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption",
"bypassGovernance",
"readBucketRetentions",
"writeBucketRetentions",
"readFileRetentions",
"writeFileRetentions",
"readFileLegalHolds",
"writeFileLegalHolds"
],
"expirationTimestamp": null,
"keyName": "all-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
},
{
"accountId": "12f634bf3cbz",
"applicationKeyId": "00512f95cf4dcf0000000004z",
"bucketId": "e1256f0973908bfc71ed0c1z",
"capabilities": [
"listAllBucketNames",
"listBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption"
],
"expirationTimestamp": null,
"keyName": "backup-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
}
],
"nextApplicationKeyId": null
}
Code
import Foundation
let apiUrl = "" // Provided by b2_authorize_account
let accountId = "" // Provided by b2_authorize_account
let accountAuthorizationToken = "" // Provided by b2_authorize_account
// Create the request
var request = URLRequest(url: URL(string: "\(apiUrl)/b2api/v2/b2_list_keys?accountId=\(accountId)")!)
request.addValue(accountAuthorizationToken, forHTTPHeaderField: "Authorization")
// Create the task
let task = URLSession.shared.dataTask(with: request) { (data, response, error) in
if let data = data {
let json = String(data: data, encoding: .utf8)
print("\(json!)")
}
}
// Start the task
task.resume()
Output
{
"keys": [
{
"accountId": "12f634bf3cby",
"applicationKeyId": "00512f95cf4dcf0000000004y",
"bucketId": null,
"capabilities": [
"listKeys",
"writeKeys",
"deleteKeys",
"listBuckets",
"writeBuckets",
"deleteBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption",
"bypassGovernance",
"readBucketRetentions",
"writeBucketRetentions",
"readFileRetentions",
"writeFileRetentions",
"readFileLegalHolds",
"writeFileLegalHolds"
],
"expirationTimestamp": null,
"keyName": "all-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
},
{
"accountId": "12f634bf3cbz",
"applicationKeyId": "00512f95cf4dcf0000000004z",
"bucketId": "e1256f0973908bfc71ed0c1z",
"capabilities": [
"listAllBucketNames",
"listBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption"
],
"expirationTimestamp": null,
"keyName": "backup-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
}
],
"nextApplicationKeyId": null
}
Code
require 'json'
require 'net/http'
api_url = "" # Provided by b2_authorize_account
account_id = "" # Provided by b2_authorize_account
account_authorization_token = "" # Provided by b2_authorize_account
uri = URI("#{api_url}/b2api/v2/b2_list_keys?accountId=#{account_id}")
req = Net::HTTP::Get.new(uri)
req.add_field("Authorization","#{account_authorization_token}")
http = Net::HTTP.new(req.uri.host, req.uri.port)
http.use_ssl = true
res = http.start {|http| http.request(req)}
case res
when Net::HTTPSuccess then
puts res.body
when Net::HTTPRedirection then
fetch(res['location'], limit - 1)
else
res.error!
end
Output
{
"keys": [
{
"accountId": "12f634bf3cby",
"applicationKeyId": "00512f95cf4dcf0000000004y",
"bucketId": null,
"capabilities": [
"listKeys",
"writeKeys",
"deleteKeys",
"listBuckets",
"writeBuckets",
"deleteBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption",
"bypassGovernance",
"readBucketRetentions",
"writeBucketRetentions",
"readFileRetentions",
"writeFileRetentions",
"readFileLegalHolds",
"writeFileLegalHolds"
],
"expirationTimestamp": null,
"keyName": "all-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
},
{
"accountId": "12f634bf3cbz",
"applicationKeyId": "00512f95cf4dcf0000000004z",
"bucketId": "e1256f0973908bfc71ed0c1z",
"capabilities": [
"listAllBucketNames",
"listBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption"
],
"expirationTimestamp": null,
"keyName": "backup-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
}
],
"nextApplicationKeyId": null
}
Code
using System.Net;
using System.Net.Http;
var apiUrl = ""; //Provided by b2_authorize_account
var accountAuthorizationToken = ""; //Provided by b2_authorize_account
var accountId = ""; //Provided by b2_authorize_account
HttpClient client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Get,
new Uri(apiUrl + "/b2api/v2/b2_list_keys?accountId=" + accountId));
request.Headers.TryAddWithoutValidation("Authorization", accountAuthorizationToken);
using var response = await client.SendAsync(request);
var responseBody = await response.Content.ReadAsStringAsync();
Console.WriteLine(responseBody);
Output
{
"keys": [
{
"accountId": "12f634bf3cby",
"applicationKeyId": "00512f95cf4dcf0000000004y",
"bucketId": null,
"capabilities": [
"listKeys",
"writeKeys",
"deleteKeys",
"listBuckets",
"writeBuckets",
"deleteBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption",
"bypassGovernance",
"readBucketRetentions",
"writeBucketRetentions",
"readFileRetentions",
"writeFileRetentions",
"readFileLegalHolds",
"writeFileLegalHolds"
],
"expirationTimestamp": null,
"keyName": "all-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
},
{
"accountId": "12f634bf3cbz",
"applicationKeyId": "00512f95cf4dcf0000000004z",
"bucketId": "e1256f0973908bfc71ed0c1z",
"capabilities": [
"listAllBucketNames",
"listBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption"
],
"expirationTimestamp": null,
"keyName": "backup-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
}
],
"nextApplicationKeyId": null
}
Code
$account_id = ""; // From b2_authorize_account call
$api_url = ""; // From b2_authorize_account call
$auth_token = ""; // From b2_authorize_account call
$session = curl_init($api_url . "/b2api/v2/b2_list_keys?accountId=" . $account_id);
// Add headers
$headers = array();
$headers[] = "Authorization: " . $auth_token;
curl_setopt($session, CURLOPT_HTTPHEADER, $headers);
curl_setopt($session, CURLOPT_RETURNTRANSFER, true);
$server_output = curl_exec($session);
curl_close ($session);
echo ($server_output);
Output
{
"keys": [
{
"accountId": "12f634bf3cby",
"applicationKeyId": "00512f95cf4dcf0000000004y",
"bucketId": null,
"capabilities": [
"listKeys",
"writeKeys",
"deleteKeys",
"listBuckets",
"writeBuckets",
"deleteBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption",
"bypassGovernance",
"readBucketRetentions",
"writeBucketRetentions",
"readFileRetentions",
"writeFileRetentions",
"readFileLegalHolds",
"writeFileLegalHolds"
],
"expirationTimestamp": null,
"keyName": "all-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
},
{
"accountId": "12f634bf3cbz",
"applicationKeyId": "00512f95cf4dcf0000000004z",
"bucketId": "e1256f0973908bfc71ed0c1z",
"capabilities": [
"listAllBucketNames",
"listBuckets",
"readBuckets",
"listFiles",
"readFiles",
"shareFiles",
"writeFiles",
"deleteFiles",
"readBucketEncryption",
"writeBucketEncryption"
],
"expirationTimestamp": null,
"keyName": "backup-bucket-key",
"namePrefix": null,
"options": [
"s3"
]
}
],
"nextApplicationKeyId": null
}