This page contains information on the SDK's classes, methods and functions.
A client for EasilyDo's Sift API. Sift is an Artificial Intelligence for Email that creates relevant features for your users with an email parse API that simplifies and understands mail.
You can read more about Sift here.
The SiftAPI object returns a Promise for each of the API endpoint implemented. You can read more about Promises [here](https://developer.mozilla.org/en-US/do cs/Web/JavaScript/Reference/Global_Objects/Promise).
Parameters
apiKey- Astringthat can be found from the [developer's dashboard](htt ps://sift.easilydo.com/sift/dashboard)apiSecret- Astringthat can be found from the [developer's dashboard](h ttps://sift.easilydo.com/sift/dashboard)
Example
ES6/7:
import { SiftAPI } from 'siftapi';
let sift = new Sift('<API_KEY>', '<API_SECRET>');ES5:
var siftapi = require('siftapi');
var sift = new siftapi.SiftAPI('<API_KEY>', '<API_SECRET>');Returns the parsed eml file in the Promise.
Parameters
username: Astringthat is the username to perform Discovery withfilename: Astringthat is the absolute path of theemlfile
Example
ES6/7:
import fs from 'fs';
let data;
fs.readFile('<filename>', (err, eml) => {
if(err) {
return console.log(err);
}
sift.discovery('<username>', eml)
.then(body => {
data = body
})
.catch(err => {
return console.log('err');
});
});ES5:
var fs = require('fs');
var data;
fs.readFile('<filename>', function(err, eml) {
if(err) {
return console.log(err);
}
sift.discovery('<username>', eml)
.then(function(body) {
data = body
})
.catch(function(err) {
return console.log(err);
});
});Adds a new user with the given username. The add connections API will automatically create an account if it doesn't exist.
Parameters
username: Astringthat is the expected username of the new userlocale: Astringthat is the locale of the new user
Examples
let newUser;
sift.addUser('test')
.then(body => {
newUser = body.result;
/*
{
"user_id": "<newly created user id>",
"username": "<given user name>"
}
*/
})
.catch(err => {
console.log(err)
});Removes a user with the given username.
Parameters
username: Astringthat is the expected username of the user to be removed
Example
sift.deleteUser('test')
.then(body => {
console.log(body.result); // "deleted"
})
.catch(err => {
console.log(err)
});Get all email connections linked to the user account.
Parameters
username: Astringthat is the expected username of the user to obtain the email connections from
Example
sift.getEmailConnections('test')
.then(body => {
if (body.message !== 'success' && body.code !== 200) {
return console.log(body.message);
}
console.log(body.result);
/*
[{
"email": "johndoe@gmail.com",
"state": "<valid or invalid>",
"id": 2,
"email_type": "google"
},
{
"email": "john.doe@icloud.com",
"state": "<valid or invalid>",
"id": 3,
"email_type": "imap"
}]
*/
})
.catch(err => {
console.log(err);
});Adds a new email connection to the user account.
Parameters
username: Astringthat is the expected username of the user to add the email connection toaccountType: Astring,google/yahoo/live/imap/exchangeemailParams: Anobjectcontaining account specific parameters, see below for which parameter to include
Account Specific Parameters
Gmail
{
"account": <Email address associated with Google>,
"refresh_token": <The refresh token for the OAuth2 connection>
}
Yahoo
{
"account": <Email address associated with Yahoo>,
"refresh_token": <The refresh token for the OAuth2 connection,>
"redirect_uri": <The redirect URI that was used for the OAuth2 connection>
}
Microsoft Live/Hotmail
{
"refresh_token": <The refresh token for the OAuth2 connection>,
"redirect_uri": <The redirect URI that was used for the OAuth2 connection>
}
IMAP
{
"account": <Email address associated with the IMAP account>,
"password": <Password for the IMAP account>,
"host": <Host for the IMAP account>
}
Exchange
{
"email": <Email address for the Exchange account>,
"password": <Password for the Exchange account>,
"host": <Host of the exchange account> (Optional),
"account": <Username for the Exchange account> (Optional)
}
Example
let params = {
account: "username@gmail.com",
refresh_token: "token"
};
let newEmailConnectionId;
sift.addEmailConnection('username', 'google' params)
.then(body => {
newEmailConnectionId = body.result.id
console.log(body);
/*
{
"message": "success",
"code": 200,
"id": "<uuid>",
"result": {
"id": "<newly created connection_id>"
}
}
*/
})
.catch(err => {
return console.log(err);
});Deletes an email connection from the given user.
Parameters
username: Astringthat is the userame of the user to remove the connection fromconnection_id: Anintegerthat is the connection to be removed
Example
sif.deleteEmailConnection('username', 'connection_id')
.then(body => {
console.log(body);
/*
{
"message": "success",
"code": 200,
"id": "<uuid>",
"result": "deleted"
}
*/
})
.catch(err => {
return console.log(err);
});Get all Sifts(tasks) from the user.
Parameters
username- Astringthat is the username of the user to get the Sifts fromparams- Anobjectthat contains additional params.limit- The maximum number of results to return. Developer can set any value between 0 to 100 and max is 100. (Defaults to 100)offset- Start the list at this offset (zero-based)last_update_time- Epoch timestamp. Returns results with last update time greater than (that is, more recent than) the specified time.domains- A list of domains separated by comma. The domain should be one of the following string: flight, hotel, rentalcar, train, boardingpass, shipment, contact, purchase, reservation, event, deal, bill. If omited, this api will return the sifts with all domains.
Example
sift.getSifts('username', {})
.then(body => {
console.log(body)
/*
{
"message": "success",
"code": 200,
"id": "<uuid>",
"result": [
{
"payload": <schema object for sift payload>,
"sift_id": <sift id>,
"mime_id": <id of raw email message>,
"fid": <id of folder in the email server>,
"mid": <id of message in the email server>,
"account_id": <id of email account>,
"user_id": <id of user>
}, ...
]
}
*/
})
.catch(err => {
console.log(err);
});Get a single Sift from the user.
Parameters
username- Astringthat is the username of the user to get the Sifts fromsiftId- Anintegerthat is the ID of the Sift to get from the userparams- Anobjectthat contains: { include_eml: 1 <- if an eml MIME file is wanted together with the payload }
Example
sift.getSift('username', '<sift_id>', { include_eml: 1 })
.then(body => {
console.log(body)
/*
{
"message": "success",
"code": 200,
"id": "<uuid>",
"result": {
"payload": <schema object for sift payload>,
"sift_id": <sift id>,
"mime_id": <id of raw email message>,
"fid": <id of folder in the email server>,
"mid": <id of message in the email server>,
"account_id": <id of email account>,
"user_id": <id of user>
}
}
*/
})
.catch(err => {
console.log(err);
});Get a new token for specific user.
Parameters
username- Astringthat is the username of the user to get the token for
Example
let connectToken;
sift.getConnectToken('username')
.then(body => {
console.log(body);
/*
{
"message": "success",
"code": 200,
"id": "<uuid>",
"result": {
"connect_token": "<newly created connect_token>"
}
}
*/
})
.catch(err => {
return console.log(err);
});Gives feedback to the EasilyDo team.
Parameters
email- Astringthat is the contents of the eml file, similar to the one sent todiscoverylocale: Astringthat is the locale of the emailtimezone: Astringthat is the timezone of the email
Example
sift.postFeedback(emlString, 'en_US', 'America/Los_Angeles')
.then(body = {
console.log(body);
/*
{
"message": "OK",
"code": 200,
"id": "<uuid>",
"result": {
"bill": {"extracted": true, "classified": true}
}
}
*/
})
.catch(err => {
return console.log(err);
});