# Call Notion API from Mobile App without Token Leakage

> Never place NOTION_API_KEY inside Mobile App (iOS & Android) source. RealComposer injects them when calling https://api.notion.com/v1/databases/{{query.databaseId}}/query, so browsers see only a client token.

- Canonical page: https://realcomposer.com/recipes/notion-api-mobile-proxy
- Client platform: Mobile App (iOS & Android)
- Upstream services: Notion
- Category: Security & Secret Vault
- JSON version: https://realcomposer.com/recipes/notion-api-mobile-proxy.json
- Install in RealComposer (free plan, pre-fills this pipeline): https://realcomposer.com/dashboard/pipelines/new?recipe=notion-api-mobile-proxy&via=agent

## Problem: Notion keys in Mobile App (iOS & Android) network tabs

Mobile App (iOS & Android) ships code or scripts to end-user devices. Any Notion bearer token in those bundles can be copied from DevTools, proxies, or repackaged apps.

- Shared Mobile App (iOS & Android) projects revealing Notion tokens
- Sudden Notion quota burn from scripted abuse
- Inability to rotate keys without redeploying clients

## Solution steps

1. **Add vault secrets for this pipeline**: Add NOTION_API_KEY to RealComposer Secret Vault. Values decrypt only inside the Cloudflare Worker that calls the upstream.

2. **Set headers, mapping, and cache TTL**: Configure headersTemplate to inject vault secrets, target https://api.notion.com/v1/databases/{{query.databaseId}}/query, and Add output mapping fields that mirror the JSON contract your screen already expects.

3. **Call from Mobile App (iOS & Android)**: Authorize with Bearer rc_live_ and fetch the mapped JSON contract your UI already expects.

```
let url = URL(string: "https://realcomposer.com/v1/workspace/notion-api-mobile-proxy")!
var request = URLRequest(url: url)
request.addValue("Bearer rc_live_token", forHTTPHeaderField: "Authorization")
```

## 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 Notion API from Mobile App without Token Leakage",
  "method": "POST",
  "cacheTtlSeconds": 0,
  "authMode": "client_token",
  "steps": [
    {
      "stepKey": "notion",
      "upstreamUrlTemplate": "https://api.notion.com/v1/databases/{{query.databaseId}}/query",
      "httpMethod": "POST",
      "headersTemplate": {
        "Authorization": "Bearer {{secrets.NOTION_API_KEY}}",
        "Notion-Version": "2022-06-28",
        "Content-Type": "application/json"
      },
      "timeoutMs": 10000
    }
  ],
  "outputMapping": {
    "version": 1,
    "fields": [
      {
        "targetPath": "pageId",
        "sourcePath": "results.0.id",
        "type": "string",
        "sourceStep": "notion"
      },
      {
        "targetPath": "title",
        "sourcePath": "results.0.properties.Name.title.0.plain_text",
        "type": "string",
        "sourceStep": "notion"
      }
    ]
  }
}
```

## Call the pipeline

```bash
curl -X POST "https://realcomposer.com/v1/workspace/notion-api-mobile-proxy" \
  -H "Authorization: Bearer rc_live_client_token" \
  -H "Content-Type: application/json" \
  -d '{"model":"example"}'
```

## Payload before and after

Raw upstream response:

```json
{
  "requestId": "req_notion-a",
  "upstreamLatencyMs": 142,
  "audit": {
    "region": "edge",
    "trace": "notion-api-mobile-proxy"
  },
  "payload": {
    "id": "sample_id",
    "status": "active",
    "nested": {
      "tags": [
        "demo"
      ],
      "internal": true
    },
    "unused_blob": {
      "foo": "bar",
      "bar": "baz"
    }
  }
}
```

Slimmed RealComposer response:

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

## FAQ

### Is it safe to log Notion responses in Mobile App (iOS & Android)?

Use scoped tokens where the vendor allows them on notion-api-mobile-proxy. Admin keys stay {{secrets.*}} references only.

### When does edge caching apply to this recipe?

notion-api-mobile-proxy 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?

Rotate vault secrets for notion-api-mobile-proxy anytime; clients keep the same rc_live_ token.
