Links

Stripe to SendGrid

Overview

In this example, we’re going to use the Buildable SDK to send data from Stripe to SendGrid in 2 easy steps:
  1. 1.
    Create a Stripe connection in Buildable
  2. 2.
    Transact the Message using SendGrid in code
For this example, you'll need a few things:
  • A Buildable account and Buildable Secret Key
  • A Stripe account and Secret Key
  • A SendGrid account and API Key

Step 1: Create a Stripe Connection

To grab events from Stripe, simply create a Stripe connection in Buildable:
  1. 1.
    Click on the Connections tab
  2. 2.
    Click + New
  3. 3.
    Select the Stripe option
  4. 4.
    Securely add your Stripe credentials
  5. 5.
    Click Connect to establish the connection
  6. 6.
    Select the customer.created
  7. 7.
    Click Subscribe
O
Once the connection is established, Buildable will automatically ingest data from Stripe for the selected event types and display them in the Messages tab

Step 2: Transact the Message using SendGrid

Install the Buildable Node SDK
> npm install @buildable/messages
Create an Environment Variable
Add your Buildable Secret Key values in a .env file
Create your Listener
Grab the customer.created message from Buildable and send an email using the @sendgrid/mail package
// Init the SDK
const { createClient } = require('@buildable/messages');
const sgMail = require('@sendgrid/mail');
sgMail.setApiKey(process.env.SENDGRID_API_KEY);
const client = createClient(process.env.MY_BUILDABLE_SECRET);
// Transact the Message using SendGrid
client.on('customer.created', async ({ event, payload }) => {
const msg = {
to: payload.data.object.email,
from: '[email protected]', // Use the email address or domain you verified above
subject: 'Thanks for your purchase!',
text: `Hey, ${payload.data.object.name}!\n\nThanks for signing up for our service!`,
};
try {
await sgMail.send(msg);
} catch (error) {
console.error(error);
if (error.response) {
console.error(error.response.body)
}
}
}, {
platform: "stripe", // Connection platform
label: "my-stripe" // Connection name
});

Ready to test?

Give it a try by creating a customer through the Stripe dashboard!