The following examples assume a logged-in session. The options argument is
required even when empty. For shared links, supply url_token and password
together. external_access_token, when needed, also requires that pair.
createDirectory and createFile additionally accept
external_access_token_for_parent_item for access to their parent.
Pass null for the root directory. The privacy flag defaults to false if you
pass undefined; pass it explicitly before the options and callbacks.
sdk.createDirectory(null, 'Documents', false, {}, onSuccess, onError);
Accepts a browser File or an ArrayBuffer. For a File, pass null for the
metadata fields to derive them from the file. With an ArrayBuffer, supply a
title, extension, and MIME type. The privacy flag is required.
const file = new File(['Hello'], 'greeting.txt', { type: 'text/plain' });
sdk.createFile(null, null, null, null, file, false, {}, onSuccess, onError);
With an ArrayBuffer:
const buffer = new TextEncoder().encode('Hello').buffer;
sdk.createFile(null, 'greeting', 'txt', 'text/plain', buffer, false, {}, onSuccess, onError);
getItem accepts an array of item IDs and returns decrypted metadata through
the success callback:
sdk.getItem([123, 456], {}, onSuccess, onError);
Supply the parent directory ID, or -1 for the root. type can be '',
'personal', 'company', 'shared_for_me', or 'shared_by_me'.
sdk.listAllItems(-1, { type: 'personal' }, onSuccess, onError);
Get all active items with false, or request deleted items with true:
sdk.getAllItems(false, onSuccess, onError);
Get descendants of one or more items:
sdk.getItemsDescendants([123], {}, onSuccess, onError);
Pass null for the title or description you want to leave unchanged. Supplying
null for both performs no update.
sdk.updateItem(123, 'New title', null, {}, onSuccess, onError);
sdk.editNote(123, 'Updated note content', {}, onSuccess, onError);
editNote creates updated content for a text file; its callback receives version
data from the API.
Upload a new version using a file of the same type:
const versionFile = new File(['Updated'], 'greeting.txt', { type: 'text/plain' });
sdk.createItemVersion(123, versionFile, {}, onSuccess, onError);
Delete a version by passing the item and version IDs in the expected object:
sdk.deleteItemVersion({ id: 123, version: { id: 456 } }, {}, onSuccess, onError);
Pass the destination directory ID first and the item IDs second. Use -1 for
the root destination. Passing null with an options object currently reports
parent_id_is_missing.
sdk.copyItems(789, [123], {}, onSuccess, onError);
sdk.moveItems(789, [123], {}, onSuccess, onError);
For shared links, these methods accept external_access_token as an array of
strings, rather than the single string used by most other file methods.
Pass item descriptors with itemId; include versionId to select a version.
The success callback receives an array of Blobs for the application to save or
use. This method does not create a browser download link for you.
sdk.downloadItem([{ itemId: 123 }], {}, onSuccess, onError);
sdk.downloadItem([{ itemId: 123, versionId: 456 }], {}, onSuccess, onError);
sdk.permanentlyDeleteItems([123], {}, onSuccess, onError);
Despite its name, permanentlyDeleteItems currently sends a soft-delete
request. Do not rely on it for permanent erasure. There is no public SDK method
for hard deletion or restoring deleted items in this release.