suite-js-sdk

21.1.3 • Public • Published

suite-js-sdk

Codeship Status for emartech/suite-js-sdk Dependency Status

Simple Javascript wrapper for the Emarsys API.

Important: This library does not support WSSE authentication. It is intended only to be used by Emarsys add-ons and internal services.

Installation

npm install --save suite-js-sdk

Testing

npm test

Emarsys API Hint

This wrapper tries to implement all available methods of the Emarsys API in a node fashion, exposing a Promise-only interface.

However, the Emarsys API lacks a decent amount of methods that you expect an API to provide. Thus, if methods are missing or a certain implementation style was chosen it is most likely due to the inconsistency of the API itself. Feel free to get in touch or submit a pull request if you encounter any problems.

Configuration and Setup

Debug

If you want to debug. Set your environment variables

DEBUG=suite-sdk,suiterequest

Authentication middleware

Prerequisites

The koa bodyparser module should be installed and in use before the use of the koaMiddleware.

npm install koa-bodyparser -S

In application configuration:

var bodyParser = require('koa-bodyparser');

var app = koa();
app.use(bodyParser());

Configuration

Set your environment variables

SUITE_ESCHER_SECRET=yourEscherSecret
SUITE_ESCHER_CREDENTIAL_SCOPE=yourEscherCredentialScope

Usage

var middleware = require('suite-js-sdk').authentication.koaMiddleware.getMiddleware();

If the authentication fails it throws an error with 401 code. If the authentication success it decorates the request with a validatedData property. It contains the signed parameters.

Translation middleware

Configuration

var middleware = require('suite-js-sdk').translations.koaMiddleware.decorateRenderWithTranslations();

The middleware use 'validatedData' from the request. 'validatedData' must contain an 'environment' property. If you want to load an admins language then 'validatedData' must contain a 'customer_id' and an 'admin_id' properties. If you want to load a specific language then 'validatedData' must contain a 'language' property.

Usage

Middleware decorates the render method. It will add 'translations' object as render data. It also adds a '_' method as render data. So you can use it for translations.

translations = {
    dialogs: {
        invitation: {
            confirmation: {
                message: 'test string with %s and with %s'
            }
        }
    }
}

in your jade file

p.message= _('dialogs.invitation.confirmation.message', [ 'firstParameter', 'second parameter'])

Interacting with the API

Authentication

Authenticate with the api credentials provided by your Emarsys account manager.

Set your environment variables

SUITE_API_KEY=yourApiKey
SUITE_API_SECRET=yourSecretKey

After in your Codebase

var SuiteAPI = require('suite-js-sdk').api;
var suiteAPI = SuiteAPI.create(options);

Options

  • {String} customerId: the id of the customer
  • {String} apiKey: API key
  • {String} apiSecret: API secret
  • {String} environment: API environment

SDK methods

Each of the following methods take a last options parameter as a last argument. With this options set you can override the customerId, escherOptions, etc. that you had defined when created an instance from the API client, like:

var SuiteAPI = require('suite-js-sdk').api;
var suiteAPI = SuiteAPI.create({
   customerId: 1083232
});

suiteAPI.administrator.getAdministrators({}, {
    customerId: 20234245
});

In the example above, the API will be called with customerId = 20234245.

Administrators

suiteAPI.administrator.getAdministrators(payload, options);
Get By Name

Data of an admin can be queried by providing its name.

suiteAPI.administrator.getAdministratorByName(payload, options);
suiteAPI.administrator.patchAdministrator(payload, options);
suiteAPI.administrator.createAdministrator(payload, options);
suiteAPI.administrator.deleteAdministrator(payload, options);
Disable

Changes the status of the admin to disabled so logging in will not be possible.

suiteAPI.administrator.disableAdministrator(payload, options);
Enable

Changes the status of the disabled admin back to enabled so logging in becomes possible.

suiteAPI.administrator.enableAdministrator(payload, options);
suiteAPI.administrator.getInterfaceLanguages(payload, options);

Returns the start pages of an administrator.

suiteAPI.administrator.getStartPages(payload, options);
suiteAPI.administrator.getAccessLevels(payload, options);
Promote to Superadmin

Levels up an admin to a superadmin.

suiteAPI.administrator.promoteToSuperadmin(payload, options);
Create Superadmin

Creates a superadmin.

suiteAPI.administrator.createSuperadmin(payload, options);
Invite Existing Administrator

Sets the status of the admin to disabled and invites the admin again. The admin can log in only after completing the necessary data on the invitation form.

suiteAPI.administrator.inviteExistingAdministrator(payload, options);

AutomationCenter

suiteAPI.automationCenter.programResource(payload, options);
suiteAPI.automationCenter.programsEntrypoints(payload, options);

Campaign

create
suiteAPI.campaign.create(payload, options);
update
suiteAPI.campaign.update(payload, options);

Condition

List
suiteAPI.condition.list(payload, options);
List with contact fields
suiteAPI.condition.listWithContactFields(payload, options);

Contact

suiteAPI.contact.getData(payload, options);

To return the contacts with string field ids, specify { stringIds: true } in the options.

suiteAPI.contact.getData(payload, { stringIds: true });
suiteAPI.contact.create(payload, options);
Merge
suiteAPI.contact.merge(payload, options);
suiteAPI.contact.update(payload, options);
suiteAPI.contact.createOrUpdate(payload, options);
suiteAPI.contact.delete(payload, options);
suiteAPI.contact.checkIds(payload, options);
suiteAPI.contact.lastChange(payload, options);

Contact List

