- Print
- DarkLight
Call the Native API
- Print
- DarkLight
Most of the API calls for Backblaze B2 Cloud Storage accept a POST with JSON data and return JSON data.
Constructing the URL
For most calls, construct the URL by combining the following elements:
- The
apiUrl
that is returned by b2_authorize_account /b2api
/v
versionNumber/
apiName
The version number indicates which version of the API that you want to call. The API name indicates which API entry point that you want to call. The resulting URL looks like the following example if you call version 3, the current version, of b2_list_file_names:
https://api123.backblazeb2.com/b2api/v3/b2_list_file_names
Authorizing an Account
The call to b2_authorize_account is unique because the API URL is fixed: https://api.backblazeb2.com, so the full URL looks like the following example:
https://api.backblazeb2.com/b2api/v3/b2_authorize_account
v2
with b2_authorize_account for B2 Native API calls if the Partner API is enabled on your account.POST JSON -> JSON
The typical case for API calls to Backblaze B2 is to create a request as a JSON object, POST it to the Backblaze B2 service, and receive a JSON object in the response.
The following example shows a request using cURL on the command-line:
ACCOUNT_ID=... # Comes from your account page on the Backblaze web site
ACCOUNT_AUTH_TOKEN=... # Comes from the b2_authorize_account call
API_URL=... # Comes from the b2_authorize_account call
BUCKET_NAME=any_name_you_pick # 63 char max: letters, digits, and hyphen -
BUCKET_TYPE=allPrivate # Either allPublic or allPrivate
curl -H "Authorization: $ACCOUNT_AUTH_TOKEN" \
-d "{\"accountId\": \"$ACCOUNT_ID\", \"bucketName\": \"$BUCKET_NAME\", \"bucketType\": \"$BUCKET_TYPE\"}" \
"$API_URL/b2api/v3/b2_create_bucket"
The following example shows a JSON response:
{
"bucketId" : "e1256f0973908bfc71ed0c1z",
"accountId" : "12f634bf3cbz",
"bucketName" : "any_name_you_pick",
"bucketType" : "allPrivate"
}
GET -> JSON
All API calls that accept POST-ed JSON also accept the parameters as URL query parameters. This is convenient for ad-hoc requests that you type by hand and for using in a browser.
The following request example is equivalent to the example above:
ACCOUNT_ID=... # Application Key from the Backblaze web site
ACCOUNT_AUTH_TOKEN=... # Comes from the b2_authorize_account call
API_URL=... # Comes from the b2_authorize_account call
BUCKET_NAME=any_name_you_pick # 63 char max: letters, digits, and hyphen -
BUCKET_TYPE=allPrivate # Either allPublic or allPrivate
curl -H "Authorization: $ACCOUNT_AUTH_TOKEN" \
"$API_URL/b2api/v3/b2_create_bucket?accountId=$ACCOUNT_ID&bucketName=$BUCKET_NAME&bucketType=$BUCKET_TYPE"