# Retool Public App Hide REST API Credentials

> Never place API_BEARER_TOKEN inside Retool source. RealComposer injects them when calling https://jsonplaceholder.typicode.com/users/{{query.userId}}, so browsers see only a client token.

- Canonical page: https://realcomposer.com/recipes/retool-public-app-hide-api-credentials
- Client platform: Retool
- Upstream services: REST API
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/retool-public-app-hide-api-credentials.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=retool-public-app-hide-api-credentials&via=agent

## Problem: REST API keys in Retool network tabs

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

- Shared Retool projects revealing REST API tokens
- Sudden REST API quota burn from scripted abuse
- Inability to rotate keys without redeploying clients

## Solution steps

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

2. **Target the real upstream URL**: Point step upstream at https://jsonplaceholder.typicode.com/users/{{query.userId}} 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. **Query from Retool**: Call https://realcomposer.com/v1/workspace/retool-public-app-hide-api-credentials with a restricted rc_live_ client token. Retool never sends upstream secrets.

```
// REST resource or JS query
const rows = await fetch('https://realcomposer.com/v1/workspace/retool-public-app-hide-api-credentials', {
  headers: { Authorization: 'Bearer rc_live_token' }
}).then(r => r.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": "Retool Public App Hide REST API Credentials",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "upstream",
      "upstreamUrlTemplate": "https://jsonplaceholder.typicode.com/users/{{query.userId}}",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.API_BEARER_TOKEN}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "userId",
        "sourcePath": "id",
        "type": "number",
        "sourceStep": "upstream"
      },
      {
        "targetPath": "name",
        "sourcePath": "name",
        "type": "string",
        "sourceStep": "upstream"
      },
      {
        "targetPath": "email",
        "sourcePath": "email",
        "type": "string",
        "sourceStep": "upstream"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/retool-public-app-hide-api-credentials" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_retool-p",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "retool-public-app-hide-api-credentials"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "userId": "sample",
  "name": "sample",
  "email": "sample"
}
```

## FAQ

### Can Retool call REST API without holding the production key?

Log request IDs for retool-public-app-hide-api-credentials, not raw REST API payloads, because upstream bodies may include PII.

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

retool-public-app-hide-api-credentials forwards client JSON to POST upstreams unchanged; secrets interpolate only in URLs and header templates.

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

Upstream steps in retool-public-app-hide-api-credentials honor timeoutMs and optional fallback JSON without leaking secrets.
