This package provides programmatic access to several Maropost services. It
consists of eight services within the Maropost.Api
namespace. Each service
consists of one or more functions that perform an operation against your
Maropost account. These functions return a result object indicating
success/failure, any Exceptions throw, and the resulting data.
npm is the standard node.js packaging system. You can find this package at https://www.npmjs.com/package/maropost.api. You can install it by running
npm i maropost.api
To use a service, first instantiate it, providing your Maropost AccountId and Auth Token. For example, to get your list of reports using the Reports service, execute:
var { Maropost } = require('maropost.api')
var reports = new Maropost.Api.Reports(myAccountId, myAuthToken);
var result = await reports.get();
if (result.isSuccess) {
var myReports = result.data;
}
The result object contains three fields:
isSuccess
(bool)errorMessage
(string)exception
(Exception)
If isSuccess
is false
, then errorMessage
will contain information, and
Exception
might contain an exception, depending upon the reason for
failure. If exception
is not null
, then isSuccess
will always be false
.
The object might also contains one property, data
(dynamic), which contains whatever
data the operation itself provides. Some operations, such as delete()
operations, might not provide any data.
The specific APIs contained are:
- Campaigns
- AB Test Campaigns
- Transactional Campaigns
- Contacts
- Journeys
- Product and Revenue
- Relational Table Rows
- Reports
new Maropost.Api.Campaigns(myAccountId, myAuthToken)
get(page)
- returns the list of campaigns for the account
page
: page # (>= 1). Up to 200 records returned per page.
getCampaign(campaignId)
- returns the given campaign
campaignId
getDeliveredReports(id, page)
- returns the list of delivered reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.
getOpenReports(id, page, unique = null)
- returns the list of open reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.unique
:true
= get for unique contacts. Otherwise,false
.
getClickReports(id, page, unique = null)
- returns the list of click reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.unique
:true
= get for unique contacts. Otherwise,false
.
getLinkReports(id, page, unique = null)
- returns the list of link reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.unique
:true
= get for unique contacts. Otherwise,false
.
getBounceReports(id, page)
- returns the list of bounce reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.
getSoftBounceReports(id, page)
- returns the list of soft bounce reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.
getHardBounceReports(id, page)
- returns the list of hard bounce reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.
getUnsubscribeReports(id, page)
- returns the list of soft unsubscribe reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.
getComplaintReports(id, page)
- returns the list of complaint reports for the given campaign ID
page
: page # (>= 1). Up to 200 records returned per page.
new Maropost.Api.AbTestCampaigns(myAccountId, myAuthToken)
createAbTest(name, fromEmail, replyTo, address, language, campaignGroupsAttributes, commit, sendAt, brandId, suppressedListIds, suppressedSegmentIds, suppressedJourneyIds, emailPreviewLink, decidedBy, lists, cTags, segments)
name
: name of the new campaignfromEmail
: default sender email address for campaign emailsreplyTo
: default reply-to email address for campaign emailsaddress
: default physical address included on campaign emailslanguage
: ISO 639-1 language code (e.g,"en"
). 2 characters.campaignGroupsAttributes
: array of attributes. Each attribute is itself an object with the following properties (all strings):name
: name of the groupcontent_id
: content IDsubject
: subject line of emailsfrom_name
: "from name" on emailspercentage
: percentage of emails that should be sent with these settingspreheader
:send_at
: DateTime string having the formatYYYY-MM-DD HH:mm:ss
commit
: acceptable values are:"Save as Draft"
or"Send Test"
or"Schedule"
sendAt
: DateTime string having the formatYYYY-MM-DD HH:mm:ss
brandId
:suppressedListIds
: array of list IDs in string formatsuppressedSegmentIds
: array of segment IDs in string formatsuppressedJourneyIds
: array of journey IDs in string formatemailPreviewLink
: 1 for true, or 0 for falsedecidedBy
lists
: array of targeted list IDs, formatted as strings (E.g., ["12","13"])cTags
segments
: array of targeted segment IDs, formatted as strings (E.g., ["12","13"])
new Maropost.Api.TransactionalCampaigns(myAccountId, myAuthToken)
-
get(page)
- returns the list of Transaction Campaigns
page
: page # (>= 1). Up to 200 records returned per page.
-
create(name, subject, preheader, fromName, fromEmail, replyTo, contentId, emailPreviewLink, address, language, ctags)
- Creates a Transactional Campaign
name
: campaign namesubject
: campaign subjectpreheader
: campaign preheaderfromName
: sender name in the emailfromEmail
: sender email addressreplyTo
: reply-to email addresscontentId
:emailPreviewLink
: true to send email; false to not send.address
: physical addresslanguage
: ISO 639-1 language code (e.g., "en"). 2 characters.ctags
: array of campaign tags
-
sendEmail(campaignId, contentId = null, contentName = null, contentHtmlPart = null, contentTextPart = null, sendAtHour = null, sendAtMinute = null, ignoreDnm = null, contactId = null, recipientEmail = null, recipientFirstName = null, recipientLastName = null, recipientCustomFields = null, bccEmail = null, fromName = null, fromEmail = null, subject = null, replyTo = null, senderAddress = null, tags = null, ctags = null )
- Sends a transactional campaign email to a recipient. Sender's information will be automatically fetched from the transactional campaign, unless provided in the function arguments.
campaignId
: must be a campaign that already exists when you callget(...)
. If you don't have one, first callcreate(...)
.contentId
: If provided, the transactional campaign's content will be replaced by this content.contentName
: If contentId is null, the transactional campaign's content name will be replaced by this name.contentHtmlPart
: If contentId is null, the transactional campaign's content HTML part will be replaced by this HTML part.contentTextPart
: If contentId is null, the transactional campaign's content Text part will be replaced by this Text part.sendAtHour
: Must be 1-12. Otherwise the email will go out immediately. If the hour is less than the current hour, the email will go out the following day.sendAtMinute
: Must be 0-60. Otherwise will be treated as 0. If the hour and minute combine to less than the current time, the email will go out the following day.ignoreDnm
: If true, ignores the Do Not Mail list for the recipient contact.contactId
: contact ID of the recipient.recipientEmail
: email address. Ignored unlesscontactId
is null. Otherwise, it must be a well-formed email address according toFILTER_VALIDATE_EMAIL
.recipientFirstName
: recipient's first name. Ignored unlesscontactId
is null.recipientLastName
: recipient's last name. Ignored unlesscontactId
is null.recipientCustomFields
: custom fields for the recipient. Ignored unlesscontactId
is null. Is an associative array where the item key is the name of the custom field, and the item value is the field value. All keys must be strings. All values must be non-null scalars.bccEmail
: BCC recipient. May only pass a single email address, empty string, or null. If provided, it must be a well-formed email address according tovalidateEmail
.fromName
: sender's name. IffromEmail
is set, it overrides the transactional campaign default sender name. Ignored otherwise.fromEmail
: sender's email address. Overrides the transactional campaign default sender email.subject
: subject line of email. Overrides the transactional campaign default subject.replyTo
: reply-to address. Overrides the transactional campaign default reply-to.senderAddress
: physical address of sender. Overrides the transactional campaign default sender address.tags
: associative array where the item key is the name of the tag within the content, and the item value is the tag's replacement upon sending. All keys must be strings. All values must be non-null scalars.ctags
: campaign tags. Must be a simple array of scalar values.
new Maropost.Api.Contacts(myAccountId, myAuthToken)
-
getForEmail(email)
- Gets the contact according to email address
email
: email address of the contact
-
getOpens(contactId, page)
- Gets the list of opens for the specified contact
page
: page # (>= 1). Up to 200 records returned per page.
-
getClicks(contactId, page)
- Gets the list of clicks for the specified contact
page
: page # (>= 1). Up to 200 records returned per page.
-
getForList(listId, page)
- Gets the list of contacts for the specified list
listId
page
: page # (>= 1). Up to 200 records returned per page.
-
getContactForList(listId, contactId)
- Gets the specified contact from the specified list
listId
contactId
-
updateForListAndContact( listId, contactId, email, firstName = null, lastName = null, phone = null, fax = null, uid = null, customField = [], addTags = [], removeTags = [], removeFromDNM = true, subscribe = true )
- Creates a contact within a list. Updates if previous contact is matched by email
listId
: ID of the list to which the contact being updated belongscontactId
: ID of the contact being updatedemail
: Email address for the contact to be updatedfirstName
: first name of ContactlastName
: last name of Contactphone
: phone number of Contactfax
: fax number of Contactuid
: UID for the ContactcustomField
: custom fields passed as associative array. Keys represent the field names while values represent the valuesaddTags
: tags to add to the contact. Simple array of tag namesremoveTags
: tags to remove from the contact. Simple array of tag namesremoveFromDNM
: set this true to subscribe contact to the list, and remove it from DNM)subscribe
: set this true to subscribe contact to the list; false otherwise
-
createOrUpdateForList( listId, email, firstName = null, lastName = null, phone = null, fax = null, uid = null, customField = [], addTags = [], removeTags = [], removeFromDNM = true, subscribe = true )
- Creates a contact within a list. Updates if previous contact is matched by email.
listId
: ID of the list for which the contact is being createdemail
: email address for the contact to be created|updatedfirstName
: first name of ContactlastName
: last Name of Contactphone
: phone number of Contactfax
: fax number of Contactuid
: UID for the contactcustomField
: custom fields passed as associative array. Keys represent the field names while values represent the values.addTags
: tags to add to the contact. Simple array of tag names (strings).removeTags
: tags to remove from the contact. Simple array of tag names (strings).removeFromDNM
: Set this true to subscribe contact to the list, and remove it from DNM.subscribe
: true to subscribe the contact to the list; false otherwise.
-
createOrUpdateContact( contactId, email, firstName = null, lastName = null, phone = null, fax = null, uid = null, customField = [], addTags = [], removeTags = [], removeFromDNM = true, subscribe = true )
- Creates a contact without a list. Updates if already existing email is passed.
contactId
: ID of the contactemail
: Email address for the contact to be created|updatedfirstName
: first name of ContactlastName
: last Name of Contactphone
: phone number of Contactfax
: fax number of Contactuid
: UID for the contactcustomField
: custom fields passed as associative array. Keys represent the field names while values represent the valuesaddTags
: tags to add to the contact. Simple array of tag names (strings).removeTags
: tags to remove from the contact. Simple array of tag names (strings).removeFromDNM
: set this true to subscribe contact to the list, and remove it from DNM
-
createOrUpdateForListsAndWorkflows( email, firstName = null, lastName = null, phone = null, fax = null, uid = null, customField = [], addTags = [], removeTags = [], removeFromDNM = false, subscribeListIds = [], unsubscribeListIds = [], unsubscribeWorkflowIds = [], unsubscribeCampaign = null )
- Creates or updates Contact
- Multiple lists can be subscribed, unsubscribed.
- Multiple workflows can be unsubscribed.
email
: email address for the contact to be created|updatedfirstName
: first name of ContactlastName
: last name of Contactphone
: phone number of Contactfax
: fax number of Contactuid
: UID for the ContactcustomField
: custom fields passed as associative array. Keys represent the field names while values represent the valuesaddTags
: tags to add to the contact. Simple array of tag names (strings)removeTags
: tags to remove from the contact. Simple array of tag names (strings)removeFromDNM
: set this true to subscribe contact to the list, and remove it from DNMsubscribeListIds
: simple array of IDs of lists to subscribe the contact tounsubscribeListIds
: simple array of IDs of Lists to unsubscribe the contact fromunsubscribeWorkflowIds
: simple array of list of IDs of workflows to unsubscribe the contact fromunsubscribeCampaign
: campaignID to unsubscribe the contact from
- Creates or updates Contact
-
deleteFromAllLists(email)
- Deletes specified contact from all lists
email
: email address of the contact
-
deleteFromLists(contactId, listIds = [])
- Deletes the specified contact from the specified lists
contactId
: id of the contactlistIds
: simple array of ids of the lists
-
deleteContactForUid(uid)
- Deletes contact having the specified UID
-
deleteListContact(listId, contactId)
- Deletes specified contact from the specified list
-
unsubscribeAll(contactFieldValue, contactFieldName = 'email')
- Unsubscribes contact having the specified field name/value.
contactFieldValue
: the value of the field for the contact(s) being unsubscribedcontactFieldName
: the name of the field being checked for the value. At present, the accepted field names are: 'email' or 'uid'
new Maropost.Api.Journeys(myAccountId, myAuthToken)
-
get(page)
- Gets the list of journeys
page
: page # (>= 1). Up to 200 records returned per page.
-
getCampaigns(journeyId, page)
- Gets the list of all campaigns for the specified journey
page
: page # (>= 1). Up to 200 records returned per page.
-
getContacts(journeyId, page)
- Gets the list of all contacts for the specified journey
page
: page # (>= 1). Up to 200 records returned per page.
-
stopAll(contactId, recipientEmail, uid)
- Stops all journeys, filtered for the matching parameters
contactId
: this filter ignored unless greater than 0recipientEmail
: this filter ignored if nulluid
: this filter ignored if null
-
pauseJourneyForContact(journeyId, contactId)
- Pause the specified journey for the specified contact
-
pauseJourneyForUid(journeyId, uid)
- Pause the specified journey for the contact having the specified UID
-
resetJourneyForContact(journeyId, contactId)
- Reset the specified journey for the specified active/paused contact. Resetting a contact to the beginning of the journeys will result in sending of the same journey campaigns as originally sent.
-
public function resetJourneyForUid(journeyId, uid)
- Reset the specified journey for the active/paused contact having the specified UID. Resetting a contact to the beginning of the journeys will result in sending of the same journey campaigns as originally sent.
-
public function startJourneyForContact(journeyId, contactId)
- Restarts a journey for a paused contact. Adds a new contact in journey. Retriggers the journey for a contact who has finished its journey once. (To retrigger, make sure that "Retrigger Journey" option is enabled.)
-
startJourneyForUid(journeyId, uid)
- Restarts a journey for a paused contact having the specified UID. Adds a new contact in journey. Retriggers the journey for a contact who has finished its journey once. (To retrigger, make sure that "Retrigger Journey" option is enabled.)
new Maropost.Api.ProductAndRevenue($myAccountId, $myAuthToken)
-
getOrder(id)
- Gets the specified order
-
getOrderForOriginalOrderId(originalOrderId)
- Gets the specified order
-
createOrder(requireUnique, contactEmail, contactFirstName, contactLastName, orderDateTime, orderStatus, originalOrderId, orderItems, customFields = null, addTags = null, removeTags = null, uid = null, listIds = null, grandTotal = null, campaignId = null, couponCode = null)
- Creates an order
requireUnique
: true to validate that the order has a unique original_order_id for the given contact.contactEmail
contactFirstName
contactLastName
orderDateTime
: uses the format: "YYYY-MM-DDTHH:MM:SS-05:00"orderStatus
originalOrderId
: sets the original_order_id fieldorderItems
an array of OrderItemInput objects.customFields
associative array where the key (string) represents the field name and the value is the field valueaddTags
simple array of tags to add (scalar values)removeTags
simple array of tags to remove (scalar values)uid
listIds
CSV list of IDs (e.g, "12,13")grandTotal
campaignId
couponCode
-
updateOrderForOriginalOrderId(originalOrderId, orderDateTime, orderStatus, orderItems, campaignId = null, couponCode = null)
- Updates an existing eCommerce order using unique original_order_id if the details are changed due to partial return or some other update.
originalOrderId
: matches the original_order_id field of the orderorderDateTime
: uses the format: YYYY-MM-DDTHH:MM:SS-05:00orderStatus
orderItems
: restates the orderItems as as array of OrderItemInput objects.campaignId
couponCode
-
updateOrderForOrderId(orderId, orderDateTime, orderStatus, orderItems, campaignId = null, couponCode = null)
- Updates an existing eCommerce order using unique order_id if the details are changed due to partial return or
- some other update.
orderId
: matches the Maropost order_id field of the orderorderDateTime
: uses the format: YYYY-MM-DDTHH:MM:SS-05:00orderStatus
orderItems
: restates the orderItems as as array of OrderItemInput objects.campaignId
couponCode
-
deleteForOriginalOrderId(originalOrderId)
- Deletes the complete eCommerce order if the order is cancelled or returned
originalOrderId
matches the original_order_id field of the order
-
deleteForOrderId(id)
- Deletes the complete eCommerce order if the order is cancelled or returned using Maropost order id
id
: Maropost order_id
-
deleteProductsForOriginalOrderId(originalOrderId, productIds)
- Deletes the specified product(s) from a complete eCommerce order if the product(s) is cancelled or returned
originalOrderId
: matches the original_order_id field of the orderproductIds
: the product(s) to delete from the order
-
deleteProductsForOrderId(id, productIds)
- Deletes the specified product(s) from a complete eCommerce order if the product(s) is cancelled or returned
id
: Maropost order_idproductIds
: the product(s) to delete from the order
Unlike the other services, the constructor for this requires a third
parameter: tableName
. So for example:
new Maropost.Api.RelationalTables(myAccountId, myAuthToken, tableName);
tableName
sets which relational table the service's operations should act against. To switch tables, you do not need to re-instantiate the service. Simply update the TableName
property of the instance:
var rows = new Maropost.Api.RelationalTableRows(myAccountId, myAuthToken, 'table1');
rows._setTableName('table2');
-
get()
- Gets the records of the Relational Table
-
show(id)
- Gets the specified record from the Relational Table
id
: ID of the existing record you wish to read
-
create(keyValues)
- Adds a record to the Relational Table
keyValues
: Multiple objects, for the record to be updated, each item consisting of two fields:key
: string representing the name of the fieldvalue
: scalar value representing the new value for the field.- Any DateTime strings must be in one of three formats: "MM/DD/YYYY", "YYYY-MM-DD", or "YYYY-MM-DDThh:mm:ssTZD".
- NOTE: One of the KeyValues must represent the unique identifier.
-
update(keyValues)
- Updates a record in the Relational Table.
keyValues
: Multiple objects, for the record to be updated, each item consisting of two fields:key
: string representing the name of the fieldvalue
: scalar value representing the new value for the field.- Any DateTime strings must be in one of three formats: "MM/DD/YYYY", "YYYY-MM-DD", or "YYYY-MM-DDThh:mm:ssTZD".
- NOTE: One of the KeyValues must represent the unique identifier.
-
upsert(KeyValue... $keyValues)
- Creates or updates a record in the Relational Table.
keyValues
: Multiple objects, for the record to be updated, each item consisting of two fields:key
: string representing the name of the fieldvalue
: scalar value representing the new value for the field.- Any DateTime strings must be in one of three formats: "MM/DD/YYYY", "YYYY-MM-DD", or "YYYY-MM-DDThh:mm:ssTZD".
- NOTE: One of the KeyValues must represent the unique identifier.
-
delete(idFieldName, idFieldValue)
- Deletes the given record of the Relational Table
idFieldName
name of the field representing the unique identifier (E.g., "id", "email")idFieldValue
value of the identifier field, for the record to delete.
new Maropost.Api.Reports(myAccountId, myAuthToken)
-
get(page)
- returns the list of reports
page
: page # (>= 1). Up to 200 records returned per page.
-
getReport(id)
- Gets the list of reports
id
: report ID
-
getOpens( page, fields = [], from = null, to = null, unique = null, email = null, uid = null, per = null )
- returns the list of open reports based on filters and fields provided
page
: page # (>= 1). Up to 200 records returned per page.
fields
: contact field names to retrievefrom
: the beginning of date range filterto
: the end of the date range filterunique
: when true, gets only unique opensemail
: filters by provided email in the contactuid
: filters by uidper
: determines how many records per request to receive
-
getClicks( page, fields = [], from = null, to = null, unique = null, email = null, uid = null, per = null )
- returns the list of click reports
page
: page # (>= 1). Up to 200 records returned per page.fields
: plucks these contact fields if they existfrom
: start of specific date range filterto
: end of date range filterunique
: if true, gets unique recordsemail
: gets Clicks for specific emailuid
: gets Clicks for provided uidper
: gets the specified number of records
-
getBounces( page, fields = [], from = null, to = null, unique = null, email = null, uid = null, type = null, per = null )
- returns the list of bounce reports
page
: page # (>= 1). Up to 200 records returned per page.fields
: plucks these contact fields if they existfrom
: start of specific date range filterto
: end of date range filterunique
: if true, gets unique recordsemail
: gets Bounces for specific emailuid
: gets Bounces for provided uidtype
: acceptable values are "hard" or "soft"per
: gets the specified number of records
-
getUnsubscribes( page, fields = [], from = null, to = null, unique = null, email = null, uid = null, per = null )
- returns the list of Unsubscribes with provided filter constraints
page
: page # (>= 1). Up to 200 records returned per page.fields
: plucks these contact fields if they existfrom
: start of specific date range filterto
: end of date range filterunique
if true, gets unique recordsemail
gets Unsubscribes for specific emailuid
gets Unsubscribes for provided uidper
gets the specified number of records
-
getComplaints( fields = [], from = null, to = null, unique = null, email = null, uid = null, per = null )
- returns the list of complaints filtered by provided params
page
: page # (>= 1). Up to 200 records returned per page.fields
: plucks these contact fields if they existfrom
: start of specific date range filterto
: end of date range filterunique
: if true, gets unique recordsemail
: gets Complaints for specific emailuid
: gets Complaints for provided uidper
: gets the specified number of records
-
getAbReports(name, page, from = null, to = null, per = null)
- returns the list of Ab Reports
name
: to get ab_reports with mentioned namepage
: page # (>= 1). Up to 200 records returned per page.from
: beginning of date range filterto
: end of date range filterper
: gets the mentioned number of reports
-
getJourneys(page)
- returns the list of all Journeys
page
: page # (>= 1). Up to 200 records returned per page.