Skip to content

Repository files navigation

cloudagents-node

NPM Version

A node.js client library for the Securibox Cloud Agents API

Install

$ npm install cloudagents

Getting started

The module supports all Cloud Agents API endpoints. For complete information about the API, head to the online documentation.

Endpoints

All endpoints require a valid authentication strategy provided by the Securibox team to access (basic or bearer/JWT).

varCloudAgents=require('cloudagents');varclient=newCloudAgents.Client(cloudagents_env);varauthStrategy=newCloudAgents.BasicStrategy(api_username,api_password);//or authStrategy = new CloudAgents.BearerStrategy("[token]");client.use(authStrategy);

Once an instance of the client has been created you use the following methods:

varCloudAgents=require('cloudagents');// Initialize clientvarclient=newCloudAgents.Client(cloudagents_env);// Initialize authentication strategyvarauthStrategy=newCloudAgents.BasicStrategy(api_username,api_password);// Bind authentication strategy to clientclient.use(authStrategy);//list all categoriesclient.getCategories(callback);//list all agentsclient.getAgents(callback);//list agents by categoryclient.getAgentsByCategory(category_id,callback);//search agentsclient.searchAgents(options,callback);//list all accountsclient.getAllAccounts(options,callback);//list accounts by agentclient.getAllAccounts(options,agent_id,callback);//create accountclient.createAccount(account,callback);//modify accountclient.modifyAccount(account_id,account,callback);//delete accountclient.deleteAccount(account_id,callback);//synchronize accountclient.synchronizeAccount(account_id,user_id,callback);//search accountclient.searchAccounts(options,callback);//search synchronizationsclient.searchSynchronizations(options,callback)//get all syncrhonization for an accountclient.getSynchronizationsByAccount(options,account_id,callback);//get all syncrhonization for an accountclient.getLastSynchronizationByAccount(account_id,callback);//acknowledge synchronization by accountclient.acknowledgeSynchronizationForAccount(account_id,acknowledgement,callback);//search documents by account, user, pending with or without contentclient.searchDocuments(options,callback);//get a specific downloaded documentclient.getDocument(document_id,callback);//acknowledge the reception of a specific documentclient.acknowledgeDocumentDelivery(document_id,callback);//get documents by account idclient.getDocumentsByAccount(options,account_id,callback);

All parameters except options are required. If the options parameter is omitted, the last argument to the function will be interpreted as the callback.

Callbacks

All callbacks are in the form:

functioncallback(err,response){// err can be a network error or a Securibox API error.}

Examples

Collect invoices from DropBox:

varCloudAgents=require('cloudagents');varenvironment="https://sca-multitenant-prod.securibox.eu/api/v1/";// Initialize clientvarclient=newCloudAgents.Client(environment);varbasicAuthentication=newCloudAgents.BasicStrategy('api_username','api_password');client.use(basicAuthentication);//Account to createvaraccount={customerAccountId: 'randomDropboxAccountID',customerUserId: 'UserABCD',name: 'John DropBox account',agentId: '5194a49d6d064d708ed004bc12709241',//Dropbox ID that you can get by listing all available agentscredentials: [{position: 0,value: "mydropboxusername@test.com",alg: null},{position: 1,value: "mydropboxpassword",alg: null}]}//Create account and launch synchronizationclient.createAccount(account,function(err,res){if(err!=null){console.error(err);}else{console.log(res);}});// Pool synchronization status to until we get a final statusvarinterval=setInterval(function(){client.getLastSynchronizationByAccount(account.customerAccountId,function(err,res){eq(err,null);if(res.synchronizationState==CloudAgents.Constants.synchronizationState.PendingAcknowledgement||res.synchronizationState==CloudAgents.Constants.synchronizationState.Completed||res.synchronizationState==CloudAgents.Constants.synchronizationState.ReportFailed){clearInterval(interval);}})},10000);

Tests

$ make test

License

GNU GPL

About

A node.js module for the Securibox Cloud Agents API

Resources

Stars

0 stars

Watchers

4 watching

Forks

Releases

Packages

Used by

Contributors

Languages