elastic-email-api

1.5.0 • Public • Published

elastic-email-api

Elastic Email API wrapper

Latest Stable Version License NPM Downloads

Getting started:

npm install elastic-email-api
 
//or
 
npm install --save elastic-email-api
var elastic = require('elastic-email-api');

How to use:

elastic.request({
    //Options object
    path: '/account/load',
    params: { apikey: 'Your Api Key' },
    callback:  function (responseObj) {
    console.log(responseObj)
    }               
}, file);
 
//elastic.request(optionObject);

Options object:

{
 path: '/category/actiontodo', // typeof "string", REQUIRED!
 params: {param1: value, param2: value }, //typeof "object", [optional] but most of Elastic Email API requests needs it!
 callback: function (ResponseObject) {}, //typeof "function", [optional],
 hideApiKey: true // typeof "boolean", default: "false", more info below...
}

Response Object available in callback

{
error: //null or error message from request module.
response: //object with response from elastic email
path: //full path for API connection
}

Set API Key

elastic.setApiKey(YourApiKeyString);

If you set API key, you don't need it anymore in "parameters object". f.e.

elastic.request({
    path: '/account/load',
    callback: function (responseObj) {
        console.log(responseObj)
    }
});

hideApiKey property in request input

NOTE: You should not sent your api key with "contact/add". If you are using 'setApiKey' & 'request' methods, set the hideApiKey property as true...

elastic.request({
    path: '/contact/add',
    params: {
        email: 'johndoe@email.com',
        publicAccountID: 'your public account ID'
    },
    hideApiKey: true
});

But you can still specify a different API Key.

elastic.request({
    path: '/account/load',
    params: {apikey: 'Your SubAccount Api Key String'},
    callback: function (responseObj) {
        console.log(responseObj)
    }
});
//Returns detailed information about your subaccount.

Attachment Upload >= 1.3.0

const fs = require('fs');
 
var formData = {
  my_file: fs.createReadStream(__dirname + '/images.jpg')
};
 
 
elastic.request({
    path: "attachment/upload",
    apikey: 'Your APIkey',
    callback: function (responseObj) {
      console.log(responseObj)
    }
}, formData);

NOTE: From version 1.5.0 I only support request method, all wrapper methods are deprecated

Package Sidebar

Install

npm i elastic-email-api

Weekly Downloads

4

Version

1.5.0

License

MIT

Last publish

Collaborators

  • glokam