API Keys

An APIKey is a key that allows programmatic access to your Site.

API keys use the owning user's permissions, narrowed by the key's permission set, workspace scope, and any folder path restriction. If an API key is created without a user owner, it is considered a site-wide API key. Site-wide API keys with the files_only permission set are restricted to file-user permissions and workspace scoping.

Set path when creating a key to limit file and folder access to that folder and its descendants. Except for office_integration keys, the path does not need to exist when the key is created. The restriction applies to the files, folders, and file_actions endpoints, on every path those requests access, including both source and destination paths for copy and move operations. Requests to those endpoints outside the restriction are denied with not-authorized/api-key-is-path-restricted. It never grants additional access to the owning user. A key with the files_only permission set can use only those endpoints, plus GET /file_migrations/{id} to follow file operations under the visibility rules below and GET /api_key to read its own record. Every other endpoint denies a files_only key with not-authorized/api-key-only-for-file-operations.

On GET /file_migrations/{id}, any key with a path can read only migrations it started. Without a path, user-owned keys retain their user-scoped access, including Desktop and Mobile keys in the owning user's Workspace. A site-wide key bound to a Workspace can read a migration only when its source and destination are both in that Workspace. Workspace binding applies to every files_only key, including Workspace 0, and to full-access keys in a named Workspace. A full-access site-wide key in the default Workspace can read migrations across the Site. Migrations outside the caller's visibility return not-found.

We recommend registering API keys to service users wherever possible and then using User or Group Permissions to restrict that API Key appropriately.

List API Keys

SDK Function

ApiKey.list()

Return Object

ListIterator<ApiKey>

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

Function Arguments

ArgumentDescription
user_id
int64
User ID. Provide a value of 0 to operate the current session's user.

Additional Arguments

Example Request

import com.files.ListIterator;
import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.ApiKey;

