SpringCM Node.js REST API SDK
This SDK currently provides a limited feature set, as it was created and is developed primarily for internal IT work at Stria.
Accessing the REST API requires you create an API user in your SpringCM account and assign a client ID to that user in the REST API section of Account Preferences. Once set, you can use the API by providing the client ID and corresponding secret. The client ID and client secret are provided by SpringCM's support staff on request. For more information, visit this webpage.
Examples
Below are a few usage examples. Be sure to check the tests folder for more
examples.
SpringCM Client
Connect
Before you can interact with your SpringCM account, you need to connect via
the SpringCM client.
const SpringCM = require('springcm-node-sdk');
var springCm = new SpringCM({
clientId: 'your_client_id',
clientSecret: 'your_client_secret',
dataCenter: 'uatna11'
});
springCm.connect((err) => {
});
Disconnect
Once you are done using the SpringCM client, you should close the connection,
especially if your program is going to close immediately. Closing the
connection ensures all queued requests and operations are completed.
Comments shown below are only applicable when execution reaches that line,
i.e. comment #3 occurs after #2.
springCm.close(() => {
});
Folders
Root folder
springCm.getRootFolder((err, root) => {
});
Subfolders
springCm.getRootFolder((err, root) => {
springCm.getSubfolders(root, (err, folders) => {
});
});
Get folder by path
springCm.getFolder('/HR/Employee Files', (err, folder) => {
});
Get folder by UID
If you'll know the UID of a folder beforehand, you can reference it by this
UID.
springCm.getFolder('758afbfa-1f18-e812-9d16-3ca24a1e3f40', (err, folder) => {
});
Subfolder pages
If you have a folder with a large number of subfolders, you may want to
use paging. To do so, pass an options object as the second argument instead
of the callback.
springCm.getSubfolders(parent, {
offset: 0,
limit: 20
}, (err, folders) => {
});
Create a folder
You can create a new folder, or retrieve an existing folder by setting the
exclusive
option. By default, all folder creation is exclusive, meaning
the operation will fail if the folder already exists. Note that this only
applies to the base folder, i.e. creating /Contracts/ACME, Inc
with
exclusive
set to true
will succeed even if /Contracts
already exists.
springCm.createFolder('/Contracts/PseudoTech, LLC', (err, folder) => {
});
springCm.createFolder('/Contracts/ACME, Inc', { exclusive: false }, (err, folder) => {
});
Upload document to a folder
springCm.getFolder('/Deliveries/Contracts', (err, folder) => {
springCm.uploadDocument(folder, fs.createReadStream('ACME, Inc 2018.pdf'), (err, doc) => {
});
});
Documents
Get document by path
springCm.getDocument('/Contracts/ACME, Inc 01-01-2010.pdf', (err, doc) => {
});
Get document by UID
springCm.getDocument('127bd4e1-368e-1878-9651-ed101cabfdff', (err, doc) => {
});
Download document
springCm.downloadDocument('127bd4e1-368e-1878-9651-ed101cabfdff', fs.createWriteStream('./Downloaded.pdf'), (err) => {
});
springCm.getDocument('/Contracts/ACME, Inc - Signed.pdf', (err, doc) => {
springCm.downloadDocument(doc, fs.createWriteStream('./Signed.pdf'), (err) => {
});
});
Delete document
springCm.deleteDocument('/Contracts/ACME, Inc - Old.pdf', (err) => {
});
Move document
You can reference the source document and target folder by path, UID, or
with an existing object of the corresponding type, e.g.
springCm.moveDocument('/Contracts/ACME, Inc.pdf', '/New Contracts/ACME, Inc/', (err) => {
});
springCm.moveDocument('96803885-47f6-4361-9747-1d5962b3b7a4', '/Board Minutes', (err) => {
});
springCm.getDocument('96803885-47f6-4361-9747-1d5962b3b7a4', (err, doc) => {
springCm.moveDocument(doc, '/Trash', (err) => {
});
});
Query CSV data
springCm.csvLookup('/Admin/Customer Data.csv', {
'Customer Name': 'ACME, Inc.'
}, (err, rows) => {
});