# Fix CORS Error in Webflow API Call

> Fix "fix cors error in webflow api call" by pointing Webflow at RealComposer. Vault secrets authenticate https://jsonplaceholder.typicode.com/users/{{query.userId}}; client tokens gate your public URL.

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

## Problem: CORS blocks REST API in Webflow

Low-code Webflow tools expose connector tokens in shared workspaces, so REST API credentials leak to every editor.

- Browser console CORS errors blocking launches
- Editors pasting secrets into reusable components
- Inability to test locally without disabling security

## Solution steps

1. **Store upstream credentials in Secret Vault**: Create API_BEARER_TOKEN vault entries, then bind them to this pipeline step headers with {{secrets.NAME}} placeholders.

2. **Target the real upstream URL**: 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. **Call from Webflow custom code**: Allowed origins on the token should list every Webflow host that calls this URL.

```
fetch('https://realcomposer.com/v1/workspace/fix-cors-error-webflow', {
  headers: { Authorization: 'Bearer rc_live_your_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": "Fix CORS Error in Webflow API Call",
  "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-cors-error-webflow" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_fix-cors",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "fix-cors-error-webflow"
  },
  "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 Webflow call REST API without holding the production key?

Point Webflow at /recipes/fix-cors-error-webflow edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Does POST traffic get cached?

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

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

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