Skip to content

SAFE Swift API

This article is designed to show you the workflow for SAFE Application API. Below the diagram you will find the high-level steps to work with API.

Refer to our SAFE API reference documentation for more details.

Workflow using swimlane

API Workflow API Workflow

Workflow in steps

Our APIs use the OAuth2.0 Client Credentials workflow. See the steps below:

For /ProcessFatigue

  1. Generate Bearer Token.

    • the <your_client_secret> is URL encoded. You can use urlencoder.org to URL encode the client secret.
    • the <your_client_id>:<your_url_encoded_client_secret> string is base64 encoded
    • the content-type is x-www-form-urlencoded
    • the grant-type is client_credentials
    • the scope is frmsc_fast_safe_api

      Manually encoding?

      Use base64encode.org to encode or decode the string of <Your_ClientID>:<Your_URL_Encoded_ClientSecret>.

      5471E010-DDEE-4C98-FF8F-08DB2245E373:7rg6Gt+hUiobtXI9Jb37z2vtrhw1CEgDkwFZcMbN5Yc=
      
      NTQ3MUUwMTAtRERFRS00Qzk4LUZGOEYtMDhEQjIyNDVFMzczOjdyZzZHdCtoVWlvYnRYSTlKYjM3ejJ2dHJodzFDRWdEa3dGWmNNYk41WWM9
      
      Basic NTQ3MUUwMTAtRERFRS00Qzk4LUZGOEYtMDhEQjIyNDVFMzczOjdyZzZHdCtoVWlvYnRYSTlKYjM3ejJ2dHJodzFDRWdEa3dGWmNNYk41WWM9
      
  2. Use the generated token for Bearer authorization in the /ProcessFatigue endpoint to generate a fatigue scores from the roster data you sent. Ensure:

    • the mandatory fields are filled.
    • the RosterData field is populated in the correct order.

  3. If you get errors instead of fatigue scores, read the error carefully and resolve the payload errors.

  4. If you get expected results, retry sending the request to this endpoint by setting a different scale against PreferredScale property of the payload.

For /ProcessFatigueRisk

  1. Generate Bearer Token.

    • the <your_client_secret> is URL encoded. You can use urlencoder.org to URL encode the client secret.
    • the <your_client_id>:<your_url_encoded_client_secret> string is base64 encoded
    • the content-type is x-www-form-urlencoded
    • the grant-type is client_credentials
    • the scope is frmsc_fast_safe_risk_api

      Manually encoding?

      Use base64encode.org to encode or decode the string of <Your_ClientID>:<Your_URL_Encoded_ClientSecret>.

      5471E010-DDEE-4C98-FF8F-08DB2245E373:7rg6Gt+hUiobtXI9Jb37z2vtrhw1CEgDkwFZcMbN5Yc=
      
      NTQ3MUUwMTAtRERFRS00Qzk4LUZGOEYtMDhEQjIyNDVFMzczOjdyZzZHdCtoVWlvYnRYSTlKYjM3ejJ2dHJodzFDRWdEa3dGWmNNYk41WWM9
      
      Basic NTQ3MUUwMTAtRERFRS00Qzk4LUZGOEYtMDhEQjIyNDVFMzczOjdyZzZHdCtoVWlvYnRYSTlKYjM3ejJ2dHJodzFDRWdEa3dGWmNNYk41WWM9
      
  2. Use the generated token for Bearer authorization in the /ProcessFatigueRisk endpoint to generate a fatigue and risk scores from the roster data you sent. Ensure:

    • the mandatory fields are filled.
    • the RosterData field is populated in the correct order.

  3. If you get errors instead of fatigue and risk scores, read the error carefully and resolve the payload errors.

  4. If you get expected results, retry sending the request to this endpoint by setting a different scale against PreferredScale property of the payload.

Payload

Request payload

Download files

Download an example file for RosterData csv here.

The request payload is the same for both endpoints. See our API reference documentation for more information.

Schema
RosterDatastring Required