suiteAPI.contactList.create(payload, options);
suiteAPI.contactList.list(payload, options);
suiteAPI.contactList.fetch(payload, options);
suiteAPI.contactList.add(payload, options);
suiteAPI.contactList.listContactLists(payload, options);
suiteAPI.contactList.count(payload, options);
suiteAPI.contactList.getContactsData(payload, options);
suiteAPI.contactList.deleteList(payload, options);

ExternalEvent

suiteAPI.externalEvent.create(payload, options);
suiteAPI.externalEvent.list(payload, options);
suiteAPI.externalEvent.get(payload, options);
suiteAPI.externalEvent.update(payload, options);
suiteAPI.externalEvent.delete(payload, options);
suiteAPI.externalEvent.trigger(payload, options);

Language

Translate

Lists available languages for a customer in the customer's own language.

suiteAPI.language.translate(payload, options);

Settings

suiteAPI.settings.getSettings(payload, options);
Get Corporate Domains

Lists the permitted corporate domains of the customer. If corporate domains are set, registration is possible only with those email addresses which meet these requirements.

suiteAPI.settings.getCorporateDomains(payload, options);
Set Corporate Domains

Accepted corporate domains can be defined.

suiteAPI.settings.setCorporateDomains(payload, options);
Get IP Restrictions

Lists the permitted IP address rules (e.g. 192.168.* allows IP addresses which start with these two numbers and can end in any numbers).

suiteAPI.settings.getIpRestrictions(payload, options);
Set IP Restrictions

Possible IP address rules can be defined.

suiteAPI.settings.setIpRestrictions(payload, options);
Get available languages
suiteAPI.settings.getLanguages(payload, options);
Get security settings

Get security settings (IP whitelisting enabled option)

suiteAPI.settings.getSecuritySettings(payload, options);
Set security settings

Set security settings (IP whitelisting enabled option)

suiteAPI.settings.setSecuritySettings(payload, options);
Get sender domains
suiteAPI.settings.getDeliverabilitySenderDomains(payload, options);
Set sender domain
suiteAPI.settings.setDeliverabilitySenderDomain(payload, options);

Email

suiteAPI.email.create(payload, options);
suiteAPI.email.copy(payload, options);
suiteAPI.email.updateSource(payload, options);
suiteAPI.email.launch(payload, options);
suiteAPI.email.launchList(payload, options);
suiteAPI.email.list(payload, options);
suiteAPI.email.get(payload, options);
suiteAPI.email.patch(payload, options);
suiteAPI.email.sendTestMail(payload, options);

The payload must contain an email_id, which is the broadcast campaign id

suiteAPI.email.broadcast(payload, options);
suiteAPI.email.getDeliveryStatus(payload, options);
suiteAPI.email.responses(payload, options);

Returns the summary of the responses of a launched, paused, activated or deactivated email campaign.

suiteAPI.email.getResponseSummary(payload, options);
Querying Email Personalizations

Lists all possible alternate texts with their email campaigns. Alternate texts are defined for a specific field, and displayed in the email campaign if this field has no value.

suiteAPI.email.getPersonalizations(payload, options);
Updating Email Personalizations

Updates alternate texts.

suiteAPI.email.setPersonalizations(payload, options);
suiteAPI.email.createTrackedLink(payload, options);
suiteAPI.email.getTrackedLinks(payload, options);
suiteAPI.email.updateTrackedLink(payload, options);
suiteAPI.email.deleteTrackedLinks(payload, options);
suiteAPI.email.getContacts(payload, options);
suiteAPI.email.deleteTrackedLinksBySource(payload, options);
suiteAPI.email.listPrograms(payload, options);

Segment

suiteAPI.segment.listContacts(payload, options);
suiteAPI.segment.countContacts(payload, options);
suiteAPI.segment.listSegments(payload, options);
suiteAPI.segment.getSegment(payload, options);
suiteAPI.segment.create(payload, options);
suiteAPI.segment.getContactCriteria(payload, options);
suiteAPI.segment.updateContactCriteria(payload, options);
suiteAPI.segment.runForSingleContact(payload, options);
suiteAPI.segment.singleContactRunStatus(payload, options);
suiteAPI.segment.runForMultipleContacts(payload, options);
suiteAPI.segment.multipleContactsRunStatus(payload, options);

Combined Segment

suiteAPI.combinedSegment.list(payload, options);
suiteAPI.combinedSegment.create(payload, options);
suiteAPI.combinedSegment.get(payload, options);
suiteAPI.combinedSegment.update(payload, options);

Purchases

List

Lists the purchases of customer for a date range.

suiteAPI.purchase.list(payload, options);
Stats

Statistics about the purchases of customer.

suiteAPI.purchase.stats(payload, options);

Contact Fields

suiteAPI.field.create(payload, options);
suiteAPI.field.get(payload, options);
suiteAPI.field.getChoices(payload, options);
suiteAPI.field.getMultipleChoices(payload, options);
suiteAPI.field.delete(payload, options);

Export

suiteAPI.export.getData(payload, options);
suiteAPI.export.getChanges(payload, options);

Keyring

Manage customer PKI options

list
suiteAPI.keyring.list(payload, options);
get
suiteAPI.keyring.get(payload, options);
create
suiteAPI.keyring.create(payload, options);
delete
suiteAPI.keyring.delete(payload, options);

Contact Sources

suiteAPI.source.create(payload, options);

suiteAPI.source.listSources(payload, options);

Readme

Keywords

none

Package Sidebar

Install

npm i suite-js-sdk

Weekly Downloads

378

Version

21.1.3

License

MIT

Unpacked Size

233 kB

Total Files

88

Last publish

Collaborators

  • blacksonic
  • gergelyke
  • sviktor
  • draven
  • adambrunner
  • joco
  • gszabo
  • emarsys-deployer