# Contentful management api secure proxy retool

> Contentful CMA writes from Retool via edge with scoped tokens. For "contentful management api secure proxy retool", store CONTENTFUL_MANAGEMENT_TOKEN in Secret Vault, call https://api.contentful.com/spaces/{{query.spaceId}}/entries from a Worker, and let Retool hit only https://realcomposer.com/v1/workspace/contentful-cma-proxy-retool with an rc_live_ client token.

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

## Problem: Why Retool leaks Contentful credentials

Attackers routinely extract Contentful secrets from Retool builds. Direct browser calls also expose internal error payloads with hostnames.

- Production Contentful keys copied from Retool bundles
- Compliance violations after credential leaks
- Attackers replaying vault-grade scopes from a laptop

## Solution steps

1. **Bind vault keys to the Worker**: Add CONTENTFUL_MANAGEMENT_TOKEN to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Configure upstream steps and output mapping**: Use GET against https://api.contentful.com/spaces/{{query.spaceId}}/entries. Allowed origins on the client token should match 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**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
// REST resource or JS query
const rows = await fetch('https://realcomposer.com/v1/workspace/contentful-cma-proxy-retool', {
  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": "Contentful management api secure proxy retool",
  "method": "GET",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "contentful",
      "upstreamUrlTemplate": "https://api.contentful.com/spaces/{{query.spaceId}}/entries",
      "httpMethod": "GET",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.CONTENTFUL_MANAGEMENT_TOKEN}}"
      },
      "timeoutMs": 3000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "entryId",
        "sourcePath": "items.0.sys.id",
        "type": "string",
        "sourceStep": "contentful"
      },
      {
        "targetPath": "title",
        "sourcePath": "items.0.fields.title",
        "type": "string",
        "sourceStep": "contentful"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X GET "https://realcomposer.com/v1/workspace/contentful-cma-proxy-retool" \
  -H "Authorization: Bearer rc_live_client_token"
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_contentf",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "contentful-cma-proxy-retool"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

```json
{
  "entryId": "sample",
  "title": "sample"
}
```

## FAQ

### Can Retool call Contentful without holding the production key?

Point Retool at /recipes/contentful-cma-proxy-retool edge URL. RealComposer answers OPTIONS with Access-Control headers for allowed origins.

### Does POST traffic get cached?

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

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

Allowed origins on the contentful-cma-proxy-retool client token restrict which domains may call the edge URL.
