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.
npm install --save suite-js-sdk
npm test
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.
If you want to debug. Set your environment variables
DEBUG=suite-sdk,suiterequest
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());
Set your environment variables
SUITE_ESCHER_SECRET=yourEscherSecret
SUITE_ESCHER_CREDENTIAL_SCOPE=yourEscherCredentialScope
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.
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.
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'])
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);
-
{String} customerId
: the id of the customer -
{String} apiKey
: API key -
{String} apiSecret
: API secret -
{String} environment
: API environment
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
.
suiteAPI.administrator.getAdministrators(payload, options);
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);
Changes the status of the admin to disabled so logging in will not be possible.
suiteAPI.administrator.disableAdministrator(payload, options);
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);
Levels up an admin to a superadmin.
suiteAPI.administrator.promoteToSuperadmin(payload, options);
Creates a superadmin.
suiteAPI.administrator.createSuperadmin(payload, options);
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);
suiteAPI.automationCenter.programResource(payload, options);
suiteAPI.automationCenter.programsEntrypoints(payload, options);
suiteAPI.campaign.create(payload, options);
suiteAPI.campaign.update(payload, options);
suiteAPI.condition.list(payload, options);
suiteAPI.condition.listWithContactFields(payload, options);
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);
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);
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);
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);
Lists available languages for a customer in the customer's own language.
suiteAPI.language.translate(payload, options);
suiteAPI.settings.getSettings(payload, options);
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);
Accepted corporate domains can be defined.
suiteAPI.settings.setCorporateDomains(payload, options);
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);
Possible IP address rules can be defined.
suiteAPI.settings.setIpRestrictions(payload, options);
suiteAPI.settings.getLanguages(payload, options);
Get security settings (IP whitelisting enabled option)
suiteAPI.settings.getSecuritySettings(payload, options);
Set security settings (IP whitelisting enabled option)
suiteAPI.settings.setSecuritySettings(payload, options);
suiteAPI.settings.getDeliverabilitySenderDomains(payload, options);
suiteAPI.settings.setDeliverabilitySenderDomain(payload, options);
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);
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);
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);
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);
suiteAPI.combinedSegment.list(payload, options);
suiteAPI.combinedSegment.create(payload, options);
suiteAPI.combinedSegment.get(payload, options);
suiteAPI.combinedSegment.update(payload, options);
Lists the purchases of customer for a date range.
suiteAPI.purchase.list(payload, options);
Statistics about the purchases of customer.
suiteAPI.purchase.stats(payload, options);
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);
suiteAPI.export.getData(payload, options);
suiteAPI.export.getChanges(payload, options);
Manage customer PKI options
suiteAPI.keyring.list(payload, options);
suiteAPI.keyring.get(payload, options);
suiteAPI.keyring.create(payload, options);
suiteAPI.keyring.delete(payload, options);
suiteAPI.source.create(payload, options);
suiteAPI.source.listSources(payload, options);