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. Server-side query on last_event_time. The endpoint caps each response at 1000 records with no pagination, so ingestr recursively splits the time range until every window fits under the cap.
global_statsdatedatemergeGlobal email statistics. Server-side start_date/end_date filter. --interval-start is required. Aggregation defaults to daily; use a global_stats:week or global_stats:month suffix for weekly/monthly grain.
bouncesemail, createdcreatedmergeBounced addresses. Server-side start_time/end_time Unix filter.
blocksemail, createdcreatedmergeBlocked addresses (e.g. unroutable domains). Same suppression filter.
invalid_emailsemail, createdcreatedmergeInvalid addresses. Same suppression filter.
spam_reportsemail, createdcreatedmergeSpam-report suppressions. Same suppression filter.
unsubscribesemail, createdcreatedmergeGlobal unsubscribe list. Same suppression filter.
suppression_groupsid-replaceUnsubscribe (suppression) groups.
suppression_group_membersgroup_id, email-replaceSuppressed addresses per group; fans out over each group.
templatesidupdated_atmergeTransactional templates (legacy + dynamic). Filtered client-side on updated_at.
listsid-replaceMarketing contact lists. No time filter; the table is fully replaced on each run.
single_sendsidupdated_atmergeMarketing single sends. Filtered client-side on updated_at.

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.