To integrate a subscription form, use the API resource Subscribe contact.
Request Body
The standard request body looks as follows:
{
"contact" : {
"channels" : [ {
"type" : "email",
"value" : "test@mail.com"
} ]
}
}
After a resource call, one contact with the email address test@mail.com
will be added to the system.
To configure the contact name, add the firstName value to the contact field:
{
"contact" : {
"firstName" : "...",
"channels" : [ {
"type" : "email",
"value" : "test@mail.com"
} ]
}
}
To specify the segments where the subscribed contact will be added, add to the request the groups field - the string array, segment names. If the specified segments don’t exist in the system, they will be created automatically:
{
"contact" : {
"firstName" : "...",
"channels" : [ {
"type" : "email",
"value" : "test@mail.com"
} ]
},
"groups" : [ "Subscribers" ]
}
Generating Events
Once this resource is called, the system automatically generates one of two events:
-
subscribeFromAPI if a new contact has been created;
-
subscribeUpdateFromAPI — if such a contact exists.
You can see these events in Automation → Event history.
![Event history Event history](https://files.readme.io/447bc99eefa5e106b0887967c6a1f0b79ca05abe9c449e7cdf10ee9f59e10a63-integrating-subscription-form-via-api-001.webp)
Adding Workflow
Any event can be added to a workflow. When an event that is incorporated in a workflow is triggered, the workflow launch begins. For new contacts, it is advisable to send a subscription confirmation.
To make sure a new contact is created, go to Contacts → All Contacts, and enter the necessary email address into the search.
![All contacts All contacts](https://files.readme.io/272ab1d9c6e85e2ace7e3329e87da1655a2c492f85bb6c0543a4d6b1564661c3-integrating-subscription-form-via-api-002.webp)
The contact will be found. This means the contact’s email address is inactive and requires confirmation.
![Inactive contact is highlighted in gray Inactive contact is highlighted in gray](https://files.readme.io/31dd47e88ea3c212baa27de9b8f22ad153cbe86a5a992920c786045f87e3bdb8-integrating-subscription-form-via-api-003.webp)
You can't send any campaigns to such addresses besides a subscription confirmation email and other transactional emails, for example, an abandoned cart or order confirmation.