# Combine Stripe Customer and Invoices into Single REST Call

> To combine stripe customer and invoices into single rest call, configure parallel steps for Stripe. Frontend / Web performs one authorized GET/POST to RealComposer and receives a merged payload.

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

## Problem: Serial Stripe calls slow Frontend / Web pages

Each extra Stripe 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**: Store 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**: Point step customer at https://api.stripe.com/v1/customers/{{query.customerId}} with GET. Add output mapping fields that mirror the JSON contract your screen already expects. 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/combine-stripe-customer-and-invoices', {
  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 Stripe Customer and Invoices into Single REST Call",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "customer",
      "upstreamUrlTemplate": "https://api.stripe.com/v1/customers/{{query.customerId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.STRIPE_SECRET_KEY}}"
      },
      "timeoutMs": 3000
    },
    {
      "stepKey": "invoices",
      "upstreamUrlTemplate": "https://api.stripe.com/v1/invoices?customer={{query.customerId}}&limit=5",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.STRIPE_SECRET_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "customer.customerId",
        "sourcePath": "id",
        "type": "string",
        "sourceStep": "customer"
      },
      {
        "targetPath": "customer.email",
        "sourcePath": "email",
        "type": "string",
        "sourceStep": "customer"
      },
      {
        "targetPath": "invoices.customerId",
        "sourcePath": "id",
        "type": "string",
        "sourceStep": "invoices"
      },
      {
        "targetPath": "invoices.email",
        "sourcePath": "email",
        "type": "string",
        "sourceStep": "invoices"
      }
    ]
  }
}
```

## Call the pipeline

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

Slimmed RealComposer response:

```json
{
  "customer_customerId": "sample",
  "customer_email": "sample",
  "invoices_customerId": "sample",
  "invoices_email": "sample"
}
```

## FAQ

### Does Frontend / Web need CORS changes after adding RealComposer?

Store STRIPE_SECRET_KEY for combine-stripe-customer-and-invoices. Frontend / Web never sees decrypted values.

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

combine-stripe-customer-and-invoices forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates.

### How do I rotate upstream credentials?

Upstream steps in combine-stripe-customer-and-invoices honor timeoutMs and optional fallback JSON without leaking secrets.
