Simple Javascript wrapper for the Emarsys API.
npm install --save suite-js-sdk
npm test
This wrapper tries to implement all available methods of the Emarsys API in a node fashion. 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 choosen 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
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 contains an 'environment' property. If you want to load an admins language then 'validatedData' must contains a 'customer_id' and an 'admin_id' properties. If you want to load a specific language then 'validatedData' must contains 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 transations.
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();
With cache
var SuiteAPI = require('suite-js-sdk').api;
var suiteAPI = SuiteAPI.createWithCache(cacheId);
CacheId can be anything. If you want to cache / request you can use 'koa-request-id'
Each SDK methods accepts an additional options object as the last argument.
{
rawResponse: true
}
Supported option properties:
rawResponse
: the SDK method returns not just the data from the response, but all the status codes as well
suiteAPI.administrator.getAdministrators(customerId, options);
suiteAPI.administrator.getAdministrator(customerId, adminId, options);
suiteAPI.administrator.getAdministratorByName(customerId, adminName, options);
suiteAPI.administrator.patchAdministrator(customerId, adminId, payload, options);
suiteAPI.administrator.createAdministrator(customerId, payload, options);
suiteAPI.administrator.deleteAdministrator(customerId, adminId, successorId, options);
suiteAPI.administrator.disableAdministrator(customerId, adminId, options);
suiteAPI.administrator.enableAdministrator(customerId, adminId, additionalDataToModify, options);
suiteAPI.administrator.getInterfaceLanguages(customerId, options);
suiteAPI.administrator.getAccessLevels(customerId, options);
suiteAPI.administrator.promoteToSuperadmin(customerId, adminId, additionalDataToModify, options);
suiteAPI.administrator.createAdministrator(customerId, additionalDataToModify, options);
suiteAPI.administrator.createSuperadmin(customerId, additionalDataToModify, options);
suiteAPI.administrator.inviteExistingAdministrator(customerId, adminId, additionalDataToModify, options);
suiteAPI.contact.create(customerId, payload, options);
suiteAPI.contactList.create(customerId, name, contactIds, options);
suiteAPI.contactList.list(customerId, contactListId, offset, limit, options);
suiteAPI.externalEvent.trigger(customerId, eventId, payload, options);
suiteAPI.language.translate(customerId, languageId, options);
suiteAPI.settings.getSettings(customerId, options);
suiteAPI.settings.getCorporateDomains(customerId, options);
suiteAPI.settings.setCorporateDomains(customerId, corporateDomainsArray, options);
suiteAPI.email.copy(customerId, emailId, payload, options);
suiteAPI.email.updateSource(customerId, emailId, payload, options);
suiteAPI.email.launch(customerId, emailId, schedule, timezone, options);
suiteAPI.email.list(customerId, options);
suiteAPI.segment.listContacts(customerId, segmentId, offset, limit, options);
suiteAPI.segment.listSegments(customerId, options);
suiteAPI.purchase.list(customerId, startDate, endDate, offset, limit, options);
suiteAPI.programResource.list(customerId, serviceId);