The following is a description of functions to access contacts data using the REST API.
Contacts data manipulation
Common parameters
Contact data manipulation operations are very similar one another.
Request body is encoded as a structure with two main fields: "options" and "values".
you can send the contact an email if the operation succeeds. In order to do this, it is necessary to setup a transactional communication within your account. Along the same line, upon operation succeeding, it is as well possible to make the contact enter one or more automated flows by specifying the key (entry point) of an API-event-type automated flow node.
Request Body field "options"
Option | Type | Default value | Description |
---|---|---|---|
iddatabase | Integer | Database ID for the new contact | |
sendemail | Boolean | false | Request to send an email to the contact |
sendemailonactions | String (comma separated values) | insert, restore | List of action for which send the email
|
idtemplate | Integer | null | Template ID to use for the email |
enterworkflow | Boolean | false | Request the contact to enter an automated flow |
enterworkflowonactions | String (comma separated values) | insert, restore | List of actions upon which a contact is going to be triggered to enter an automated flow |
key | String | null | Id of the entry point exploited by the contact to enter the workflow. When no workflow id is provided, every workflow containing the specified entry point will be started |
idworkflow | Integer | 0 | Optional id of the workflow to be entered by the contact. When left unspecified (0), every workflow containing the provided key will be entered. Otherwise only the specified workflow (id) will be started |
wf.[VAR_NAME] | Primitive types | Optionally, it is feasible to associate enter-flow requests with session context variables: any of such variables can be specified adopting the pattern wf.[VAR_NAME] , where [VAR_NAME] is to be replaced with the actual variable name. Primitive types values can be assigned to these variables. Multiple context variables can be bound to the same request. |
|
denyupdatecontact | Boolean | false | It prevents to update a contact |
forceallowrestorecontactonupdate | Boolean | false | It allows to reactivate a suspended or unsubscribed contact even if 'denyupdatecontact' is set to 'true' |
denysubscribenewcontact | Boolean | false | It prevents to subscribe new contacts |
denysubscribeunsubscribedcontact | Boolean | false | Denies to reactivate already unsubscribed contacts |
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). |
lookuprelations | Boolean | false | If 'true' for every relation field a lookup on the table is done in order to use the logical primary key value of the table instead of the integer internal key |
addToSimpleGroup | Integer | (empty) | If not empty, the contact will be added to the given audience. The ID must be a valid ID of a static audience in the database of the contact. If the contact is already assigned to the audience no error is reported |
removeFromSimpleGroup | Integer | (empty) | If not empty, the contact will be removed from the given audience. The ID must be a valid ID of a static audience in the database of the contact. If the contact is not yet assigned to the audience no error is reported |
returnwebtrackingid | Boolean | false | Web Tracking contact session ID |
storeEvent | String | This option requests to register an event. The only valid value is 'contactUnsubscribed'. You have to supply messageRef option as well. | |
messageRef | String | Set the reference message onto which register the event requested by storeEvent option. You can get this value using [message:ref] placeholder |
Request Body field "values"
This object contains the list of fields to be associated to the new contact, use the field id as key, for instance "email", "name", etc.
For decimal numbers use a string JSON type and the separator indicated for the user who is performing the operation.
Example: "decimal_number": "1234.56"
or "decimal_number": "1234,56"
depending on the format of the real numbers indicated in the user's international settings.
Response Body fields
The response is a structure with these fields
Key | Type | Description |
---|---|---|
ok | Boolean | True if the operation succeeds |
pk | String | Primary key of the contact |
idcontact | Integer | Integer unique id of the contact |
action | String | Action which has been executed, can be one of "insert","update","delete","nothing","reactivate","restore", "subscription_confirm", "suspend" |
errors | List of errors | List of errors, for each error there is a type and a reference to the invalid field, possible errors are SYNTAX_ERROR,UNIQUE_CONSTRAINT_VIOLATION, EMPTY_REQUIRED_FIELD,GENERIC_ERROR,ACTION_NOT_ALLOWED
|
sendemail | Structure | Contains the result of the sending of the email |
sendemail.emailsent | Boolean | True if the email was sent |
sendemail.emailaddress | String | Recipient of the email |
sendemail.idsimplemessage | String | ID of the transactional message |
enterworkflow | Structure | Contains the result of automated flow entering requests |
enterworkflow.workflowentered | Boolean | True if at least one automated flow session was started as the result of contact data manipulation |
enterworkflow.idworkflowsessions | List of Integers | List of session ID corresponding to the automated flow sessions started as the result of contact data manipulation |
Subscribe contact
Using the Status
field, admitted values are subscribed, unconfirmed, unsubscribed and suspended.
POST https://apiserver/ws/rest/api/v19/contacts/subscribe
Result: a new contact is subscribed or, if already present, updated and its corresponding status set to 'subscribed', see Common parameters for parameters.
Request body example:
{ "options": { "iddatabase": 1, "sendemail": true, "idtemplate": 8 }, "values": { "email":"myemail@domain.com" } }
Response example:
{ "ok": false, "idcontact": 123, "action":"insert", "pk":"myemail@domain.com", "sendemail":{ "emailsent":true, "emailaddress":"myemail@domain.com", "idsimplemessage":1 }, "enterworkflow": null }
Further request body example:
{ "options": { "iddatabase": 1, "enterworkflow": true, "enterworkflowonactions":"insert", "key": "contactadded" }, "values": { "email":"myemail@domain.com" } }
Example of possible response to previous request:
{ "ok": true, "idcontact": 123, "action":"insert", "pk":"myemail@domain.com", "enterworkflow":{ "workflowentered":true, "idworkflowsessions": [1, 3, 5] }, "sendemail": null }
Unsubscribe contact
POST https://apiserver/ws/rest/api/v19/contacts/unsubscribe
Result: an existing contact is unsubscribed, fields other than "status" can be updated, see Common parameters for parameters.
If you are unsubcribing a contact using the primary key and no contact matches your query, then a new contact with status = 'unsubscribed' will be created. This is generally useful because you want to record that a contact does not want to receive messages from you.
Request Body example 1 (using idcontact):
{ "values": { "idcontact":65, "CAUSA_ELIMINAZIONE":1 } }
Note: the value of the ID CAUSA_ELIMINAZIONE (it is referred to the contact Unsubscription cause field) is optional, numeric, and may vary based on the field configuration defined in the account.
Request Body example 2 (using primarykey and iddatabase):
{ "options": { "iddatabase": 1 }, "values": { "email":"myemail@domain.com" } }
Request Body example 3 (using sendemail):
{ "options": { "iddatabase": 1, "sendemail": true, "sendemailonactions": "update,delete", "idtemplate": 8 }, "values": { "email":"myemail@domain.com" } }
Response example:
{ "ok": false, "idcontact": 65, "action":"insert", "pk":"myemail@domain.com", "errors": null, "sendemail": null, "enterworkflow": null }
Update single contact data using the primary key
POST https://apiserver/ws/rest/api/v19/contacts/merge
Result: an existing contact is updated, if a contact does not exist, then it is created with status='subscribed', see Common parameters for parameters.
If you are unsubcribing a contact using the primary key and no contact matches your query, then a new contact with status = 'unsubscribed' will be created. This is generally useful because you want to record that a contact does not want to receive messages from you
Request Body example 1 (using idcontact):
{ "options": { }, "values": { "idcontact":65 } }
Request Body example 2 (using primarykey and iddatabase):
{ "options": { "iddatabase": 1 }, "values": { "email":"myemail@domain.com" } }
Response example:
{ "ok": false, "idcontact": 65, "action":"insert", "pk":"myemail@domain.com", "errors": null, "sendemail": null, "enterworkflow": null }
Get single contact
GET https://apiserver/ws/rest/api/v19/contacts/contact/{idcontact}
Result: gets every field of a single contact
Query parameters:
Key | Type | Description |
---|---|---|
idcontact | Integer | The ID of the contact |
Get a Web Tracking ID for single contact
GET https://apiserver/ws/rest/api/v19/webtracking/contact/{idcontact}
Result: gets a Web Tracking ID for a single contact
Path parameters:
Key | Type | Description |
---|---|---|
idcontact | Integer | The ID of the contact |
Response example:
{ "idcontact": 1234, "idwebtracking": "xxxxxxxxx", "idaddressbook": 5555, "primaryKey": "foo@example.com" }
Update single contact by ID
POST https://apiserver/ws/rest/api/v19/contacts/contact/{idcontact}
Result: update a single contact, see Common parameters for parameters
Query parameters:
Key | Type | Description |
---|---|---|
idcontact | Integer | The ID of the contact |
Update multiple contact data with batch service
POST https://apiserver/ws/rest/api/v19/contacts/batchmerge
Result: an existing contact is updated, if a contact does not exist, then it is created with status='subscribed', see Common parameters for parameters.
even if this function allows a more efficient execution of the operation (by reusing data structures and connections on the server side), it is not recommended to request batches of more than 1000 items (please, contact the technical support for any further information or suggestion).
Parameter | Type | Description |
---|---|---|
iddatabase | String | (Mandatory) the ID of the database in which the contacts will be inserted / updated / unsubscribed |
values | List of BatchMergeValues | At least you have to define the database primary key - e.g. the "EMAIL" field |
options | List of MergeContactBodyOptions | Available options: Commons parameters |
Return values: List of MergeResult
Request Body example:
{ "iddatabase":1, "options":{ "denyupdatecontact":true }, "contacts":[ {"values":[ { "field":"email", "value":"myemail@domain.com" }, { "field":"NAME", "value":"name1" } ]}, {"values":[ { "field":"email", "value":"myemail2@domain.com" }, { "field":"NAME", "value":"name2" } ]} ] }
Response example:
[ { "ok":true, "idcontact":1, "action":"insert", "pk":"myemail1@domain.com", "errors": null, "sendemail":null, "enterworkflow":null, "idwebtracking":null }, { "ok":false, "idcontact":65, "action":"update", "pk":"myemail2@domain.com", "errors": [{ "type":"ACTION_NOT_ALLOWED", "field":null }], "sendemail":null, "enterworkflow":null, "idwebtracking":null } ]
Permissions: Manage contacts of database
Queries
Query a list of contact
GET https://apiserver/ws/rest/api/v19/contacts/query?query=QUERY
Result: returns a list of contacts
See query documentation in order to learn how to write a SELECT query of the CONTACTS table
Note: if you have to export a large volume of data, consider using the Bulk export API
Note: the query MUST be escaped as every URL parameter
Query parameters:
Key | Type | Description |
---|---|---|
query | String | The query on the CONTACTS system table |
Query examples:
query=SELECT * FROM CONTACTS WHERE email='myemail@domain.com' and iddatabase=6
Query a list of Web Tracking ID
GET https://apiserver/ws/rest/api/v19/webtracking/contacts?query={query}
Result: given a query on contacts, it returns the list of associated Web Tracking ID
See query documentation in order to learn how to write a SELECT query of the CONTACTS table
Note: the query MUST be escaped as every URL parameter
Query parameters:
Key | Type | Description |
---|---|---|
query | String | The query on the CONTACTS system table |
Query examples:
query=SELECT * FROM CONTACTS WHERE email='myemail@domain.com' and iddatabase=6