Firing an Entry Event is great for injecting contacts into a Salesforce Marketing Cloud journey, especially if you need to be able to inject them from an external system or a website.
It’s also useful when you’re creating a custom form on a CloudPage and would like to replicate the behavior of SmartCapture forms, which allow injecting contacts to a journey upon form submission (real-time).
API Event Entry Source
When you create the journey for use with a custom form on a CloudPage, the only difference in the setup is the entry source, which in this case will be the API Event.
The API event in Journey Builder connects the journey canvas to an API used to admit contacts into a journey. When the API fires an event, the contacts entering the journey are stored in a Marketing Cloud data extension you choose. You can set a filter using Marketing Cloud data attributes to ensure that only intended customers enter the journey.
When you drag and drop the API Event into your journey’s canvas, click on it and choose to create an event. You will be prompted to choose a Data Extension for use with the journey and you will also see that an Event Definition Key has been created for your journey – copy it, as we will need it later for our script. Activate the journey.
Custom form on a CloudPage
We can now create our form on a CloudPage. For the purpose of this tutorial, it will be a very simple form collecting just the end user’s email address. We will also add some AMPscript to process the data from the form. If you haven’t created a form on a CloudPage yet, you might want to check out this article first: Create a Sales Cloud-integrated lead capture form using AMPscript. Here’s a basic form for our use case:
Fire an Entry Event using API
In order to inject a contact from our form into a journey, we will use Salesforce Marketing Cloud’s REST API, specifically the /interaction/v1/events route. Here’s an example request:
And an example response, which would indicate that the request has been processed correctly:
As a security measure, it’s best to store your Client Id and Secret as encoded values in a Data Extension to avoid exposing them in your script. My preferred way is to use the EncryptSymmetric and DecryptSymmetric AMPscript functions for encryption, and a simple lookup to get their values from a Data Extension.
Here’s how the authentication part could look like:
Once we obtain the
access_token and the
rest_instance_url, we can move on to our actual call. We will pass the
Request.GetQueryStringParameter(). Remember to include all the values passed in the payload in your target Data Extension, which you chose earlier upon creating the journey. Here we have just one such field, called
The full script
If you put all the above together, you should end up with something like this:
Leave a comment below or email me at email@example.com.
6 thoughts on “Add subscribers to a Journey from a CloudPage using Fire Entry Event”
Should integration type be server-to-server or web App in installing package
Yes, server to server is correct
if (email != null && accessToken != null)
is not working, I had to change it. can you confirm if the above condition is correct?
I left a comment already but it seems it didn’t go through, sorry if it did.
Does the data extension used for the Data Entry source need to be the same populated by the form in Cloudpages?
Great article, thank you! Given that the code runs server side, why do you feel you need to encrypt or hide the credentials? Do you mean from any marketers who might be working on the Cloudpage?
Hi, If the data is coming into the marketing cloud from an external lead generation form through Mulesoft and multiple contacts enter their information parallelly from anywhere in the world but JSON is handling the single request. If we want to handle multiple requests at the same time, Then do we need to change anything?