# Merge Airtable Records and Sendgrid Email Templates

> Instead of Frontend / Web firing serial fetches to Airtable and SendGrid, one pipeline hits https://api.airtable.com/v0/{{query.baseId}}/{{query.tableName}}?maxRecords=5 (and sibling steps) in parallel and returns mapped JSON.

- Canonical page: https://realcomposer.com/recipes/merge-airtable-and-sendgrid-templates
- Client platform: Frontend / Web
- Upstream services: Airtable, SendGrid
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/merge-airtable-and-sendgrid-templates.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=merge-airtable-and-sendgrid-templates&via=agent

## Problem: Waterfall latency from multiple Airtable and SendGrid requests

Frontend / Web widgets often await Airtable and SendGrid sequentially, multiplying TLS handshakes on cellular networks and amplifying failure rates.

- Race conditions between parallel manual fetches
- Higher mobile data usage from redundant JSON
- Timeouts when any upstream exceeds cellular RTT

## Solution steps

1. **Add vault secrets for this pipeline**: Create AIRTABLE_PAT, SENDGRID_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Configure upstream steps and output mapping**: Use GET against https://api.airtable.com/v0/{{query.baseId}}/{{query.tableName}}?maxRecords=5. Allowed origins on the client token should match leave cache ttl at 0 when each response is user-specific (include userid or record id in query params before enabling cache).

3. **Call from Frontend / Web**: Allowed origins on the token should list every Frontend / Web host that calls this URL.

```
const res = await fetch('https://realcomposer.com/v1/workspace/merge-airtable-and-sendgrid-templates', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
```

## Pipeline config

Import this config into a RealComposer pipeline. `{{secrets.NAME}}` values are read from the encrypted Secret Vault at request time, so the client never sees them.

```json
{
  "name": "Merge Airtable Records and Sendgrid Email Templates",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "airtable",
      "upstreamUrlTemplate": "https://api.airtable.com/v0/{{query.baseId}}/{{query.tableName}}?maxRecords=5",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.AIRTABLE_PAT}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "sendgrid",
      "upstreamUrlTemplate": "https://api.sendgrid.com/v3/marketing/stats?start_date={{query.startDate}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.SENDGRID_API_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "airtable.recordId",
        "sourcePath": "records.0.id",
        "type": "string",
        "sourceStep": "airtable"
      },
      {
        "targetPath": "airtable.fields",
        "sourcePath": "records.0.fields",
        "type": "object",
        "sourceStep": "airtable"
      },
      {
        "targetPath": "sendgrid.delivered",
        "sourcePath": "0.stats.0.metrics.delivered",
        "type": "number",
        "sourceStep": "sendgrid"
      },
      {
        "targetPath": "sendgrid.opens",
        "sourcePath": "0.stats.0.metrics.opens",
        "type": "number",
        "sourceStep": "sendgrid"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/merge-airtable-and-sendgrid-templates" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_merge-ai",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "merge-airtable-and-sendgrid-templates"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "airtable_recordId": "sample",
  "airtable_fields": "sample",
  "sendgrid_delivered": "sample",
  "sendgrid_opens": "sample"
}
```

## FAQ

### Can Frontend / Web call Airtable without holding the production key?

Store AIRTABLE_PAT, SENDGRID_API_KEY for merge-airtable-and-sendgrid-templates. Frontend / Web never sees decrypted values.

### Does POST traffic get cached?

merge-airtable-and-sendgrid-templates keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache.

### Can I restrict which domains call this pipeline?

Upstream steps in merge-airtable-and-sendgrid-templates honor timeoutMs and optional fallback JSON without leaking secrets.
