Skip to content

SendGrid

SendGrid is Twilio's email delivery and marketing platform.

Bruin supports SendGrid as a source for Ingestr assets, and you can use it to ingest data from SendGrid into your data warehouse.

To set up a SendGrid connection, you need to have a SendGrid API key. For more information, please refer here

Follow the steps below to correctly set up SendGrid as a data source and run ingestion:

Configuration

Step 1: Add a connection to .bruin.yml file

To connect to SendGrid, you need to add a configuration item to the connections section of the .bruin.yml file. This configuration must comply with the following schema:

yaml
    connections:
      sendgrid:
        - name: "my_sendgrid"
          api_key: "YOUR_SENDGRID_API_KEY"
  • api_key: The API key used for authentication with the SendGrid v3 API.
  • on_behalf_of (optional): The subuser username to query on behalf of, when using a parent account to access a subuser's data.

Step 2: Create an asset file for data ingestion

To ingest data from SendGrid, you need to create an asset configuration file. This file defines the data flow from the source to the destination. Create a YAML file (e.g., sendgrid_ingestion.yml) inside the assets folder and add the following content:

yaml
name: public.sendgrid
type: ingestr
connection: postgres

parameters:
  source_connection: my_sendgrid
  source_table: 'bounces'
  destination: postgres
  • name: The name of the asset.
  • type: Specifies the type of the asset. It will be always ingestr type for SendGrid.
  • connection: This is the destination connection.
  • source_connection: The name of the SendGrid connection defined in .bruin.yml.
  • source_table: The name of the data table in SendGrid you want to ingest. For example, bounces would ingest bounced email records.

Available Source Tables

TablePKInc KeyInc StrategyDetails
messagesmsg_idlast_event_timemergeEmail Activity feed. Requires the Email Activity add-on.
global_statsdatedatemergeGlobal email statistics. Requires --interval-start. Use a global_stats:week or global_stats:month suffix for weekly/monthly grain.
bouncesemail, createdcreatedmergeBounced addresses.
blocksemail, createdcreatedmergeBlocked addresses.
invalid_emailsemail, createdcreatedmergeInvalid addresses.
spam_reportsemail, createdcreatedmergeSpam-report suppressions.
unsubscribesemail, createdcreatedmergeGlobal unsubscribe list.
suppression_groupsidreplaceUnsubscribe (suppression) groups.
suppression_group_membersgroup_id, emailreplaceSuppressed addresses per group.
templatesidupdated_atmergeTransactional templates (legacy + dynamic).
listsidreplaceMarketing contact lists.
single_sendsidupdated_atmergeMarketing single sends.

Step 3: Run asset to ingest data

bash
bruin run ingestr.sendgrid.asset.yml

As a result of this command, Bruin will ingest data from the given SendGrid table into your Postgres database.