BaseCRM Official API V2 library client for NodeJS
$ npm install basecrm
var BaseCRM = require('basecrm');
Using this api without authentication gives an error
// BaseCRM equal to BaseCRM.Client
var client = new BaseCRM.Client({
accessToken: '<YOUR_PERSONAL_ACCESS_TOKEN>'
});
The following options are available while instantiating a client:
- accessToken: Personal access token
- baseUrl: Base url for the api
- timeout: Request timeout
Most of the resources now have a Model API, read the details in the documentations below.
- Account
- Associated Contacts
- Contacts
- Deal Sources
- Deals
- Lead Sources
- Leads
- Line Items
- Loss Reasons
- Notes
- Orders
- Pipelines
- Products
- Stages
- Tags
- Tasks
- Users
The following sample code shows how to perform a full synchronization flow using high-level wrapper.
First of all you need an instance of BaseCRM.Client
. High-level BaseCRM.Sync
wrapper uses BaseCRM.Sync.Service
to interact with the Sync API.
In addition to the client instance, you must provide a device’s UUID within deviceUUID
parameter. The device’s UUID must not change between synchronization sessions, otherwise the sync service will not recognize the device and will send all the data again.
var client = new BaseCRM.Client({
accessToken: '<YOUR_PERSONAL_ACCESS_TOKEN>'
});
var sync = new BaseCRM.Sync(client, '<YOUR_DEVICES_UUID>');
Now all you have to do is to call fetch
method and pass a block that you might use to store fetched data to a database.
var db = [];
sync.fetch(function(type, action, data) {
return db.indexOf(type + '_' + JSON.stringify(data)) ? BaseCRM.Sync.ACK : BaseCRM.Sync.NACK;
});
Notice that you must return BaseCRM.Sync.ACK
or BaseCRM.Sync.NACK
.
MIT
Report here.