# Retool CORS Error Connecting to External REST API

> Retool browsers cannot call https://jsonplaceholder.typicode.com/users/{{query.userId}} directly because of CORS and hidden credentials. RealComposer responds to OPTIONS and proxies authorized traffic.

- Canonical page: https://realcomposer.com/recipes/fix-retool-cors-error
- Client platform: Retool
- Upstream services: REST API
- Category: Platforms & Frameworks
- JSON version: https://realcomposer.com/recipes/fix-retool-cors-error.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=fix-retool-cors-error&via=agent

## Problem: Retool cannot attach secret headers to REST API

Retool runs in the browser or a sandbox without a secret store. REST API rejects unsigned browser origins or requires server-only headers.

- Proxy hacks that break when vendors tighten CSP
- Zapier-only workarounds adding cost and latency
- Guest users seeing failed network requests in demos

## Solution steps

1. **Add vault secrets for this pipeline**: Store API_BEARER_TOKEN in the vault. Retool never embeds the raw secret, only a revocable rc_live_ client token.

2. **Configure upstream steps and output mapping**: Configure headersTemplate to inject vault secrets, target https://jsonplaceholder.typicode.com/users/{{query.userId}}, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Query from Retool**: Allowed origins on the token should list every Retool host that calls this URL.

```
// REST resource or JS query
const rows = await fetch('https://realcomposer.com/v1/workspace/fix-retool-cors-error', {
  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 CORS Error Connecting to External REST API",
  "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/fix-retool-cors-error" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_fix-reto",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "fix-retool-cors-error"
  },
  "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

### What should Retool store instead of REST API secrets?

Log request IDs for fix-retool-cors-error, not raw REST API payloads, because upstream bodies may include PII.

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

fix-retool-cors-error keeps cache TTL at 0 because it uses POST upstream calls or per-user responses. Add ids to query strings before enabling GET cache.

### How do I rotate upstream credentials?

Upstream steps in fix-retool-cors-error honor timeoutMs and optional fallback JSON without leaking secrets.
