# Merge Contentful Cms Data with Real Time Pricing API

> Instead of Frontend / Web firing serial fetches to Contentful and Stripe, one pipeline hits https://cdn.contentful.com/spaces/{{query.spaceId}}/entries (and sibling steps) in parallel and returns mapped JSON.

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

## Problem: Waterfall latency from multiple Contentful and Stripe requests

Frontend / Web widgets often await Contentful and Stripe 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. **Bind vault keys to the Worker**: Store CONTENTFUL_ACCESS_TOKEN, STRIPE_SECRET_KEY in the vault. Frontend / Web never embeds the raw secret, only a revocable rc_live_ client token.

2. **Target the real upstream URL**: Configure headersTemplate to inject vault secrets, target https://cdn.contentful.com/spaces/{{query.spaceId}}/entries, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Call from Frontend / Web**: Call https://realcomposer.com/v1/workspace/merge-contentful-with-live-pricing with a restricted rc_live_ client token. Frontend / Web never sends upstream secrets.

```
const res = await fetch('https://realcomposer.com/v1/workspace/merge-contentful-with-live-pricing', {
  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 Contentful Cms Data with Real Time Pricing API",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "contentful",
      "upstreamUrlTemplate": "https://cdn.contentful.com/spaces/{{query.spaceId}}/entries",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.CONTENTFUL_ACCESS_TOKEN}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "stripe",
      "upstreamUrlTemplate": "https://api.stripe.com/v1/customers/{{query.customerId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.STRIPE_SECRET_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "contentful.entryId",
        "sourcePath": "items.0.sys.id",
        "type": "string",
        "sourceStep": "contentful"
      },
      {
        "targetPath": "contentful.title",
        "sourcePath": "items.0.fields.title",
        "type": "string",
        "sourceStep": "contentful"
      },
      {
        "targetPath": "stripe.customerId",
        "sourcePath": "id",
        "type": "string",
        "sourceStep": "stripe"
      },
      {
        "targetPath": "stripe.email",
        "sourcePath": "email",
        "type": "string",
        "sourceStep": "stripe"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/merge-contentful-with-live-pricing" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

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

Slimmed RealComposer response:

```json
{
  "contentful_entryId": "sample",
  "contentful_title": "sample",
  "stripe_customerId": "sample",
  "stripe_email": "sample"
}
```

## FAQ

### What should Frontend / Web store instead of Contentful secrets?

Log request IDs for merge-contentful-with-live-pricing, not raw Contentful payloads, because upstream bodies may include PII.

### How do I forward JSON bodies to POST upstreams?

merge-contentful-with-live-pricing vault headers attach server-side, but Anthropic or OpenAI model and messages must come from the client body.

### How do I rotate upstream credentials?

Rotate vault secrets for merge-contentful-with-live-pricing anytime; clients keep the same rc_live_ token.
