1.2.2 • Published 7 months ago

sendpost_javascript_sdk v1.2.2

Weekly downloads
-
License
Unlicense
Repository
github
Last release
7 months ago

sendpost_javascript_sdk

sendpost - JavaScript client for sendpost_javascript_sdk Email API and SMTP relay to not just send and measure email sending, but also alert and optimise. We provide you with tools, expertise and support needed to reliably deliver emails to your customers inboxes on time, every time.

Installation

For Node.js

npm

To publish the library as a npm, please follow the procedure in "Publishing npm packages".

Then install it via:

npm install sendpost_javascript_sdk --save

For browser

The library also works in the browser environment via npm and browserify. After following the above steps with Node.js and installing browserify with npm install -g browserify, perform the following (assuming main.js is your entry file):

browserify main.js > bundle.js

Then include bundle.js in the HTML pages.

Webpack Configuration

Using Webpack you may encounter the following error: "Module not found: Error: Cannot resolve module", most certainly you should disable AMD loader. Add/merge the following section to your webpack config:

module: {
  rules: [
    {
      parser: {
        amd: false
      }
    }
  ]
}

Getting Started

Please follow the installation instruction and execute the following JS code:

const { EmailApi, EmailMessage } = require('sendpost_javascript_sdk');
const email = new EmailApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key

(async function() {
  const message = new EmailMessage();
  message.from = { email: 'richard@piedpiper.com' };
  message.to = [{ email: 'gavin@hooli.com' }]
  message.subject = 'Hello'
  message.htmlBody = '<strong>it works!</strong>';
  message.ippool = 'PiedPiper'

  const opts = {
    emailMessage: message
  };
  try {
    const data = await email.sendEmail(apiKey, opts)
    console.log('API called successfully. Returned data: ', data);
  } catch (error) {
    console.error(error);
  }
})()

Example with cc, bcc and template:

const { EmailApi, EmailMessage } = require('sendpost_javascript_sdk');
const email = new EmailApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key

(async function() {
  const message = new EmailMessage();
  message.from = { email: 'richard@piedpiper.com' };

  message.to = [{
    email: 'gavin@hooli.com',
    cc: [{ email: 'dinesh@bachmanity.com' }],
    bcc: [{ email: 'jian@bachmanity.com' }],
  }]

  message.subject = 'Hello'
  message.htmlBody = '<strong>it works!</strong>';
  message.ippool = 'PiedPiper'

  message.template = 'Welcome Mail'

  const opts = {
    emailMessage: message
  };
  try {
    const data = await email.sendEmailWithTemplate(apiKey, opts)
    console.log('API called successfully. Returned data: ', data);
  } catch (error) {
    console.error(error);
  }
})()

Suppressions

Create Suppressions

const { SuppressionApi, RSuppression } = require('sendpost_javascript_sdk');
const suppressionApi = new SuppressionApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key

(async function() {
  const rSuppression = new RSuppression();
  rSuppression.hardBounce = [{ email: 'richard@piedpiper_fake.com' }];

  // fields are optional, but you have to send at least one of them.

  // rSuppression.manual = [{ email: 'richard@piedpiper_fake2.com' }];
  // rSuppression.spamComplaint = [{ email: 'richard@piedpiper_fake3.com' }];
  // rSuppression.unsubscribe = [{ email: 'richard@piedpiper_fake4.com' }];

  const opts = {
    rSuppression: rSuppression
  };
  try {
    const data = await suppressionApi.createSuppressions(apiKey, opts)
    console.log('API called successfully. Returned data: ', data);
  } catch (error) {
    console.error(error);
  }
})()

Get Suppressions

const { SuppressionApi } = require('sendpost_javascript_sdk');
const suppressionApi = new SuppressionApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key

(async function() {
  const opts = {
    offset: 0,
    limit: 10,
    from: '2023-06-07',
    to: '2023-08-02'
  };
  try {
    const data = await suppressionApi.getSuppressions(apiKey, opts)
    console.log('API called successfully. Returned data: ', data);
  } catch (error) {
    console.error(error);
  }
})()

Delete Suppressions

const { SuppressionApi, RDSuppression } = require('sendpost_javascript_sdk');
const suppressionApi = new SuppressionApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key

(async function() {
  const rDSuppression = new RDSuppression();
  rDSuppression.suppressions = [{ email: 'richard@piedpiper.com' }];
  const opts = {
    rDSuppression: rDSuppression
  };
  try {
    const data = await suppressionApi.deleteSuppression(apiKey, opts)
    console.log('API called successfully. Returned data: ', data);
  } catch (error) {
    console.error(error);
  }
})()

Count Suppressions

const { SuppressionApi } = require('sendpost_javascript_sdk');
const suppressionApi = new SuppressionApi();
const apiKey = 'your_api_key'; // {String} Sub-Account API Key

(async function() {
  const opts = {
    from: '2023-06-07',
    to: '2023-08-02'
  };
  try {
    const data = await suppressionApi.count(apiKey, opts)
    console.log('API called successfully. Returned data: ', data);
  } catch (error) {
    console.error(error);
  }
})()

Documentation for API Endpoints

All URIs are relative to https://api.sendpost.io/api/v1

ClassMethodHTTP requestDescription
sendpost.EmailApisendEmailPOST /subaccount/email/
sendpost.EmailApisendEmailWithTemplatePOST /subaccount/email/template
sendpost.SuppressionApicountGET /subaccount/suppression/count
sendpost.SuppressionApicreateSuppressionsPOST /subaccount/suppression/
sendpost.SuppressionApideleteSuppressionDELETE /subaccount/suppression/
sendpost.SuppressionApigetSuppressionsGET /subaccount/suppression/

Documentation for Models

Documentation for Authorization

Endpoints do not require authorization.

1.2.2

7 months ago

1.1.2

9 months ago

1.1.1

9 months ago

1.1.0

9 months ago

1.0.0

10 months ago