# Call Hubspot API from Client Side Web Application

> Frontend / Web cannot safely store HubSpot production keys. Vault-bound headers reach https://api.hubapi.com/crm/v3/objects/contacts/{{query.contactId}} on Workers while apps call your hubspot-api-client-proxy edge URL.

- Canonical page: https://realcomposer.com/recipes/hubspot-api-client-proxy
- Client platform: Frontend / Web
- Upstream services: HubSpot
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/hubspot-api-client-proxy.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=hubspot-api-client-proxy&via=agent

## Problem: Why Frontend / Web leaks HubSpot credentials

Attackers routinely extract HubSpot secrets from Frontend / Web builds. Direct browser calls also expose internal error payloads with hostnames.

- Production HubSpot keys copied from Frontend / Web bundles
- Compliance violations after credential leaks
- Attackers replaying vault-grade scopes from a laptop

## Solution steps

1. **Store upstream credentials in Secret Vault**: Add HUBSPOT_ACCESS_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Target the real upstream URL**: Use GET against https://api.hubapi.com/crm/v3/objects/contacts/{{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**: Allowed origins on the token should list every Frontend / Web host that calls this URL.

```
const res = await fetch('https://realcomposer.com/v1/workspace/hubspot-api-client-proxy', {
  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": "Call Hubspot API from Client Side Web Application",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "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": "contactId",
        "sourcePath": "id",
        "type": "string",
        "sourceStep": "hubspot"
      },
      {
        "targetPath": "email",
        "sourcePath": "properties.email",
        "type": "string",
        "sourceStep": "hubspot"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/hubspot-api-client-proxy" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

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

Slimmed RealComposer response:

```json
{
  "contactId": "sample",
  "email": "sample"
}
```

## FAQ

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

Point Frontend / Web at /recipes/hubspot-api-client-proxy edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Does POST traffic get cached?

hubspot-api-client-proxy POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard.

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

Upstream steps in hubspot-api-client-proxy honor timeoutMs and optional fallback JSON without leaking secrets.
