In the world of modern software and business, no application is an island. Your agentic workflows and automations are most powerful when they can communicate with the outside world—to send emails, process payments, update a CRM, or post notifications. This is where third-party APIs come in, and action.do provides the perfect framework to manage these integrations with simplicity and power.
At its core, automation is about connecting systems. action.do provides the building blocks—atomic actions—to create a robust and scalable "business-as-code" architecture. Let's dive into how you can use these actions to seamlessly integrate any third-party API into your workflows.
You could make a raw fetch call directly within a larger script, but this approach quickly becomes messy, repetitive, and difficult to maintain. By wrapping each third-party API call in an atomic action, you unlock several key advantages:
Let's break down how to build an action that interacts with an external service. We'll use the common example of sending a welcome email, which would likely involve an API call to a service like SendGrid, Mailgun, or AWS SES.
The structure is simple and declarative:
import { action } from '@do-sdk/core';
// Import the SDK for your email service
import { mailgunClient } from '../lib/mailgun';
export const sendWelcomeEmail = action({
name: 'send-welcome-email',
description: 'Sends a welcome email to a new user via Mailgun.',
// 1. Define the inputs your action needs
inputs: {
to: { type: 'string', required: true },
name: { type: 'string', required: true }
},
// 2. Implement the core logic in the handler
handler: async ({ inputs, context }) => {
const { to, name } = inputs;
// You'd get your API key securely from context or environment variables
// const apiKey = context.secrets.MAILGUN_API_KEY;
console.log(`Preparing to send welcome email to ${name} at ${to}`);
try {
// 3. Make the actual API call
const response = await mailgunClient.messages.create('your-domain.com', {
from: 'Welcome Team <welcome@your-domain.com>',
to: [to],
subject: `Welcome to the platform, ${name}!`,
text: `Hi ${name},\n\nWe're so glad to have you here!`,
html: `<h1>Hi ${name},</h1><p>We're so glad to have you here!</p>`
});
// 4. Return a structured, successful output
return { success: true, messageId: response.id };
} catch (error) {
console.error('Failed to send email:', error);
// 5. Handle errors gracefully
throw new Error(`Email sending failed: ${error.message}`);
}
},
});
Let's review the key steps in the handler:
The true power emerges when you chain these simple building blocks together. An action.do is a single task. A workflow.do is an orchestration of these tasks to achieve a larger business goal.
Imagine a new user signing up. A workflow could orchestrate a series of API-calling actions:
Each step is a simple, reusable, and robust atomic action. The workflow simply defines the order and logic of their execution. If you need to switch your email provider from Mailgun to SendGrid, you only update the send-welcome-email action. The rest of your business logic remains completely untouched.
Ready to stop writing brittle, monolithic scripts and start building powerful, scalable automations? Encapsulate your API calls with action.do and create the robust building blocks your agentic workflows deserve.