API Documentation
The Bregway API is a RESTful interface built on Next.js API routes that connects to each tenant's Salesforce org. All endpoints require authentication via the Salesforce OAuth session cookie.
Base URL
https://app.bregway.com/apiFor tenant-specific portals: https://[client].app.bregway.com/api
Authentication
All API requests require a valid session. Authenticate via the OAuth flow at /api/auth/login. The session is stored in an encrypted HTTP-only cookie (bregway_session) and automatically included in browser requests. Server-side requests should forward the cookie header.
Authentication
Bregway uses Salesforce OAuth 2.0 for authentication. Tokens are stored in encrypted HTTP-only cookies and never exposed to the browser.
Initiates Salesforce OAuth flow. Redirects the user to SF login page.
Parameters
returnTostringURL to redirect after successful login
Handles OAuth callback from Salesforce. Exchanges code for tokens, creates encrypted session cookie.
Returns current session info (user name, org ID, role). Returns 401 if no valid session.
Response Example
{
"user": "Laurent Detroyat",
"email": "laurent@detroyat-aviation.com",
"orgId": "00D5g000004XXXX",
"role": "Broker_Admin",
"instanceUrl": "https://detroyat.my.salesforce.com"
}Clears session cookie and revokes SF token. Redirects to login page.
Opportunities
Charter trip opportunities — the core object. Each opportunity represents a client trip request moving through your pipeline.
List all opportunities for the current user. Supports filtering by stage, date range, and search.
Parameters
stagestringFilter by pipeline stage (e.g., "Qualification", "Quote Sent")
searchstringSearch opportunity name or account name
limitnumberResults per page (default: 50)
offsetnumberPagination offset
Response Example
{
"records": [
{
"Id": "006...",
"Name": "LHR-NCE Roundtrip - Jet Group",
"StageName": "Quote Sent",
"Amount": 42000,
"CloseDate": "2026-03-15",
"Account": { "Name": "Jet Group International" }
}
],
"totalSize": 127
}Get full opportunity detail including related quotes, trip legs, and activity history.
Response Example
{
"Id": "006...",
"Name": "LHR-NCE Roundtrip - Jet Group",
"StageName": "Quote Sent",
"Amount": 42000,
"Trip_Legs__r": [...],
"Quotes__r": [...],
"Activities": [...]
}Update opportunity fields (stage, amount, close date, etc.).
Parameters
StageNamestringNew pipeline stage
AmountnumberUpdated deal amount
CloseDatestringExpected close date (YYYY-MM-DD)
Quotes
Manage charter quotes linked to opportunities. Each quote contains operator pricing, margin calculations, and client-facing amounts.
List all quotes for an opportunity.
Response Example
{
"records": [
{
"Id": "a0B...",
"Operator__c": "Silver Cloud Air",
"Aircraft_Type__c": "Citation CJ3",
"Operator_Price__c": 18900,
"Client_Price__c": 20800,
"Margin_Percent__c": 10.05,
"Status__c": "Sent",
"Selected__c": true
}
]
}Create a new quote on an opportunity.
Parameters
Opportunity__cstringrequiredOpportunity ID
Operator__cstringrequiredOperator account name
Aircraft_Type__cstringrequiredAircraft type
Operator_Price__cnumberrequiredPrice from operator (cost)
Client_Price__cnumberrequiredPrice to client (sell)
Update a quote (toggle selection, change pricing, update status).
Delete a quote from an opportunity.
Trip Legs
Individual flight segments within a trip. Multi-leg itineraries are represented as ordered trip legs under an opportunity.
List all trip legs for an opportunity, ordered by sequence.
Response Example
{
"records": [
{
"Id": "a0C...",
"Departure_Airport__c": "EGLF",
"Arrival_Airport__c": "LFMN",
"Departure_Date__c": "2026-03-20T09:00:00Z",
"Passengers__c": 6,
"Sequence__c": 1
}
]
}Add a trip leg to an opportunity.
Parameters
Opportunity__cstringrequiredOpportunity ID
Departure_Airport__cstringrequiredICAO code
Arrival_Airport__cstringrequiredICAO code
Departure_Date__cstringrequiredISO 8601 datetime
Passengers__cnumberrequiredPassenger count
Operator CRM
Manage your operator network — fleet data, deal history, communications, and performance metrics.
List operator accounts with fleet summary and performance stats.
Get full fleet listing for an operator.
Response Example
{
"records": [
{
"Registration__c": "G-DLAA",
"Aircraft_Type__c": "Global 6000",
"Pax_Capacity__c": 13,
"Base_Airport__c": "EGLF",
"Status__c": "Available"
}
]
}List all deals (quotes/opportunities) with this operator.
Communication history with the operator (emails, calls, notes).
Dashboard
Aggregated analytics and pipeline metrics for the broker dashboard.
Returns pipeline summary: active opps, pending quotes, revenue this month, win rate.
Response Example
{
"activeOpportunities": 23,
"pendingQuotes": 8,
"revenueThisMonth": 245000,
"revenueTarget": 300000,
"winRate": 0.34,
"avgDealCycle": 12
}Pipeline breakdown by stage with amounts.
Error Handling
All errors return a consistent JSON structure with an HTTP status code, error type, and human-readable message.
{
"error": "UNAUTHORIZED",
"message": "Session expired. Please re-authenticate.",
"status": 401
}400BAD_REQUESTInvalid parameters or missing required fields
401UNAUTHORIZEDNo valid session or expired token
403FORBIDDENInsufficient permissions for this action
404NOT_FOUNDResource does not exist or is not accessible
429RATE_LIMITEDToo many requests — retry after backoff
500INTERNAL_ERRORServer error — Salesforce API failure or unexpected exception
Rate Limits
Rate limits are applied per-user, per-tenant to protect Salesforce API limits. Limits scale with your plan tier.
Tier
Requests/min
Requests/day
Burst
When rate limited, the API returns 429 with a Retry-After header indicating seconds to wait.