# Combine intercom users with clerk user metadata

> Clerk user profile and Intercom contact record stitched for in-app chat. For "combine intercom users with clerk user metadata", store INTERCOM_ACCESS_TOKEN, CLERK_SECRET_KEY in Secret Vault, call https://api.intercom.io/contacts from a Worker, and let React / Flutter / Mobile hit only https://realcomposer.com/v1/workspace/combine-intercom-with-clerk-users with an rc_live_ client token.

- Canonical page: https://realcomposer.com/recipes/combine-intercom-with-clerk-users
- Client platform: React / Flutter / Mobile
- Upstream services: Intercom, Clerk
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/combine-intercom-with-clerk-users.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=combine-intercom-with-clerk-users&via=agent

## Problem: Serial Intercom and Clerk calls slow React / Flutter / Mobile pages

Each extra Intercom and Clerk 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 INTERCOM_ACCESS_TOKEN, CLERK_SECRET_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.intercom.io/contacts. 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 React / Flutter / Mobile**: 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-intercom-with-clerk-users', {
  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 intercom users with clerk user metadata",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "intercom",
      "upstreamUrlTemplate": "https://api.intercom.io/contacts",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.INTERCOM_ACCESS_TOKEN}}",
        "Accept": "application/json"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "clerk",
      "upstreamUrlTemplate": "https://api.clerk.com/v1/users/{{query.userId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.CLERK_SECRET_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "intercom.contactId",
        "sourcePath": "data.0.id",
        "type": "string",
        "sourceStep": "intercom"
      },
      {
        "targetPath": "intercom.email",
        "sourcePath": "data.0.email",
        "type": "string",
        "sourceStep": "intercom"
      },
      {
        "targetPath": "clerk.userId",
        "sourcePath": "id",
        "type": "string",
        "sourceStep": "clerk"
      },
      {
        "targetPath": "clerk.email",
        "sourcePath": "email_addresses.0.email_address",
        "type": "string",
        "sourceStep": "clerk"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/combine-intercom-with-clerk-users" \
  -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-intercom-with-clerk-users"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "intercom_contactId": "sample",
  "intercom_email": "sample",
  "clerk_userId": "sample",
  "clerk_email": "sample"
}
```

## FAQ

### Does React / Flutter / Mobile need CORS changes after adding RealComposer?

Log request IDs for combine-intercom-with-clerk-users, not raw Intercom payloads, because upstream bodies may include PII.

### What cache key does RealComposer use?

combine-intercom-with-clerk-users keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache.

### How do I rotate upstream credentials?

Upstream steps in combine-intercom-with-clerk-users honor timeoutMs and optional fallback JSON without leaking secrets.
