marketo_send_sample_email
Send a preview email to a specified address for QA. Optionally use a lead's data to render the email with personalized content.
Instructions
Send a sample/preview of an email to a specified email address. Optionally render with a specific lead's data by passing leadId. Useful for QA before approving.
Input Schema
| Name | Required | Description | Default |
|---|---|---|---|
| emailId | Yes | ||
| emailAddress | Yes | ||
| textOnly | No | ||
| leadId | No |
Implementation Reference
- src/index.ts:525-545 (handler)The core handler for the marketo_send_sample_email tool. Sends a sample email via Marketo's REST API. Accepts emailId, emailAddress, textOnly (optional), and leadId (optional). Calls makeApiRequest with POST method to the /asset/v1/email/{emailId}/sendSample.json endpoint using application/x-www-form-urlencoded content type.
server.tool( 'marketo_send_sample_email', 'Send a sample/preview of an email to a specified email address. Optionally render with a specific lead\'s data by passing leadId. Useful for QA before approving.', { emailId: z.number(), emailAddress: z.string().email(), textOnly: z.boolean().optional(), leadId: z.number().optional(), }, tool(async ({ emailId, emailAddress, textOnly, leadId }) => { const data: Record<string, string> = { emailAddress }; if (textOnly !== undefined) data.textOnly = textOnly.toString(); if (leadId !== undefined) data.leadId = leadId.toString(); return makeApiRequest( `/asset/v1/email/${emailId}/sendSample.json`, 'POST', data, 'application/x-www-form-urlencoded' ); }) ); - src/index.ts:528-533 (schema)Zod schema for input validation. Requires emailId (number) and emailAddress (email format string). Optionally accepts textOnly (boolean) and leadId (number).
{ emailId: z.number(), emailAddress: z.string().email(), textOnly: z.boolean().optional(), leadId: z.number().optional(), }, - src/index.ts:525-545 (registration)Registration of the tool with the MCP server under the name 'marketo_send_sample_email'.
server.tool( 'marketo_send_sample_email', 'Send a sample/preview of an email to a specified email address. Optionally render with a specific lead\'s data by passing leadId. Useful for QA before approving.', { emailId: z.number(), emailAddress: z.string().email(), textOnly: z.boolean().optional(), leadId: z.number().optional(), }, tool(async ({ emailId, emailAddress, textOnly, leadId }) => { const data: Record<string, string> = { emailAddress }; if (textOnly !== undefined) data.textOnly = textOnly.toString(); if (leadId !== undefined) data.leadId = leadId.toString(); return makeApiRequest( `/asset/v1/email/${emailId}/sendSample.json`, 'POST', data, 'application/x-www-form-urlencoded' ); }) ); - src/index.ts:23-53 (helper)Helper function that executes the actual HTTP request to the Marketo API, using Bearer token authentication and supporting both JSON and URL-encoded content types.
async function makeApiRequest( endpoint: string, method: string, data?: any, contentType: string = 'application/json' ) { const token = await tokenManager.getToken(); const headers: Record<string, string> = { Authorization: `Bearer ${token}`, }; if (contentType) { headers['Content-Type'] = contentType; } try { const response = await axios({ url: `${MARKETO_BASE_URL}${endpoint}`, method, data: contentType === 'application/x-www-form-urlencoded' ? new URLSearchParams(data).toString() : data, headers, }); return response.data; } catch (error: any) { console.error('API request failed:', error.response?.data || error.message); throw error; } }