try {
  HashMap<String, Object> parameters = new HashMap<>();
  parameters.put("user_id", 1);
  
  ListIterator<ApiKey> apiKeys = ApiKey.list(parameters);
  for (ApiKey apiKey : apiKeys.listAutoPaging()) {
    // Operate on apiKey
  }
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Show information about current API key. (Requires current API connection to be using an API key.)

SDK Function

ApiKey.findCurrent()

Return Object

ApiKey

Authorization Requirement

Available to all authenticated keys or sessions.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.ApiKey;

try {
  ApiKey apiKey = ApiKey.findCurrent();
  // Operate on apiKey
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Show API Key

SDK Function

ApiKey.find()

Return Object

ApiKey

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

Function Arguments

ArgumentDescription
id
int64
Required
Api Key ID.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.ApiKey;

try {
  HashMap<String, Object> parameters = new HashMap<>();
  ApiKey apiKey = ApiKey.find(id, parameters);
  // Operate on apiKey
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Create API Key

SDK Function

ApiKey.create()

Return Object

ApiKey

Authorization Requirement

Available to all authenticated keys or sessions.

Function Arguments

ArgumentDefaultDescription
user_id
int64
User ID. Provide a value of 0 to operate the current session's user.
description
string
User-supplied description of API key.
expires_at
string
API Key expiration date
name
string
Required
""Internal name for the API Key. For your use.
aws_style_credentials
boolean
falseIf true, this API key will be usable with AWS-compatible endpoints, such as our Inbound S3-compatible endpoint.
path
string
Restricts the file and folder operations made with this key, meaning the files, folders, and file_actions endpoints, to the specified folder and its descendants, including copy and move destinations. For GET /file_migrations/&#123;id&#125;, a key with a path can read only migrations it started. Other endpoints do not apply the path restriction; use the files_only permission set to confine a key to file operations and their supporting lookups. Does not grant access beyond the owning user's permissions. Optional except for office_integration keys, which require a path the owning user can read.
permission_set
string
"full"Permissions for this API Key. Keys with the desktop_app permission set only have the ability to do the functions provided in our Desktop App (File and Share Link operations). Keys with the office_integration permission set are auto generated, and automatically expire, to allow users to interact with office integration platforms. Keys with the files_only permission set can use only the files, folders, and file_actions endpoints, where they perform file operations as a full-access file user in the key's workspace scope, along with GET /file_migrations/&#123;id&#125; and GET /api_key. On the migration lookup, any key with a path can read only migrations it started. Without a path, user-owned keys retain user-scoped access; site-wide Workspace-bound keys can read only migrations whose source and destination are both in their Workspace. Every files_only key is Workspace-bound, including Workspace 0, as is a full-access key in a named Workspace. A full-access site-wide key in the default Workspace retains Site-wide migration access. Migrations outside the caller's visibility return not-found. Keys with files_only cannot use site admin, workspace admin, folder admin, group admin, partner admin, or billing privileges from the owning user, and every other endpoint denies them with not-authorized/api-key-only-for-file-operations.
Possible values: none, full, desktop_app, sync_app, office_integration, mobile_app, files_only
workspace_id
int64
0Workspace ID for this API Key. 0 means the default workspace.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.ApiKey;

try {
  HashMap<String, Object> parameters = new HashMap<>();
  parameters.put("name", "My Main API Key");
  
  ApiKey apiKey = ApiKey.create(parameters);
  // Operate on apiKey
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Update current API key. (Requires current API connection to be using an API key.)

SDK Function

ApiKey.updateCurrent()

Return Object

ApiKey

Authorization Requirement

Available to all authenticated keys or sessions.

Function Arguments

ArgumentDescription
expires_at
string
API Key expiration date
name
string
Internal name for the API Key. For your use.
permission_set
string
Permissions for this API Key. Keys with the desktop_app permission set only have the ability to do the functions provided in our Desktop App (File and Share Link operations). Keys with the office_integration permission set are auto generated, and automatically expire, to allow users to interact with office integration platforms. Keys with the files_only permission set can use only the files, folders, and file_actions endpoints, where they perform file operations as a full-access file user in the key's workspace scope, along with GET /file_migrations/&#123;id&#125; and GET /api_key. On the migration lookup, any key with a path can read only migrations it started. Without a path, user-owned keys retain user-scoped access; site-wide Workspace-bound keys can read only migrations whose source and destination are both in their Workspace. Every files_only key is Workspace-bound, including Workspace 0, as is a full-access key in a named Workspace. A full-access site-wide key in the default Workspace retains Site-wide migration access. Migrations outside the caller's visibility return not-found. Keys with files_only cannot use site admin, workspace admin, folder admin, group admin, partner admin, or billing privileges from the owning user, and every other endpoint denies them with not-authorized/api-key-only-for-file-operations.
Possible values: none, full, desktop_app, sync_app, office_integration, mobile_app, files_only

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.ApiKey;

try {
  HashMap<String, Object> parameters = new HashMap<>();
  parameters.put("expires_at", "2000-01-01T01:00:00Z");
  
  ApiKey apiKey = ApiKey.updateCurrent(parameters);
  // Operate on apiKey
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Update API Key

SDK Function

apiKey.update();

Return Object

ApiKey

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

Attribute Setters

SetterDescription
setDescription
string
User-supplied description of API key.
setExpiresAt
string
API Key expiration date
setName
string
Internal name for the API Key. For your use.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.ApiKey;

try {
  // Find the apiKey object by its id.
  ApiKey apiKey = ApiKey.find(id, null);
  HashMap<String, Object> parameters = new HashMap<>();
  parameters.put("description", "example");
  apiKey.update(parameters);
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Delete current API key. (Requires current API connection to be using an API key.)

SDK Function

ApiKey.deleteCurrent()

Return Object

No return value.

Authorization Requirement

Available to all authenticated keys or sessions.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.ApiKey;

try {
  ApiKey.deleteCurrent();
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

Delete API Key

SDK Function

apiKey.delete();

Return Object

No return value.

Authorization Requirement

Not available to user API keys or sessions from users that are marked as Shared/Bot users.

Example Request

import com.files.exceptions.*;
import com.files.exceptions.ApiErrorException.*;
import com.files.models.ApiKey;

try {
  // Find the apiKey object by its id.
  ApiKey apiKey = ApiKey.find(id, null);
  apiKey.delete(null);
} catch (NotAuthenticatedException e) {
  System.out.println("Authentication Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
} catch (SdkException e) {
  System.out.println("Unknown Error Occurred (" + e.getClass().getName() + "): " + e.getMessage());
}

The ApiKey Object

Some of the functions above return a ApiKey object. The attributes of this object are listed below.

AttributeDescription
id
int64
API Key ID
descriptive_label
string
Unique label that describes this API key. Useful for external systems where you may have API keys from multiple accounts and want a human-readable label for each key.
description
string
User-supplied description of API key.
created_at
date-time
Time which API Key was created
expires_at
date-time
API Key expiration date
key
string
API Key actual key string
aws_style_credentials
boolean
If true, this API key will be usable with AWS-compatible endpoints, such as our Inbound S3-compatible endpoint.
aws_access_key_id
string
AWS Access Key ID to use with AWS-compatible endpoints, such as our Inbound S3-compatible endpoint.
aws_secret_key
string
AWS Secret Key to use with AWS-compatible endpoints, such as our Inbound S3-compatible endpoint.
last_use_at
date-time
API Key last used - note this value is only updated once per 3 hour period, so the 'actual' time of last use may be up to 3 hours later than this timestamp.
name
string
Internal name for the API Key. For your use.
permission_set
string
Permissions for this API Key. Keys with the desktop_app permission set only have the ability to do the functions provided in our Desktop App (File and Share Link operations). Keys with the office_integration permission set are auto generated, and automatically expire, to allow users to interact with office integration platforms. Keys with the files_only permission set can use only the files, folders, and file_actions endpoints, where they perform file operations as a full-access file user in the key's workspace scope, along with GET /file_migrations/&#123;id&#125; and GET /api_key. On the migration lookup, any key with a path can read only migrations it started. Without a path, user-owned keys retain user-scoped access; site-wide Workspace-bound keys can read only migrations whose source and destination are both in their Workspace. Every files_only key is Workspace-bound, including Workspace 0, as is a full-access key in a named Workspace. A full-access site-wide key in the default Workspace retains Site-wide migration access. Migrations outside the caller's visibility return not-found. Keys with files_only cannot use site admin, workspace admin, folder admin, group admin, partner admin, or billing privileges from the owning user, and every other endpoint denies them with not-authorized/api-key-only-for-file-operations.
Possible values: none, full, desktop_app, sync_app, office_integration, mobile_app, files_only
platform
string
If this API key represents a Desktop app, what platform was it created on?
site_id
int64
Site ID
site_name
string
Site Name
url
string
URL for API host.
user_id
int64
User ID for the owner of this API Key. May be blank for Site-wide API Keys.
workspace_id
int64
Workspace ID for this API Key. 0 means the default workspace.