# Merge salesforce contacts with hubspot crm one api

> Parallel fetch Salesforce Contact and HubSpot CRM contact into one JSON object. For "merge salesforce contacts with hubspot crm one api", store SALESFORCE_ACCESS_TOKEN, HUBSPOT_ACCESS_TOKEN in Secret Vault, call https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}} from a Worker, and let Frontend / Web hit only https://realcomposer.com/v1/workspace/merge-salesforce-with-hubspot-api with an rc_live_ client token.

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

## Problem: Waterfall latency from multiple Salesforce and HubSpot requests

Frontend / Web widgets often await Salesforce and HubSpot 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**: Store SALESFORCE_ACCESS_TOKEN, HUBSPOT_ACCESS_TOKEN in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token.

2. **Target the real upstream URL**: Use GET against https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}}. 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**: Call https://realcomposer.com/v1/workspace/merge-salesforce-with-hubspot-api with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.

```
const res = await fetch('https://realcomposer.com/v1/workspace/merge-salesforce-with-hubspot-api', {
  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 salesforce contacts with hubspot crm one api",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "salesforce",
      "upstreamUrlTemplate": "https://{{secrets.SALESFORCE_INSTANCE}}.my.salesforce.com/services/data/v68.0/sobjects/Contact/{{query.contactId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.SALESFORCE_ACCESS_TOKEN}}"
      },
      "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": "salesforce.contactId",
        "sourcePath": "Id",
        "type": "string",
        "sourceStep": "salesforce"
      },
      {
        "targetPath": "salesforce.email",
        "sourcePath": "Email",
        "type": "string",
        "sourceStep": "salesforce"
      },
      {
        "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/merge-salesforce-with-hubspot-api" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_merge-sa",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "merge-salesforce-with-hubspot-api"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "salesforce_contactId": "sample",
  "salesforce_email": "sample",
  "hubspot_contactId": "sample",
  "hubspot_email": "sample"
}
```

## FAQ

### Is it safe to log Salesforce responses in Frontend / Web?

Use scoped tokens where the vendor allows them on merge-salesforce-with-hubspot-api. Admin keys stay {{secrets.*}} references only.

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

merge-salesforce-with-hubspot-api keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache.

### What happens if an upstream step times out?

Upstream steps in merge-salesforce-with-hubspot-api honor timeoutMs and optional fallback JSON without leaking secrets.
