I am trying to set up a Destination Function that sends events to Salesforce Marketing Cloud (SFMC) Transactional API endpoint. My goal is to trigger an email send whenever a specific event (e.g., "Order Confirmation") occurs in Segment Source. Can someone share example of js code which i can take as an example. I am not very good in creating a js code from scratch. Thanks.
Hey Rahul,
The default functions setup includes a template that can cover the barebones of what you are looking for.
Salesforce Documentation has some detail on the exact post request that you would be looking to make, including formatting:
Host: https://YOUR_SUBDOMAIN.rest.marketingcloudapis.com
POST /messaging/v1/email/messages/MESSAGE_KEY
Content-Type: application/json
Authorization: Bearer YOUR_ACCESS_TOKEN
{
"definitionKey": "2FA_order_accounts",
"recipient":
{
"contactKey": "recipient2",
"to": "recipient2@example.com",
"attributes": {
"UserAttribute_1": "value_1",
"UserAttribute_n": "value_n"
}
}
}
If you are completely new to building functions, I’d recommend giving our Copilot a try - just click the “get help from copilot” button in the function builder and ask it to implement the post request formatting into the function when you receive an “order confirmation” event.
After the function is set up, it looks like everything regarding your email template would be set up in Salesforce directly.
Let me know how this goes, and if we can help with any followup after Copilot has given it a try.
Cheers,
Tyler
Reply
Enter your E-mail address. We'll send you an e-mail with instructions to reset your password.