# SendGrid

![SendGrid_logo.png](https://assets.relyanceuat.xyz/images/docs/7174118784525/7173539987085.png)
SendGrid is a cloud-based platform SMTP provider that solves the challenge of email delivery. It provides and manages all the technical details of an email server on your company's behalf, so your communications with customers are reliably sent and delivered as needed.

In order to integrate SendGrid with Relyance AI you will need a SendGrid **API KEY**.

#### In SendGrid:

![SendGrid-3.png](https://assets.relyanceuat.xyz/images/docs/7174118784525/7174021246989.png)
![SendGrid-2.png](https://assets.relyanceuat.xyz/images/docs/7174118784525/7174021229069.png)
1. Login to your SendGrid web app account.
2. Navigate to **Settings**> **API Keys** in the left hand menu.
3. Click the **Create API Key** Button.

4. Give your **API KEY** a descriptive name like 'relyance-api' and either select **Full Access** or **Restricted Access**.

When selecting Restricted access, make sure you give read access to each of the available endpoints.

![SendGrid-1.png](https://assets.relyanceuat.xyz/images/docs/7174118784525/7173897609741.png)

SendGrid doesn't offer Read Access on some endpoints, such as Marketing. In these cases you may need to provide full access in order for Relyance to read from those endpoints.
5. Click **Create & View**.
6. Copy the API Key on the following screen to use in the Relyance Application. **You will not be able to access the API Key again after you leave this screen.**
7. In some instances you may need to run the following command in a terminal in order to enable certain endpoints:
```bash
curl -X PUT "https://api.sendgrid.com/v3/api_keys/<<API KEY ID>>" \
--header "Authorization: Bearer <<YOUR_API_KEY_HERE>>" \
--header "Content-Type: application/json" \
--data '{"name": "Profiles key", "scopes": ["user.profile.read", "marketing.read","teammates.read"]}'
```
If needed, please contact Relyance support for assistance with this step.

#### In the Relyance AI application:

1. Login to your Relyance account.
2. Navigate to the **Settings** Menu in the bottom left-hand side.
3. Select **Integrations**.
4. Click on the **Vendors and Data Stores** filter.
5. Find the **SendGrid** integration card and click it to open its connections.
6. Under **Authentication Method**, choose **Custom**.
8. Paste the **API KEY** into its respective field.

![SendGrid-4.png](https://assets.relyanceuat.xyz/images/docs/7174118784525/7174179288333.png)

The **Authentication** step asks for:

- **API KEY**: required; held as a secret.
- **Enable Marketing Campaigns scanning**: Enable to scan SendGrid Marketing Campaigns contacts and field definitions. Requires Marketing Campaigns to be provisioned on the account and a Custom Access API key with the marketing.read scope enabled (Full Access API keys do not include this scope); optional.

9. Click **Authenticate**.
10. At this point, you should see the following result on the Vendor Integrations page:

![SendGrid-5.png](https://assets.relyanceuat.xyz/images/docs/7174118784525/7174179287053.png)

11. Congratulations, you are now connected to **SendGrid**.

<!-- terraform-examples:begin (generated from the integration catalog; do not hand-edit) -->

## Manage this integration with Terraform

Connections for this integration can be managed as code with the [Relyance Terraform provider](https://registry.terraform.io/providers/Relyance/relyance/latest). Non-secret fields go in `auth.params`; secret fields go in `auth.secrets_wo`, which is write-only — never stored in Terraform state. Rotate secrets by bumping `auth.secrets_wo_version`.

```hcl
resource "relyance_integration_connection" "twilio_sendgrid" {
  vendor = "twilio_sendgrid"
  name   = "<your connection name>"

  auth = {
    method = "api-key"
    params = {
      data_storage_location = "us"
    }
    # Secret fields are write-only: sent to Relyance, never stored in state.
    secrets_wo = {
      api_key = var.twilio_sendgrid_api_key
    }
    secrets_wo_version = 1
  }

  scans = { "data-inspection" = { enabled = true } }
}
```

<!-- terraform-examples:end -->
