> ## Documentation Index
> Fetch the complete documentation index at: https://sequin.io/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# SendGrid Reference

<Warning>
  **Pardon the mess**

  You are viewing docs related to an older version of Sequin. We're in the process of updating our provider-specific guides and will be done in a few weeks (May 2024). [Please click here](/) to view the latest version of the docs.

  If you're interested in SendGrid and want to learn more about what's changing, [send us a note](mailto:support@sequin.io).
</Warning>

## Supported objects[](#supported-objects "Direct link to Supported objects")

SendGrid offers an extensive API for email operations. Here is a list of objects we support:

| Collection Name          | Read | Write |
| ------------------------ | ---- | ----- |
| Mail Send                | ✅    | ✅     |
| Contacts                 | ✅    | ✅     |
| Custom Fields            | ✅    | ✅     |
| Lists                    | ✅    | ✅     |
| Marketing Campaign Stats | ✅    |       |
| Segments                 | ✅    | ✅     |
| Single Sends             | ✅    | ✅     |
| Security                 | ✅    | ✅     |
| Settings                 | ✅    | ✅     |
| Templates                | ✅    | ✅     |

Need a SendGrid object we're not syncing? We can add it quickly. [Send us a note](mailto:support@sequin.io).

## Setup & Installation[](#setup--installation "Direct link to Setup & Installation")

Sequin authenticates to your SendGrid data using an API Key.

To authenticate with SendGrid:

1. [Generate an API Key](https://app.sendgrid.com/settings/api%5Fkeys) in your SendGrid account.
2. Copy and paste the API Key into the Sequin UI.

Please refer to the [official SendGrid documentation](https://docs.sendgrid.com/ui/account-and-settings/api-keys) for detailed steps and guidelines on generating and managing API keys.

## The Syncing Process[](#the-syncing-process "Direct link to The Syncing Process")

We first backfill your Postgres database with the SendGrid data you've selected. The time for the backfill is dependent upon the amount of data you want to sync. Unless your SendGrid account has over a million records, the backfill should complete in under an hour. Smaller accounts finish in a few minutes. We'll email you when your backfill is complete.

After the initial backfill, we make use of webhooks to ensure all changes in SendGrid are synced instantly. We use occasional polling to make sure we don't miss any changes. This means that changes in SendGrid should show up in your database in a matter of seconds.

Sequin ensures that the upstream API is always the source of truth.

Learn more about \[our syncing process]/syncs.

## Read and write SendGrid data using SQL[](#read-and-write-sendgrid-data-using-sql "Direct link to Read and write SendGrid data using SQL")

You'll connect to your database via [Sequin's Postgres Proxy](/sql-writes), which lets you read from your synced tables as well as write to them. You can use any SQL client that works with Postgres.

Here's an example of what one of your SendGrid tables might look like in your database:

```sql theme={null}
db7hea89oah3tas=> \dt

                   List of relations
 Schema |           Name            | Type  |  Owner
--------+---------------------------+-------+----------
 public | _sync_cdc                 | table | sequin
 public | templates                 | table | sequin
 public | mail_sends                | table | sequin
 public | parses                    | table | sequin
(4 rows)

```

You'll see all the SendGrid objects you selected when setting up your sync are now tables in your database. You'll also see a `_sync_cdc` table which Sequin uses to manage your sync.

Here's what it looks like to query the `templates` table:

```sql theme={null}
select
    id,
    name,
    generation,
    updated_at,
    versions,
from
    templates
where
    id = 'd-d3535';

```

Which returns a row that looks like:

```sql theme={null}
-[ RECORD 1 ]---+-----------------------------
id           | d-d3535
name  | There was a problem
generation        | dynamic
updated_at    | 2023-10-16 18:28:17
versions  | []

```

Updating a SendGrid template is as simple as writing a SQL query. For example, to change the name of the template we just selected, you can write a query like this:

```sql theme={null}
update templates
set name = 'There was a problem updating your credit card'
where id = 'd-d3535';

```

Sequin will write this change to both SendGrid and your database at the same time.

If a write to SendGrid fails, Sequin will roll back the write to your database. For example, if you try to update a template's name to be an integer, you'll receive a Postgres error:

```sql theme={null}
update templates
set name = 12345
where id = 'd-d3535';

ERROR:  column "name" is of type text but expression is of type integer

```

## Next steps[](#next-steps "Direct link to Next steps")

Your SendGrid tables are now available as fully readable and writeable tables in your database. You can query for all your data using SQL, and mutate data thanks to Sequin's Postgres Proxy. To build on this foundation, here are some next steps:

* [Setup your ORM](/reads) to work with your synced tables.
* Edit the SendGrid objects and properties you're syncing at any time.
* Create [views](https://www.postgresql.org/docs/current/tutorial-views.html) on your SendGrid data to tailor your schema to your needs.
* Invite your team to your Sequin account and start building!

If you need assistance setting up your sync, just [send us a note](mailto:support@sequin.io). We're around and eager to help.

## Troubleshooting[](#troubleshooting "Direct link to Troubleshooting")

* If you encounter any errors during the installation or syncing processes, please [reach out](mailto:support@sequin.io).
