# Merge Plaid Accounts and Transactions into Single Mobile Payload

> Instead of Mobile App (iOS & Android) firing serial fetches to Plaid, one pipeline hits https://production.plaid.com/accounts/get (and sibling steps) in parallel and returns mapped JSON.

- Canonical page: https://realcomposer.com/recipes/merge-plaid-accounts-and-transactions
- Client platform: Mobile App (iOS & Android)
- Upstream services: Plaid
- Category: Multi-API Aggregation
- JSON version: https://realcomposer.com/recipes/merge-plaid-accounts-and-transactions.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=merge-plaid-accounts-and-transactions&via=agent

## Problem: Waterfall latency from multiple Plaid requests

Mobile App (iOS & Android) widgets often await Plaid 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 PLAID_SECRET in the vault. Mobile App (iOS & Android) never embeds the raw secret, only a revocable rc_live_ client token.

2. **Set headers, mapping, and cache TTL**: Use POST against https://production.plaid.com/accounts/get. Allowed origins on the client token should match post pipelines set cache ttl to 0 because realcomposer only stores get responses at the edge.

3. **Call from Mobile App (iOS & Android)**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
let url = URL(string: "https://realcomposer.com/v1/workspace/merge-plaid-accounts-and-transactions")!
var request = URLRequest(url: url)
request.addValue("Bearer rc_live_token", forHTTPHeaderField: "Authorization")
```

## 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 Plaid Accounts and Transactions into Single Mobile Payload",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "plaid",
      "upstreamUrlTemplate": "https://production.plaid.com/accounts/get",
      "httpMethod": "POST",
      "headersTemplate": {
        "Content-Type": "application/json"
      },
      "timeoutMs": 10000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "accountId",
        "sourcePath": "accounts.0.account_id",
        "type": "string",
        "sourceStep": "plaid"
      },
      {
        "targetPath": "name",
        "sourcePath": "accounts.0.name",
        "type": "string",
        "sourceStep": "plaid"
      },
      {
        "targetPath": "type",
        "sourcePath": "accounts.0.type",
        "type": "string",
        "sourceStep": "plaid"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/workspace/merge-plaid-accounts-and-transactions" \
  -H "Authorization: Bearer rc_live_client_token" \
  -H "Content-Type: application/json" \
  -d '{"model":"example"}'
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_merge-pl",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "merge-plaid-accounts-and-transactions"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "accountId": "sample",
  "name": "sample",
  "type": "sample"
}
```

## FAQ

### Does Mobile App (iOS & Android) need CORS changes after adding RealComposer?

Yes for merge-plaid-accounts-and-transactions. Ship only an rc_live_ client token in Mobile App (iOS & Android); RealComposer injects PLAID_SECRET on https://production.plaid.com/accounts/get.

### What cache key does RealComposer use?

merge-plaid-accounts-and-transactions forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates.

### How do I rotate upstream credentials?

Rotate vault secrets for merge-plaid-accounts-and-transactions anytime; clients keep the same rc_live_ token.