See the table below for the format of the data. Note:

  • This property takes comma separated values (csv).
  • The roster data must be in the same order as shown below.
  • You can omit the column titles. In such a case, the order in which the column titles are listed below will be assumed.
  • You can send multiple rows at a time.
  • You can fill in the required columns and delete the others.
  • If you are sending the data to a column that is not required, you must send all columns. The columns without data can be left blank.


ColumnName
(+ required)
Format Description
Reference+ Text A free-text field usually used to indicate a pilot. Use pilot's name or ID.
OnDutyDate+ Date (DD/MM/YYYY) The duty start date.
OnDutyTime+ Time (hh:mm) The duty start time.
StartAirport+ Text The airport at which the duty started. Send ICAO, IATA, or FAA airport codes or a combination of these codes.
OffDutyDate+ Date (DD/MM/YYYY) The duty end date.
OffDutyTime+ Time (hh:mm) The duty end time.
EndAirport+ Text The airport at which the duty ended. Send ICAO, IATA, or FAA airport codes or a combination of these codes.
Sectors Number The number of flights in duty. Default value is 1.
CrewComposition Number Send
  • 2 for 2 Pilots
  • 3 for 3 Pilots
  • 4 for 4 Pilots
  • 9 for Cabin Crew
Default value is 2.
SleepCount Number (0-2) The number of sleeps the pilot or the crew member slept on duty.
SleepOrder Number (1-3) The rank, which the pilot or the crew member slept in. Send
  • 1 for First
  • 2 for Second
  • 3 for Third
SleepClass Number (1-5) Send
  • 1 for Class 1 - Bunk
  • 2 for Class 2 - Cabin seat: 40 degrees or more recline
  • 3 for Class 3 - Flight deck seat
  • 4 for Class 4 - Economy seat: Less than 40 degrees recline
  • 5 for Class 5 - Jump seat
HomeBase+ Text Send ICAO, IATA, or FAA airport codes or a combination of these codes. Default value is Start airport code.
TimeReference+ Number (0-2) The reference time zone. Send
  • 0 for UTC
  • 1 for Base airport timezone
  • 2 for Local timezone
OnPartialAugmentDate Date (DD/MM/YYYY) The time on which the pilot or the crew member started their partial augmentation.
OnPartialAugmentTime Time (hh:mm) The time at which the pilot or the crew member started their partial augmentation.
OffPartialAugmentDate Date (DD/MM/YYYY) The date on which the pilot or the crew member ended their partial augmentation.
OffPartialAugmentTime Time (hh:mm) The time at which the pilot or the crew member ended their partial augmentation.
FirstRestStartDate Date (DD/MM/YYYY) The date on which the pilot or the crew member started their first rest.
FirstRestStartTime Time (hh:mm) The time at which the pilot or the crew member started their first rest.
FirstRestEndDate Date (DD/MM/YYYY) The date on which the pilot or the crew member ended their first rest.
FirstRestEndTime Time (hh:mm) The time at which the pilot or the crew member ended their first rest.
SecondRestStartDate Date (DD/MM/YYYY) The date on which the pilot or the crew member started their second rest.
SecondRestStartTime Time (hh:mm) The time at which the pilot or the crew member started their second rest.
SecondRestEndDate Date (DD/MM/YYYY) The date on which the pilot or the crew member ended their second rest.
SecondRestEndTime Time (hh:mm) The time at which the pilot or the crew member ended their second rest.
SplitShift Number (0-1) Indicates whether the pilot or crew member had rested in between flight. Send
  • 0 for True
  • 1 for False
DutyType Number (1-3) The type of duty. Send
  • 1 for active
  • 2 for active - split shift
  • 3 for standby duty
Fleet Text A free-text field used to indicate fleet message.
Rank Text A free-text field used to indicate a pilot's rank.
Workload Number When the sector count is 0, send
  • 0 for no activity, i.e. doing nothing but not sleeping
  • 10 for average workload on a typical single-sector duty. Equivalent to workload prior to being able to change workload
  • 20 for average workload on a typical four-sector duty
  • 30 for very high workloads
  • 40 for exceptionally high workloads only seen occasionally
  • 50 for extremely high workloads only rarely seen
When the sector count is more than 0, send
  • -50 for half the workload of standard flying this number of sectors
  • 0 for standard duty workloads flying this number of sectors. Equivalent to workload prior to being able to change workload
  • 100 for double the workload of standard flying this number of sectors
