Custom Browser API
Overview
The FPS platform provides a global browser API for custom HTML components. This API handles authentication automatically using secure HTTP-only cookies, eliminating the need to manage session tokens in your code.
Available APIs
window.callEndpoint()
window.callEndpoint()Makes authenticated API requests to your backend endpoints.
Signature:
window.callEndpoint(endpoint, method, body, params, callback, options)Parameters:
endpoint(string) - The API endpoint name (e.g.,'getFeatures','updateUser')method(string) - HTTP method:'GET','POST','PUT','DELETE'body(object) - Request body for POST/PUT/DELETE requests (ignored for GET)params(object) - Query parameters (e.g.,{ page: 1, limit: 10 })callback(function) - Callback function:(status, data, settings, fullResponse) => {}status(string) -'ok'or'error'data(array|object) - Response datasettings(object) - View settings (optional)fullResponse(object) - Full API response
options(object) - Optional settings (e.g.,{ signal: abortController.signal })
Returns: Nothing (results passed to callback)
Examples
Basic GET Request
POST Request with Body
Update Request
Search with Filters
With Abort Controller
Authentication
All requests are automatically authenticated. The session token is stored in a secure HTTP-only cookie and is automatically included with every request. You don't need to:
Store tokens in localStorage/sessionStorage
Manually add authorization headers
Handle token refresh
The platform manages authentication for you.
Error Handling
Migration Guide
If you have existing code using fetch() directly, you need to migrate to window.callEndpoint() for authentication to work properly.
Before (Old Code - Will Not Work)
After (New Code - Works)
File Upload with FormData
Important for file uploads:
Use FormData instead of plain object for body parameter
The browser automatically sets correct Content-Type with boundary for multipart/form-data
Field name 'file' must match your backend FileUpload data structure field
You can append multiple files or additional text fields to FormData
AI Migration Prompt
Use this prompt with an AI assistant to automatically convert your old code:
PROMPT:
Example Conversion:
Input:
AI Output:
Best Practices
Always check status in the callback before using data
Don't store tokens - authentication is handled automatically
Use meaningful endpoint names that match your backend structure
Handle errors gracefully with user-friendly messages
Use AbortController for long-running requests that can be cancelled
Test in browser console before integrating into your component
Troubleshooting
Request not authenticated
Make sure you're logged in to the platform
Check that the user has valid session (check browser cookies for
token_new_*)
Endpoint not found
Verify the endpoint name matches your backend configuration
Check for typos in the endpoint string
Data not received
Verify the callback function is being called
Check browser console for errors
Inspect network tab in DevTools to see the actual request/response
Additional Resources
See
SESSION_AUTH.mdfor details on session managementCheck your backend API documentation for available endpoints
Use browser DevTools Network tab to debug requests
Last updated
Was this helpful?