Skip to content

Commit 55b09de

Browse files
docs: add section on calling external APIs via proxy in custom journey blocks
1 parent aa8aa7f commit 55b09de

1 file changed

Lines changed: 64 additions & 0 deletions

File tree

docs/apps/components/custom-journey-block.md

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,70 @@ Once your App with a custom Journey Block is installed, you can use it in the Jo
151151

152152

153153

154+
## Calling External APIs via Proxy
155+
156+
Custom journey blocks run in the browser. If your block needs to call a third-party API that requires credentials (API keys, OAuth tokens, etc.), **never embed those secrets in your client-side code**. Instead, use the [API Proxy](./api-proxy.md) — it runs server-side and injects credentials on your behalf so they never reach the browser.
157+
158+
### Setup
159+
160+
1. **Add an API Proxy component** to your app in the App Builder (see [API Proxy docs](./api-proxy.md) for full setup).
161+
2. **Install the App SDK** in your journey block project:
162+
163+
```bash
164+
npm install @epilot/app-sdk
165+
```
166+
167+
### Using the proxy in a journey block
168+
169+
Journey blocks receive a `publicToken` via the container props. Pass this token to the `proxy` function to authenticate the request:
170+
171+
```typescript
172+
import { proxy } from '@epilot/app-sdk';
173+
174+
function App(props: AppProps<unknown>) {
175+
useEffect(() => {
176+
if (!props.container.publicToken) return;
177+
178+
proxy('my-api', '/endpoint', {
179+
appId: 'your-app-id',
180+
token: props.container.publicToken,
181+
method: 'POST',
182+
body: { hello: 'world' },
183+
})
184+
.then((response) => response.json())
185+
.then((data) => console.log('Proxy response:', data))
186+
.catch((error) => console.error('Proxy error:', error));
187+
}, [props.container.publicToken]);
188+
189+
return <div>...</div>;
190+
}
191+
```
192+
193+
| Parameter | Description |
194+
| --- | --- |
195+
| `'my-api'` | The proxy name you configured in the App Builder |
196+
| `'/endpoint'` | The path appended to the proxy's target URL |
197+
| `appId` | Your app's ID |
198+
| `token` | The `publicToken` from the journey block container props |
199+
| `method` | HTTP method (`GET`, `POST`, `PUT`, `DELETE`, etc.) |
200+
| `body` | Optional request body (automatically serialized to JSON) |
201+
202+
:::tip
203+
The `publicToken` is only available at runtime when the journey is rendered for an end user. During development, you can test with a hardcoded token — just make sure to remove it before publishing.
204+
:::
205+
206+
### How it works
207+
208+
1. Your journey block calls `proxy()` with the `publicToken`
209+
2. The request is sent to the epilot proxy server (not directly to the third-party API)
210+
3. The proxy resolves the credentials configured in the App Builder (API key, Bearer token, or OAuth 2.0)
211+
4. The proxy forwards the request to the target API with credentials injected server-side
212+
5. The response is returned to your journey block
213+
214+
This means your API keys and secrets are **never exposed** in the journey's client-side bundle or network requests visible to end users.
215+
216+
For full details on authentication types, request signing, and security, see the [API Proxy documentation](./api-proxy.md).
217+
154218
## Useful Resources
155219

156220
### Journey UI Library Concorde (React)

0 commit comments

Comments
 (0)