# Call paddle api from react without leaking api key

> Proxy Paddle Billing API with restricted client tokens and vault-held API keys. For "call paddle api from react without leaking api key", store PADDLE_API_KEY in Secret Vault, call https://api.paddle.com/subscriptions/{{query.subscriptionId}} from a Worker, and let React hit only https://realcomposer.com/v1/workspace/call-paddle-api-from-react-securely with an rc_live_ client token.

- Canonical page: https://realcomposer.com/recipes/call-paddle-api-from-react-securely
- Client platform: React
- Upstream services: Paddle
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/call-paddle-api-from-react-securely.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=call-paddle-api-from-react-securely&via=agent

## Problem: Paddle keys in React network tabs

React ships code or scripts to end-user devices. Any Paddle bearer token in those bundles can be copied from DevTools, proxies, or repackaged apps.

- Shared React projects revealing Paddle tokens
- Sudden Paddle quota burn from scripted abuse
- Inability to rotate keys without redeploying clients

## Solution steps

1. **Add vault secrets for this pipeline**: Create PADDLE_API_KEY vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Target the real upstream URL**: Point step paddle at https://api.paddle.com/subscriptions/{{query.subscriptionId}} 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 React**: Call https://realcomposer.com/v1/workspace/call-paddle-api-from-react-securely with a restricted rc_live_ client token. React never sends upstream secrets.

```
const res = await fetch('https://realcomposer.com/v1/workspace/call-paddle-api-from-react-securely', {
  headers: { Authorization: 'Bearer rc_live_your_token' }
});
const data = await res.json();
```

## 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": "Call paddle api from react without leaking api key",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "paddle",
      "upstreamUrlTemplate": "https://api.paddle.com/subscriptions/{{query.subscriptionId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.PADDLE_API_KEY}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "subscriptionId",
        "sourcePath": "data.id",
        "type": "string",
        "sourceStep": "paddle"
      },
      {
        "targetPath": "status",
        "sourcePath": "data.status",
        "type": "string",
        "sourceStep": "paddle"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/call-paddle-api-from-react-securely" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_call-pad",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "call-paddle-api-from-react-securely"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

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

## FAQ

### What should React store instead of Paddle secrets?

Point React at /recipes/call-paddle-api-from-react-securely edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Will Anthropic or Linear prompt bodies be rewritten?

Cache key for call-paddle-api-from-react-securely: internal edge-cache path plus sorted query. Identical params hit; vary userId per user.

### Can I restrict which domains call this pipeline?

Upstream steps in call-paddle-api-from-react-securely honor timeoutMs and optional fallback JSON without leaking secrets.
