Files.com JavaScript SDK
The Files.com JavaScript SDK, currently at version 1.2.610, provides a direct, high-performance integration with the Files.com cloud-native MFT, SFTP, and secure file-sharing platform. It enables applications to programmatically interact with files, folders, users, automations, and other administrative tasks through Files.com's RESTful APIs over HTTPS. This SDK is a core internal component for Files.com, ensuring it is actively maintained, continuously updated, and performant. Releases are frequent, following a MAJOR.MINOR.BUILDNUMBER semantic versioning, where MAJOR or MINOR changes may introduce breaking changes, and BUILDNUMBER updates are generally non-disruptive. Key differentiators include unifying SFTP, AS2, and HTTPS protocols, offering 50+ native connectors, military-grade encryption, and a unified platform for governance, visibility, and compliance, aiming to replace brittle legacy file transfer solutions with a robust, always-on fabric for automating mission-critical file flows.
Common errors
-
TypeError: files_com_lib_Files_js__WEBPACK_IMPORTED_MODULE_0__.default is not a constructor
cause Attempting to use a CommonJS `require()` without appending `.default` to access the main export in a mixed ES module environment, or incorrect ES Module interop.fixIf using CommonJS `require()`, ensure you append `.default`: `const Files = require('files.com/lib/Files.js').default;`. If using ES modules, ensure your build system correctly handles exports. -
Error: No API key provided
cause The SDK was initialized or an API call was made without a global API key set via `Files.setApiKey()` or a per-request/per-object API key provided.fixSet the API key globally with `Files.setApiKey('YOUR_API_KEY');` at application startup, or provide it as an option in specific API calls or model constructors: `new User(params, { apiKey: 'YOUR_API_KEY' });`. -
Module not found: Error: Can't resolve 'files.com/Files'
cause Incorrect import path for an SDK module. The SDK modules are nested under the `lib/` directory.fixCorrect the import path to include `/lib/`, for example: `import Files from 'files.com/lib/Files.js';` or `const Files = require('files.com/lib/Files.js').default;`. -
FilesApiError: Bad credentials (Status: 401)
cause The provided API key is invalid, revoked, expired, or does not have sufficient permissions for the attempted operation.fixVerify the API key in your Files.com account, ensuring it is active and has the necessary permissions. Regenerate the key if necessary. Check if a user-specific API key has administrative privileges if administrative actions are being performed.
Warnings
- gotcha When using CommonJS `require()` syntax for SDK modules, you must append `.default` to access the main export (e.g., `require('files.com/lib/Files.js').default`). Omitting this will result in runtime errors.
- gotcha API keys have different scopes. User-specific API keys only grant access based on that user's permissions. An administrator's API key provides full access, while a non-administrator's key restricts access to only files the user can access, without site administration functions.
- gotcha The import paths for SDK modules are specific and typically include `/lib/` (e.g., `files.com/lib/Files.js` or `files.com/lib/models/User.js`). Directly importing from `files.com` without `/lib/` will result in module not found errors.
- gotcha While `Files.setApiKey()` configures a global API key, it's possible to override this on a per-request or per-object basis by passing `{ apiKey: 'YOUR_KEY' }` in the options parameter of model constructors or API calls. This is important for multi-tenancy or different permission contexts.
- gotcha The Files.com SDK uses HTTPS (port 443) for all communication. While firewall changes are typically not required, connectivity issues might arise if outgoing HTTPS traffic on port 443 is blocked by network policies.
- breaking Files.com SDKs follow semantic versioning (MAJOR.MINOR.BUILDNUMBER). Major or minor version changes may introduce breaking changes, requiring review before upgrading. Build number changes are generally non-disruptive bug fixes or performance improvements.
Install
-
npm install files.com -
yarn add files.com -
pnpm add files.com
Imports
- Files
const Files = require('files.com/lib/Files.js')import Files from 'files.com/lib/Files.js';
- User
const User = require('files.com/lib/models/User.js')import User from 'files.com/lib/models/User.js';
- FilesApiError
const FilesApiError = require('files.com/lib/Errors')import { FilesApiError } from 'files.com/lib/Errors';
Quickstart
import Files from 'files.com/lib/Files.js';
import User from 'files.com/lib/models/User.js';
import * as FilesErrors from 'files.com/lib/Errors';
const API_KEY = process.env.FILESCOM_API_KEY ?? '';
if (!API_KEY) {
console.error('FILESCOM_API_KEY environment variable is not set.');
process.exit(1);
}
Files.setApiKey(API_KEY);
async function fetchCurrentUser() {
try {
// Retrieve the current authenticated user's details
const user = await User.current();
console.log(`Successfully authenticated as user: ${user.name} (ID: ${user.id})`);
console.log('User details:', user.attributes);
} catch (error) {
if (error instanceof FilesErrors.FilesApiError) {
console.error(`Files.com API Error: ${error.message} (Status: ${error.httpStatus})`);
} else {
console.error('An unexpected error occurred:', error);
}
process.exit(1);
}
}
fetchCurrentUser();