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
Workflow in steps
Our APIs use the OAuth2.0 Client Credentials workflow. See the steps below:
For /ProcessFatigue
-
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
isx-www-form-urlencoded
- the
grant-type
isclient_credentials
-
the
scope
isfrmsc_fast_safe_api
Manually encoding?
Use base64encode.org to encode or decode the string of
<Your_ClientID>:<Your_URL_Encoded_ClientSecret>
.
- the
-
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.
- If you get errors instead of fatigue scores, read the error carefully and resolve the payload errors.
- 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
-
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
isx-www-form-urlencoded
- the
grant-type
isclient_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>
.
- the
-
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.
- If you get errors instead of fatigue and risk scores, read the error carefully and resolve the payload errors.
- 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
|
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
|
SleepClass | Number (1-5) | Send
|
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
|
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
|
DutyType | Number (1-3) | The type of duty. Send
|
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
|
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
|
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 formatmdy
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 scaleKSS
for Karolinska Sleepiness ScaleKP
for Karolinska Probability scaleVD
for Vigilance Degradation scaleCRD
for Complex Reaction Degradation scalePMR
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.