# Combine Twilio Verification and User Registration API

> Instead of Frontend / Web firing serial fetches to Twilio, one pipeline hits https://verify.twilio.com/v2/Services/{{secrets.TWILIO_VERIFY_SID}}/Verifications (and sibling steps) in parallel and returns mapped JSON.

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

## Problem: Waterfall latency from multiple Twilio requests

Frontend / Web widgets often await Twilio 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**: Add TWILIO_AUTH_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Set headers, mapping, and cache TTL**: Configure headersTemplate to inject vault secrets, target https://verify.twilio.com/v2/Services/{{secrets.TWILIO_VERIFY_SID}}/Verifications, and Add output mapping fields that mirror the JSON contract your screen already expects. Twilio Verify expects application/x-www-form-urlencoded. RealComposer forwards JSON bodies as-is; wrap Verify calls in a dedicated form-encoding adapter if needed.

3. **Call from Frontend / Web**: 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-twilio-and-user-registration', {
  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 Twilio Verification and User Registration API",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "twilio",
      "upstreamUrlTemplate": "https://verify.twilio.com/v2/Services/{{secrets.TWILIO_VERIFY_SID}}/Verifications",
      "httpMethod": "POST",
      "headersTemplate": {
        "Authorization": "Basic {{secrets.TWILIO_BASIC_AUTH}}",
        "Content-Type": "application/json"
      },
      "timeoutMs": 10000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "status",
        "sourcePath": "status",
        "type": "string",
        "sourceStep": "twilio"
      },
      {
        "targetPath": "sid",
        "sourcePath": "sid",
        "type": "string",
        "sourceStep": "twilio"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/workspace/combine-twilio-and-user-registration" \
  -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_combine-",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "combine-twilio-and-user-registration"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "status": "sample",
  "sid": "sample"
}
```

## FAQ

### Which Twilio credential belongs in the vault for this pipeline?

Store TWILIO_AUTH_TOKEN for combine-twilio-and-user-registration. Frontend / Web never sees decrypted values.

### Does POST traffic get cached?

combine-twilio-and-user-registration POST steps bypass caches.default even if cacheTtlSeconds is set in the dashboard.

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

Rotate vault secrets for combine-twilio-and-user-registration anytime; clients keep the same rc_live_ token.
