The following is a description of functions to access transactional message data using the REST API.
Transactional messages status
Get single message status
GET https://apiserver/ws/rest/api/v19/simplemessages/message/{idmessage}
Result: gets every field of a single message
Query parameters:
Key | Type | Description |
---|---|---|
idmessage | Integer | the id of the transactional message |
address | String | email/sms recipient |
actualStatus | String | status of the transactional message. It may be: 'internalError', 'hardBounce', 'waiting', 'sent', 'notSent', 'softBounce' |
sentDate | Date | delivery date |
opened | Boolean | true, if message is opened |
lastOpenedTs | Date | date of the last opened message |
clicked | Boolean | true, if message is clicked |
lastClickedTs | Date | date of the last clicked message |
idbouncecategory | Integer | the id of the bounce category |
complainted | Boolean | true, if message is complainted |
notSentCause | String | detailed cause in the case of actualStatus='notSent' , possible values are:'unknown', 'blacklisted_recipient', 'cancelled', 'unsubscribed', 'forbidden_from', 'forbidden_replyto', 'maxsize_exceeded', 'phonerecipient_notallowed', 'empty_recipient', 'forbidden_smsfrom', 'forbidden_smsnumericfrom', 'no_credit' |
Send messages
Common parameters
All the send message call types have in common the structure of the Response (identical to Get single message status) and the structure of the Request which is composed of 2 fields: "options" and "values"
Request Body field "options":
Option | Type | Default Value | Description |
---|---|---|---|
idcontact | Integer | null | Looks up for contact's profile data using the internal id of the contact |
iddatabase | Integer | null | If the contact is not recognized this values is used to render the email as it was sent to a contact of a database |
contactprimarykey | String | null | Looks up for contact's profile data searching for a contact with the given primary key, in the given database (see iddatabase option) |
contactprimarykeyoptional | Boolean | false | If the contact isn't found, use the to field in the message values as recipient address instead of failing the delivery. Note: when no contact is found, no statistics are recorded, since the message is sent but there's no contact on any database to associate the message against. |
usecontactemail | Boolean | false | Uses the email of the given contact as the recipient address of the message (overriding message.to). |
cssinline | Boolean | false | Apply css inline to the html content of the message. |
embbeddedimages | Boolean | false | Download and embed all the images founded in the html content of the message (attaching them at the message). |
idwebsite | Integer | id of the default website | Specifies the website to use when rendering absolute URLs (for example image URLs or [link:ununsubscribe] URLs...). |
usenewsletterastemplate | Boolean | false | Indicates to use a communication template (or notification message template, which is a special type of communication) as the message body. |
renderatsend | Boolean | false | Indicates to render the message during the delivery and not while serving the API call. This option must be used in conjunction with usenewsletterastemplate. This option will result in faster API calls and in less resources usage. This is the preferred way of sending messages using usenewsletterastemplate option. With 'renderAtSend' option, message body will never be persisted on db, even if 'messageRetention' level is set to 'full'. Note: the subject value does not work as it is used the template subject. |
usehtmlcodeastemplate | Boolean | false | Indicates to use html code as the message body. In this case for example you can use mn:if conditions |
idnewsletter | Integer | null | The communication whose template is used to draw the message (usenewsletterastemplate must be set to true). |
newsletterkey | String | null | The key for sending by API of the communication whose template is used to draw the message (usenewsletterastemplate must be set to true). Note: if idnewsletter and newsletterkey are both valued, idnewsletter will be used. |
format | String | 'html' | The format of the email ('html','text','multipart') |
validatesmslength | Boolean | true | If true the number of sms parts will be validated according to the maxsmsparts option together with the account settings. |
maxsmsparts | Integer | system maximum number of sms parts | Specifies the maximum number of parts of sms message. Messages splitted in a number of parts exceeding this limit will not be sent. |
expectedDeliveryTs | Timestamp | empty | Requests to send the message at a given time. If empty it means 'as soon as possible' |
temp.xxx | String | empty | Declares the initial value of the temp.xxx variable (in Giotto language you can use this variable using [temp:xxx] syntax) |
messageRetention | String | "minimal" | Specify a retention policy for the welcome message between "minimal" (discard the message body), "full" (keep the whole message and headers) and "reserved" (discard the recipient). |
externalId | String | "null" | Assign an external Id to the messages. |
inputparam.xxx | String | empty | Declares the value of the inputparam.xxx variable (in Giotto language you can use this variable using [inputparam:xxx] syntax) |
nospool | Boolean | false | Indicates to attempt to avoid message spooling and send messages directly. This option can be helpful to send a message in a timely manner. |
idlanguage | String | null | The ID of the language to use. Valid values: "ITA", "ENG", "FRA", "null". |
usecontactcell | Boolean | false | Override 'message.to' parameter and use the phone number of the given contact as the recipient address of the message. |
Request Body field "values":
Name | Type | Default Value | Description |
---|---|---|---|
type | String | null | The type of message ('email','sms') |
to | String | null | Email address or cell to use as recipient of the message |
fromemail | String (email address) | null | Email address to use as From header of the message. For email messages only |
fromname | String | null | From name header of the message. For email messages only |
replyto | String | null | Email address to use as ReplyTo header of the message. For email messages only |
subject | String | null | Subject of the message. For email messages only |
charset | String | null | Charset of the message. For email messages only |
htmlbody | String | null | Content of the HTML version of the message. For email messages only |
textbody | String | null | Content of the TEXT version of the message. For email messages only |
from | String | null | Cell number or name of the sender. For sms messages only |
smsbody | String | null | Cell number or name of the sender. For sms messages only |
idmessagetype | Integer | Id of the transactional message type used for statistics aggregation | |
attachments | Array of Attachment | null | A collection of attachments |
header.xxxx | String | Add this kind of lines in order to add custom headers. For instance header.Message-ID=MyMessageId@myserver will add a Message-ID:MyMessageId@myserver header to the outgoing email. For email messages only
|
Attachment data structure
Name | Type | Default Value | Description |
---|---|---|---|
filename | String | null | The name of the attachment |
contenttype | String | null | Content type of the attachment. If omitted the system will try to infer it from the extension in filename, if present |
body | String | null | File content as base64 string |
Send an email message with contact data
POST https://apiserver/ws/rest/api/v19/simplemessages/message
Submit a transactional email message with an attachment to the contact that will sent as soon as possible.
Request: Refer to Common parameters section for the full list of options and values
Result: is a structure identical to the Get single message status call.
Request Body example:
{ "options": { "usecontactemail": "true", "idcontact": 8 }, "values": { "type": "email", "fromemail": "email@test.informatica.it", "fromname": "Test", "subject": "Subject for you [contact:email]", "htmlbody": "<b>Hello [contact:name]</b>", "attachments": [{ "filename": "hello.txt", "contenttype": "text/plain", "body": "aGVsbG8gd29ybGQ=" }] } } }
Send an email message using a communication as template
POST https://apiserver/ws/rest/api/v19/simplemessages/message
Submit a transactional email message using a notification template (that is a communication).
Request: Refer to Common parameters section for the full list of options and values
Result: is a structure identical to the Get single message status call.
Request Body example:
{ "options": { "usenewsletterastemplate": "true", "idnewsletter": 5, "renderatsend": "true" }, "values": { "type": "email", "fromemail": "email@test.informatica.it", "fromname": "Test", "replyto": "email@test.informatica.it", "to": "recipient@domain.it" } }
Note: if you specify the subject (value subject), you need to remove the option renderatsend (and viceversa).
Send an SMS message
POST https://apiserver/ws/rest/api/v19/simplemessages/message
Submit a transactional SMS message.
Request: Refer to Common parameters section for the full list of options and values
Result: is a structure identical to the Get single message status call.
Request Body example:
{ "options": { "usenewsletterastemplate": "true", "idnewsletter": 5 }, "values": { "type": "sms", "from": "smssender", "smsbody": "helloooo", "to": "+390000000" } }
Send a list of messages
POST https://apiserver/ws/rest/api/v19/simplemessages/messages
Submit a list of messages (email or SMS) in batch mode.
Request: Refer to Common parameters section for the full list of options and values.
Result: is a list of delivery result MNSimpleMessageSendResult, one per message.
MNSimpleMessageSendResult structure:
Name | Type | Description |
---|---|---|
error | String | Valued if the message has not been sent |
result | String | Valued if the message has been sent. Structure identical to the Get single message status call. |
Request Body example (send two messages with contact data, one via email and another via sms):
{ "messages":[ { "options":{ "usecontactemail":"true", "idcontact":8 }, "values":{ "type":"email", "fromemail":"email@test.informatica.it", "fromname":"Test", "subject":"Subject for you [contact:name]", "htmlbody":"Hello [contact:name]", "attachments":[ { "filename":"hello.txt", "contenttype":"text/plain", "body":"aGVsbG8gd29ybGQ=" } ] } }, { "options":{ }, "values":{ "type":"sms", "from":"sender", "smsbody":"Hello!", "to":"+390000000000" } } ] }
Send MIME messages
POST https://apiserver/ws/rest/api/v19/simplemessages/mimemessage
If a message has been successfully sent, gets the ID of the message, otherwise it returns an error.
To use this function is required to:
- Define the mandatory parameter
recipient
; - Pass the header:
Content-Type: message/rfc822
.
Query parameters
Key | Type | Description |
---|---|---|
recipient | String | Recipient email address (mandatory) |
idcontact | Integer | idcontact which will be linked to the message, can be null |
expectedDeliveryTs | Timestamp | Unix timestamp in millisecond (default null): specify a date to schedule delivery in the future |
destination | String | Specify if the message will be sent to platform user (backend) or to a contact (frontend) or via Simply-SMTP service (bulk). Default is frontend |
idmessagetype | Integer | Message type of the message |
cssinline | Boolean | Specify the use of css inline |
retention | String | Specify a retention policy for the given message between minimal (discard the message body), full (keep the whole message and headers on database) and reserved (discard the recipient) |
externalId | String | Id (max 1000 chars) to be associated to the message, this will be useful to map the message with some other Id |
Result: this function returns a JSON-formatted response
Value | Description |
---|---|
ok | True or false |
error | The error description |
messageId | the id of the transactional message |
Send an email message with contact data
POST https://mysite.com/ws/rest/api/v19/simplemessages/mimemessage?recipient=test@test.it&idcontact=5 Content-Type: message/rfc822
Submit a transactional email message to the contact that will sent as soon as possible
Request body example:
From: Test <example@example.com> To:test@test.com subject:My Subject MIME-Version: 1.0 Content-Type: multipart/mixed; boundary="XXXXboundary text" This is a multipart message in MIME format. --XXXXboundary text Content-Type: text/plain this is the body text --XXXXboundary text Content-Type: text/plain; Content-Disposition: attachment; filename="test.txt" this is the attachment text --XXXXboundary text--