1.0.1 • Published 7 years ago
elastic-email-promise v1.0.1
This LITE Wrapper, allows you to quickly and easily use the Elastic Email API v2 via Node.js and with ES 2015 Promises.
Quick Examples:
Install:
npm i elastic-email-promise
Set up your client:
const ee = require( 'elastic-email-promise' );
const eeClient = ee.Client( { apikey: 'Your Apikey' } );
request method with only api key required:
eeClient.request( '/account/load' )
.then( function( data ) { console.log( data ) } )
.catch( function( error ) { console.log( error ) } );
request method with more parameters:
eeClient.request( '/contact/findcontact', { email: 'example@example.com' } )
.then( function( data ) { console.log( data ) } )
.catch( function( error ) { console.log( error.message ) } )
request method with file upload:
const fs = require('fs');
eeClient.request( '/contact/upload', {
contactFile: fs.createReadStream('CSV_Sample1.csv')
})
.then( function( data ) { console.log( data ) } )
.catch( function( error ) { console.log( error.message ) } )
Request method:
eepromise.request( 'path', { params } );
path : string; path for method (f.e. "/channel/list") params: object; parameters for method return => Promise Object with respond
More information about EE Api methods you can find in EE API Documentation
How does elastic-email-promise pass Elastic Email response?
Elastic Email API (version 2) response dosen't have correct HTTP status code. All responses are JSON string:
//On success
{success: true, data: /* response data it could be array or object */}
//On false
{success: false, error: 'error message as string'}
- Elastic Email Promise will try parse response to JSON.
- If something goes wrong, the exception be thrown to Promise reject
- Then JSON success parameter will be check.
- If true: resolve( data );
- If false: reject( new Error( error ) );