How to send brevo.com emails from CommonRoom.io workflows using orkes.io / netflix conductor

Albert Wong
4 min readJul 9, 2023

Setup on the Brevo.com side.

  1. Setup an API key

Setup on the Orkes.io

  1. Create a new Workflow. Click on Workflow -> Definitions. I named my workflow “Common_Room_to_Email”. I also put in an output to let me know what email address was processed.

2. Create one task that is an HTTP task. The goal of the task was to take the JSON input, extract the values I wanted, and then send an email using the Brevo email REST endpoint. Used the example email template at https://developers.brevo.com/docs/send-a-transactional-email

{  
"sender":{
"name":"Sender Alex",
"email":"senderalex@example.com"
},
"to":[
{
"email":"${workflow.input.payload.primaryEmail}",
"name":"${workflow.input.payload.fullName}"
}
],
"subject":"Hello world",
"htmlContent":"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Brevo.</p></body></html>"
}

3. Create a secret for the Brevo API that I created earlier.

4. Create an application.

5. Assign the workflow and secret to the application with the correct permissions.

6. Test it out by running the workflow. I used the sample JSON data provided at https://docs.commonroom.io/using-common-room/webhooks

Here’s the orkes / netflix conductor source:

{
"createTime": 1688937729976,
"updateTime": 1689017770983,
"name": "Common_Room_to_Email",
"description": "Commonroom.io to Brevo Email API",
"version": 1,
"tasks": [
{
"name": "post_brevo_email_api",
"taskReferenceName": "post_brevo_email_api_ref",
"inputParameters": {
"http_request": {
"uri": "https://api.brevo.com/v3/smtp/email",
"method": "POST",
"connectionTimeOut": 3000,
"readTimeOut": 3000,
"accept": "application/json",
"contentType": "application/json",
"headers": {
"api-key": "${workflow.secrets.brevoapikey}"
},
"body": "{ \n \"sender\":{ \n \"name\":\"Sender Alex\",\n \"email\":\"senderalex@example.com\"\n },\n \"to\":[ \n { \n \"email\":\"${workflow.input.payload.primaryEmail}\",\n \"name\":\"${workflow.input.payload.fullName}\"\n }\n ],\n \"subject\":\"Hello world\",\n \"htmlContent\":\"<html><head></head><body><p>Hello,</p>This is my first transactional email sent from Brevo.</p></body></html>\"\n}"
}
},
"type": "HTTP",
"decisionCases": {},
"defaultCase": [],
"forkTasks": [],
"startDelay": 0,
"joinOn": [],
"optional": false,
"defaultExclusiveJoinTask": [],
"asyncComplete": false,
"loopOver": [],
"onStateChange": {}
}
],
"inputParameters": [
"activity",
"primaryEmail",
"fullName"
],
"outputParameters": {
"data": "${workflow.input.payload.primaryEmail}"
},
"failureWorkflow": "",
"schemaVersion": 2,
"restartable": true,
"workflowStatusListenerEnabled": false,
"ownerEmail": "atwong@alumni.uci.edu",
"timeoutPolicy": "ALERT_ONLY",
"timeoutSeconds": 0,
"variables": {},
"inputTemplate": {},
"onStateChange": {}
}

7. Now create a new workflow. I called it “CommonRoom_WebHook”

The only thing I really did was do a match on “type”. I think what this does is check if the input JSON has a “type” field.

{
"createTime": 1688967457476,
"updateTime": 1689017855380,
"name": "CommonRoom_WebHook",
"description": "Edit or extend this sample workflow. Set the workflow name to get started",
"version": 1,
"tasks": [
{
"name": "get_random_fact",
"taskReferenceName": "get_random_fact",
"inputParameters": {
"http_request": {
"uri": "https://orkes-api-tester.orkesconductor.com/api",
"method": "GET",
"connectionTimeOut": 3000,
"readTimeOut": 3000,
"accept": "application/json",
"contentType": "application/json"
}
},
"type": "HTTP",
"decisionCases": {},
"defaultCase": [],
"forkTasks": [],
"startDelay": 0,
"joinOn": [],
"optional": false,
"defaultExclusiveJoinTask": [],
"asyncComplete": false,
"loopOver": [],
"onStateChange": {}
},
{
"name": "webhook_task_4fnn8",
"taskReferenceName": "webhook_task_4fnn8_ref",
"inputParameters": {
"matches": {
"$['payload']['type']": "${workflow.input.payload.type}"
}
},
"type": "WAIT_FOR_WEBHOOK",
"decisionCases": {},
"defaultCase": [],
"forkTasks": [],
"startDelay": 0,
"joinOn": [],
"optional": false,
"defaultExclusiveJoinTask": [],
"asyncComplete": false,
"loopOver": [],
"onStateChange": {}
}
],
"inputParameters": [],
"outputParameters": {
"data": "${get_random_fact.output.response.body.fact}"
},
"failureWorkflow": "",
"schemaVersion": 2,
"restartable": true,
"workflowStatusListenerEnabled": false,
"ownerEmail": "atwong@alumni.uci.edu",
"timeoutPolicy": "ALERT_ONLY",
"timeoutSeconds": 0,
"variables": {},
"inputTemplate": {},
"onStateChange": {}
}

8. Create the webhook called “Common Room to Email”

Assign the webhook workflow to “receive the webhook event” and then click on the option to “start workflow when webhook event comes” and assign the Brevo email workflow.

9. Execute the call from Common Room or from Postman

Make sure that you use the correct headers and use the same body as the one you did with the “run workflow” step during testing.

Setup in Common Room

  1. Create the webhook

2. Create the workflow

I had to use “meet a criteria” workflow since you can’t message to a webhook yet.

Source code for all assets can be found at https://github.com/alberttwong/orkes-brevo-commonroom

--

--

Albert Wong

#eCommerce #Java #Database #k8s #Automation. Hobbies: #BoardGames #Comics #Skeet #VideoGames #Pinball #Magic #YelpElite #Travel #Candy