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/api

For 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.

GET/api/auth/login

Initiates Salesforce OAuth flow. Redirects the user to SF login page.

Parameters

returnTostringURL to redirect after successful login
GET/api/auth/callback

Handles OAuth callback from Salesforce. Exchanges code for tokens, creates encrypted session cookie.

GET/api/auth/session

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"
}
GET/api/auth/logout

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.

GET/api/sf/opportunities

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/api/sf/opportunities/:id

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": [...]
}
PATCH/api/sf/opportunities/:id

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.

GET/api/sf/quotes/:oppId

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
    }
  ]
}
POST/api/sf/quotes

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)
PATCH/api/sf/quotes/:id

Update a quote (toggle selection, change pricing, update status).

DELETE/api/sf/quotes/:id

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.

GET/api/sf/triplegs/:oppId

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
    }
  ]
}
POST/api/sf/triplegs

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.

GET/api/sf/operators

List operator accounts with fleet summary and performance stats.

GET/api/sf/operators/:id/fleet

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"
    }
  ]
}
GET/api/sf/operators/:id/deals

List all deals (quotes/opportunities) with this operator.

GET/api/sf/operators/:id/comms

Communication history with the operator (emails, calls, notes).

Dashboard

Aggregated analytics and pipeline metrics for the broker dashboard.

GET/api/sf/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
}
GET/api/sf/dashboard/pipeline

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
Starter
30
5,000
10
Professional
120
25,000
30
Enterprise
300
Unlimited
60
Platform
600
Unlimited
120

When rate limited, the API returns 429 with a Retry-After header indicating seconds to wait.