# Combine mailchimp audience with hubspot contacts

> List membership from Mailchimp and CRM lifecycle stage from HubSpot. For "combine mailchimp audience with hubspot contacts", 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 Frontend / Web hit only https://realcomposer.com/v1/workspace/combine-mailchimp-with-hubspot-contacts with an rc_live_ client token.

- Canonical page: https://realcomposer.com/recipes/combine-mailchimp-with-hubspot-contacts
- Client platform: Frontend / Web
- Upstream services: Mailchimp, HubSpot
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/combine-mailchimp-with-hubspot-contacts.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=combine-mailchimp-with-hubspot-contacts&via=agent

## Problem: Serial Mailchimp and HubSpot calls slow Frontend / Web pages

Each extra Mailchimp and HubSpot hop adds hundreds of milliseconds and another OAuth refresh path your UI must manage.

- One slow upstream blocking an entire page
- Partial failures leaving UI in inconsistent states
- Duplicate auth refresh logic per service

## Solution steps

1. **Store upstream credentials in Secret Vault**: Create MAILCHIMP_BASIC_AUTH, HUBSPOT_ACCESS_TOKEN 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://{{secrets.MAILCHIMP_DC}}.api.mailchimp.com/3.0/lists/{{query.listId}}/members?count=10. 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**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
const res = await fetch('https://realcomposer.com/v1/workspace/combine-mailchimp-with-hubspot-contacts', {
  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": "Combine mailchimp audience with hubspot contacts",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "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/combine-mailchimp-with-hubspot-contacts" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_combine-",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "combine-mailchimp-with-hubspot-contacts"
  },
  "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

### Which Mailchimp credential belongs in the vault for this pipeline?

Point Frontend / Web at /recipes/combine-mailchimp-with-hubspot-contacts edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Does POST traffic get cached?

combine-mailchimp-with-hubspot-contacts vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

### How do I rotate upstream credentials?

Upstream steps in combine-mailchimp-with-hubspot-contacts honor timeoutMs and optional fallback JSON without leaking secrets.