CrewPrepTime Number The time taken for crew to prepare. Value indicates minutes. Default value is 60 minutes.
DutyCommuteTime Number The time taken to commute to the duty. Value indicates minutes. Default value is 60 minutes.
CabinCrewSleepPattern Number (0-4) Default value is 0. Send
  • 0 for Normal Long Haul Pattern 1 or 2 sleep periods
  • 1 (ULR Pattern 1 or 2 sleep periods, short service)
  • 2 (ULR Pattern 1 sleep period, 50% cruise phase)
  • 3 (ULR Pattern Main Crew 1 or 2 sleep periods)

SleepDatastring Required

See the table below for the format of the data. Note:

  • If you provide sleep data, SAFE will not predict sleeps but use the sleep data you have provided.
  • If you are providing sleep data, all fields are mandatory.
  • If you want SAFE to predict sleep, pass an empty array.


ColumnName Format Description
ScheduleName string The unique identifier of the pilot or the crew member
SleepStart DateTime (Zulu) as string The date and time when the pilot or the crew member started sleeping. The date and time must be in Zulu format.
SleepEnd DateTime (Zulu) as string The date and time when the pilot or the crew member ended their sleep. The date and time must be in Zulu format.

DateFormatstring Required

The format which is used with the dates present in the roster data. Send only one of the following highlighted value at a time.

  • dmy for DD/MM/YYYY format
  • mdy for MM/DD/YYYY format

PreferredScalestring Required

The type of scale you want to get the results in. The following values are supported for PreferredScale property. Send only one of the following highlighted value at a time.

  • SP for Samn-Perelli scale
  • KSS for Karolinska Sleepiness Scale
  • KP for Karolinska Probability scale
  • VD for Vigilance Degradation scale
  • CRD for Complex Reaction Degradation scale
  • PMR for Percentage Missed Responses scale

Example
{
    "RosterData": "Reference,OnDutyDate,OnDutyTime,StartAirport,OffDutyDate,OffDutyTime,EndAirport,HomeBase,TimeReference\r\nPilot1,12/05/2023,19:45,SNA,13/05/2023,04:07,RSW,SNA,2\r\nPilot1,13/05/2022,00:01,RSW,13/05/2022,20:05,SNA,SNA,2",
    "SleepData": [
        {
        "ScheduleName": "Pilot 1",
        "SleepStart": "2023-01-02T19:57:00Z",
        "SleepEnd": "2023-01-02T20:30:00Z"
        }
    ],
    "DateFormat": "dmy",
    "PreferredScale": "SP"
}

Response payload

See below for an example. See our API reference documentation or Results breakdown for more information.

For Fatigue Scores

{
    "scheduleScores": [
        {
            "schedule": "Pilot1",
            "fatigueScores": [
                5.146,
                5.026,
                4.943,
                4.885,
                4.809,
                4.782,
                4.757,
                4.683,
                4.655,
                4.624,
                ...
            ]
        }
    ],
    "errors": []
}

For Fatigue Risk Scores

{
  "schedule": "Pilot 1",
  "fatigueScores": [
    3.402,
    3.42,
    3.445,
    3.475,
    3.507,
    3.54,
    3.574,
    3.606,
    3.638,
    3.668,
    3.696,
    3.722,
    3.746,
    3.768,
    3.787,
    3.804,
    3.819,
    3.831,
    3.839,
    3.847,
    3.852,
    "..."
  ],
  "riskScores": [
    12.7382,
    16.520624336581236
  ]
}

Results breakdown

Each comma-separated number under fatigueScores property indicates the fatigue score (based on the scale you chose) at 15-minute intervals. The interval list is based on duty start and end times. Compare the score against the description of the scale given in Fatigue and Risk Scales.

Risk scores are part of our proprietary solution, and we will train you to read those scores during the onboarding process. On a high-level, the Risk scores are dependent on the number of duties per each employee. If the roster data had two duties for an employee, there would be 2 risk scores for that employee. You can learn more about Risk Scales in Fatigue and Risk Scales.