# Mailchimp and hubspot combined cache layer

> Compose and cache merged marketing audience JSON. For "mailchimp and hubspot combined cache layer", store MAILCHIMP_BASIC_AUTH, HUBSPOT_ACCESS_TOKEN in Secret Vault, call https://{{secrets.MAILCHIMP_DC}}.api.mailchimp.com/3.0/lists/{{query.listId}}/members?count=10 from a Worker, and let Retool hit only https://realcomposer.com/v1/workspace/mailchimp-hubspot-shared-edge-cache with an rc_live_ client token. Enable 300s GET cache only when query params identify the resource.

- Canonical page: https://realcomposer.com/recipes/mailchimp-hubspot-shared-edge-cache
- Client platform: Retool
- Upstream services: Mailchimp, HubSpot
- Category: Edge Caching & Rate Limits
- JSON version: https://realcomposer.com/recipes/mailchimp-hubspot-shared-edge-cache.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=mailchimp-hubspot-shared-edge-cache&via=agent

## Problem: Mailchimp and HubSpot rate limits from Retool traffic

Without edge caching, identical Mailchimp and HubSpot reads during a session still round-trip to the origin.

- HTTP 429 responses during launch traffic
- Surprise SaaS overages from duplicate reads
- Slower repeat views than necessary

## Solution steps

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

2. **Target the real upstream URL**: Use GET against https://{{secrets.MAILCHIMP_DC}}.api.mailchimp.com/3.0/lists/{{query.listId}}/members?count=10. Allowed origins on the client token should match set cache ttl to 300s so repeat gets with the same query string hit caches.default.

3. **Query from Retool**: Allowed origins on the token should list every Retool host that calls this URL.

```
// REST resource or JS query
const rows = await fetch('https://realcomposer.com/v1/workspace/mailchimp-hubspot-shared-edge-cache', {
  headers: { Authorization: 'Bearer rc_live_token' }
}).then(r => r.json());
```

## 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": "Mailchimp and hubspot combined cache layer",
  "method": "GET",
  "cacheTtlSeconds": 300,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "mailchimp",
      "upstreamUrlTemplate": "https://{{secrets.MAILCHIMP_DC}}.api.mailchimp.com/3.0/lists/{{query.listId}}/members?count=10",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Basic {{secrets.MAILCHIMP_BASIC_AUTH}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "hubspot",
      "upstreamUrlTemplate": "https://api.hubapi.com/crm/v3/objects/contacts/{{query.contactId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.HUBSPOT_ACCESS_TOKEN}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "mailchimp.memberId",
        "sourcePath": "members.0.id",
        "type": "string",
        "sourceStep": "mailchimp"
      },
      {
        "targetPath": "mailchimp.email",
        "sourcePath": "members.0.email_address",
        "type": "string",
        "sourceStep": "mailchimp"
      },
      {
        "targetPath": "hubspot.contactId",
        "sourcePath": "id",
        "type": "string",
        "sourceStep": "hubspot"
      },
      {
        "targetPath": "hubspot.email",
        "sourcePath": "properties.email",
        "type": "string",
        "sourceStep": "hubspot"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/mailchimp-hubspot-shared-edge-cache" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_mailchim",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "mailchimp-hubspot-shared-edge-cache"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "mailchimp_memberId": "sample",
  "mailchimp_email": "sample",
  "hubspot_contactId": "sample",
  "hubspot_email": "sample"
}
```

## FAQ

### Is it safe to log Mailchimp responses in Retool?

Store MAILCHIMP_BASIC_AUTH, HUBSPOT_ACCESS_TOKEN for mailchimp-hubspot-shared-edge-cache. Retool never sees decrypted values.

### When does edge caching apply to this recipe?

mailchimp-hubspot-shared-edge-cache vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

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

Rotate vault secrets for mailchimp-hubspot-shared-edge-cache anytime; clients keep the same rc_live_ token.
