
Connect Two Systems (Integration)
tutorialon Jun 30, 2025 (created Nov 14, 2024) • 4 min
In this tutorial we're going to use Merrymake to connect two 3rd-party APIs; to send ourselves an email with a random joke every day.
Prerequisites
First, open Git Bash. If you don't have Git Bash, get it from https://git-scm.com/ .
We also need to make sure we have NodeJS installed. We can test this by running this command in Git Bash:
$ npm --versionIt should give something like 10.2.3. If not get it from https://nodejs.org/ The final tool we need is the Merrymake CLI, which uses Git and NodeJS. Install the CLI with the command:
$ npm install --global @merrymake/cli
Start Using Merrymake
With the CLI installed, we are ready to start using Merrymake. The first command we should run on every device we want to use Merrymake on is:
$ mm startThe mm tool now guides us through the initial process. Select:
setup new key specifically for Merrymake- Input your email address
create new organization- Name your organization or press enter to accept the suggested name
initialize with a basic templatetypescriptdeploy the service immediatelypost an event to the rapids- Input your name (or anything)
- Input
admin key - Press enter to accept the suggested duration (
14 days)
We should now see Hello, XXXX!, this means our service is running in the cloud. If you don't see this please reach out on our Discord to get assistance.

Send Emails
We are ready to start sending emails. We navigate into the repository we just created with the command:
$ cd [organization name]/back-end/service-1We'll use Mailgun as the email provider, so head over there and sign up for a free account. Remember to verify your email. Then, we need to create an API key and copy it. We put this API key in a secret environment variable with the command:
$ mm envvar- Input
MAILGUN the value is secret- Insert the API key
accessible in both prod and init run
We also need to grab our Mailgun trial email domain.
- Navigate to Send › Sending › Overview.
- Add your email to the "Authorized Recipients" on the right.
- Verify your email again.
- Copy your trial email domain

- Put that in another secret envvar:
Insert the trial domain$ mm envvar new EMAIL_DOMAIN secretxxxxxxxxxxx.mailgun.org,accessible in both prod and init run.
To work with Mailgun we need to install an npm package for it:
$ npm install mailgun.jsOpen the file index.ts and replace its content with this:
back-end/service-1/index.tsimport { merrymakeService } from "@merrymake/service";
import Mailgun from "mailgun.js";
async function handleSendEmail(payloadBuffer: Buffer) {
const joke = payloadBuffer.toString();
const mailgun = new Mailgun(FormData);
const mg = mailgun.client({
username: "api",
key: process.env.MAILGUN!,
});
mg.messages.create(process.env.EMAIL_DOMAIN!, {
from: `Merrymake <merrymake@${process.env.EMAIL_DOMAIN!}>`,
to: ["YOUR@EMAIL.com"],
subject: "Daily Joke",
text: joke,
});
}
merrymakeService({
handleSendEmail,
});Notice: Remember to change YOUR@EMAIL.com
Since we've changed the function name we also need to update the hooks in merrymake.json, so replace its content with this:
back-end/service-1/merrymake.json{
"hooks": {
"main/send-email": "handleSendEmail"
}
}We can test to verify that our code works by deploying it
$ mm deployAnd triggering it with
$ mm rapids post send-email text "This is a test" _It should say Queued job. and within 15 minutes an email should arrive in your inbox (or spam folder).

Get a Random Joke
To fetch a random joke we install a package for making HTTP requests:
$ npm install axiosWe use this library to call another 3rd-party API called iCanHazDadJoke . Open the file index.ts and replace it's content with this:
back-end/service-1/index.tsimport {
merrymakeService
postToRapids,
} from "@merrymake/service";
import Mailgun from "mailgun.js";
import axios from "axios";
async function runDaily(payloadBuffer: Buffer) {
const resp = await axios.get("https://icanhazdadjoke.com/", {
headers: { Accept: "text/plain" },
});
postToRapids("send-email", resp.data);
}
async function handleSendEmail(payloadBuffer: Buffer) {
const joke = payloadBuffer.toString();
const mailgun = new Mailgun(FormData);
const mg = mailgun.client({
username: "api",
key: process.env.MAILGUN!,
});
mg.messages.create(process.env.EMAIL_DOMAIN!, {
from: `Merrymake <merrymake@${process.env.EMAIL_DOMAIN!}>`,
to: ["YOUR@EMAIL.com"],
subject: "Daily Joke",
text: joke,
});
}
merrymakeService({
runDaily,
handleSendEmail,
});Since we've changed the function name we also need to change the hook:
back-end/service-1/merrymake.json{
"hooks": {
"main/send-email": "handleSendEmail",
"main/daily": "runDaily"
}
}Now to deploy the service we simply run:
$ mm deployThe Merrymake platform automatically builds, packages, and deploys the service, and then hooks it up for traffic.

Run on a Schedule
The only thing left is to trigger the service automatically once every day. Merrymake supports recurring jobs out of the box. We do declare our recurring events in the event-configuration folder
$ cd ../../event-configurationHere we can replace the content of cron.json
event-configuration/cron.json{
"daily": { "expression": "0 0 0 ? * * *" }
}Save the file and deploy the event-configuration:
$ mm deployConclusion
Using the CLI we have:
- Registered an account and created an organization
- Deployed a back end and the event configurations
- Inspected and posted events to our Rapids
- Set two secret environment variable
- Created a universal API key
We have seen how to implement and deploy a serverless back end with two co-deployed services that communicate.
These are the basic steps to connect two 3rd-party systems with Merrymake.
