> ## Documentation Index
> Fetch the complete documentation index at: https://docs.telemax.com.au/llms.txt
> Use this file to discover all available pages before exploring further.

# Safety score

> Trip safety score for a legacy vehicle over a date range.

### Overview

Returns trip safety score payload from `ISafetyScoreService` for a **legacy** vehicle id over a date range.

<Note>
  A V2 version of this endpoint is available: [Safety score](/v2/api-reference/get-safety-score-id). New integrations should prefer V2.
</Note>

### Endpoint

`POST /api/GetSafetyScore`

### Query parameters

<ParamField query="vehicleId" type="integer" required>
  Legacy vehicle id.
</ParamField>

<ParamField query="intervalType" type="integer">
  Used only when `start` and `finish` are **omitted**: `1` = instant range (see
  note), `2` = relative to end of local day, `3` = three-day window, `4` = week
  window—**implementation uses `finish - TimeSpan.FromDays(-N)` which adds days
  to `finish`**.
</ParamField>

<ParamField query="start" type="string (datetime)">
  Range start (optional if using `intervalType`).
</ParamField>

<ParamField query="finish" type="string (datetime)">
  Range end (optional if using `intervalType`).
</ParamField>

> ⚠️ **Note:** When `start` and `finish` are omitted, `finish` is derived from “today” in the user’s timezone and `intervalType` selects `start` per the switch in `GetSafetyScoreAsync`. The arithmetic uses `-TimeSpan.FromDays(-k)` (double negative), which **adds** days to `finish` for types 2–4. For `intervalType` `1`, `start` is set to `DateTime.UtcNow`. **Validate ranges** in staging before relying on preset windows.

### Response

**200 OK** — array of trip safety score objects.

| Field       | Type              | Description                        |
| ----------- | ----------------- | ---------------------------------- |
| `startTime` | string (datetime) | Trip start time                    |
| `endTime`   | string (datetime) | Trip end time                      |
| `riskLevel` | string            | `"Low"`, `"Medium"`, or `"High"`   |
| `riskScore` | integer (0–100)   | Numeric risk score; lower is safer |
| `duration`  | integer           | Trip duration in **seconds**       |
| `distance`  | number            | Trip distance in **km**            |

### Error responses

| Status | Meaning                                                                                                           |
| ------ | ----------------------------------------------------------------------------------------------------------------- |
| 404    | Unknown legacy vehicle                                                                                            |
| 401    | Vehicle or user/company not allowed                                                                               |
| 400    | `"Invalid date range specified."` or generic *"An error occurred while attempting to fetch the safety scores..."* |


## OpenAPI

````yaml openapi.yaml POST /api/GetSafetyScore
openapi: 3.1.0
info:
  title: Telemax External API (V1)
  version: '2026-04-14'
  description: >
    Telemax External API — fleet telemetry, vehicle commands, and integrations.


    **Base URL:** `https://api.telemax.com.au`


    **Authentication:** All routes require a `Bearer` JWT unless marked
    `[AllowAnonymous]`.

    Obtain tokens via `/api/Authentication/token/api-key` or
    `/api/Authentication/token/user`.


    **POST-first architecture:** Almost all data endpoints use `POST` with
    query-string parameters.

    The two exceptions using `GET` are `GetDeviceId` and `GET
    /api/devices/{id}/dtc-codes`.


    **API versioning:** All responses will include an `X-API-Version` header
    containing the

    date-based version string (e.g. `2026-04-14`). See the
    [Changelog](/v1/changelog) for

    the deprecation policy and version history.


    For full documentation including error handling, pagination, and known field
    quirks, see [docs.telemax.com.au](https://docs.telemax.com.au).
servers:
  - url: https://api.telemax.com.au
security:
  - BearerAuth: []
paths:
  /api/GetSafetyScore:
    parameters: []
    post:
      summary: Get Safety Scores
      description: Get safety scores for a vehicle on a per-trip basis.
      parameters:
        - name: vehicleId
          in: query
          required: true
          description: Legacy vehicle ID.
          example: 1000
          schema:
            type: integer
        - name: intervalType
          in: query
          required: false
          description: >
            Preset window (used only when `start`/`finish` are omitted). `1` =
            instant range, `2` = relative to end of local day, `3` = three-day
            window, `4` = week window. Note: the implementation uses a
            double-negative offset (`finish - TimeSpan.FromDays(-N)`) which
            **adds** days to `finish` for types 2–4. Validate in staging before
            relying on preset windows.
          schema:
            type: integer
        - name: start
          in: query
          required: false
          description: Range start (ISO 8601 UTC). Optional when using `intervalType`.
          example: '2025-05-01T00:00:00Z'
          schema:
            type: string
        - name: finish
          in: query
          required: false
          description: Range end (ISO 8601 UTC). Optional when using `intervalType`.
          example: '2025-05-02T00:00:00Z'
          schema:
            type: string
        - name: Authorization
          in: header
          required: true
          description: Bearer your_token
          example: Bearer {token}
          schema:
            type: string
      responses:
        '200':
          description: Successful response with array of trip safety score data
          content:
            application/json:
              schema:
                type: array
                items:
                  type: object
                  properties:
                    startTime:
                      type: string
                      format: date-time
                      description: Trip start time (also used as trip ID component)
                      example: '2024-01-15T08:00:00Z'
                    endTime:
                      type: string
                      format: date-time
                      description: Trip end time
                      example: '2024-01-15T08:45:00Z'
                    riskLevel:
                      type: string
                      description: Human-readable risk level
                      example: Medium
                    riskScore:
                      type: integer
                      format: int32
                      minimum: 0
                      maximum: 100
                      description: Risk score (0–100)
                      example: 62
                    duration:
                      type: integer
                      description: Trip duration in seconds
                      example: 2700
                    distance:
                      type: number
                      format: float
                      description: Total distance in kilometers
                      example: 35.75
              example:
                - startTime: '2024-01-15T08:00:00Z'
                  endTime: '2024-01-15T08:45:00Z'
                  riskLevel: Medium
                  riskScore: 62
                  duration: 2700
                  distance: 35.75
                - startTime: '2024-01-16T14:10:00Z'
                  endTime: '2024-01-16T14:50:00Z'
                  riskLevel: Low
                  riskScore: 20
                  duration: 2400
                  distance: 28.9
        '401':
          $ref: '#/components/responses/Unauthorized'
        '403':
          $ref: '#/components/responses/Forbidden'
        '404':
          $ref: '#/components/responses/NotFound'
        '422':
          $ref: '#/components/responses/UnprocessableEntity'
        '429':
          $ref: '#/components/responses/TooManyRequests'
        '500':
          $ref: '#/components/responses/InternalServerError'
components:
  responses:
    Unauthorized:
      description: >
        **401 Unauthorized** — JWT is missing, expired, or malformed.

        The JWT bearer middleware rejects the request before it reaches the
        controller.
      headers:
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            type: AUTHENTICATION
            code: TOKEN_EXPIRED
            description: >-
              The access token has expired. Request a new token using
              /api/authentication/token/user or
              /api/authentication/token/api-key.
            requestId: req_7f3a2b1c
            docUrl: https://docs.telemax.com.au/errors#token-expired
    Forbidden:
      description: >
        **403 Forbidden** — Token is valid but the caller does not have access
        to the requested company or vehicle.

        Tokens issued for one company cannot access resources scoped to a
        different company in the hierarchy.
      headers:
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            type: AUTHORIZATION
            code: COMPANY_ACCESS_DENIED
            description: >-
              Your token does not grant access to company 99. Ensure you are
              using a token issued for this company.
            requestId: req_4a1d9e2f
            docUrl: https://docs.telemax.com.au/errors#company-access-denied
    NotFound:
      description: >
        **404 Not Found** — The requested vehicle ID, company ID, or IMEI does
        not exist or is not accessible.
      headers:
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            type: NOT_FOUND
            code: VEHICLE_NOT_FOUND
            description: Vehicle with ID 9999 was not found.
            requestId: req_2b8c1a5d
            docUrl: https://docs.telemax.com.au/errors#not-found
    UnprocessableEntity:
      description: >
        **422 Unprocessable Entity** — A parameter is present but has an invalid
        format (e.g. negative vehicle ID, malformed ISO 8601 date string).
      headers:
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            type: VALIDATION
            code: INVALID_DATE_FORMAT
            description: >-
              The 'from' parameter '2025-13-45' is not a valid ISO 8601
              date-time string.
            requestId: req_9f3e7c1b
            docUrl: https://docs.telemax.com.au/errors#invalid-parameter
    TooManyRequests:
      description: >
        **429 Too Many Requests** — Rate limit exceeded. Check the Retry-After
        header for the number of seconds to wait before retrying.

        Use exponential backoff: wait Retry-After seconds, then double the
        interval on each subsequent 429.
      headers:
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
        Retry-After:
          $ref: '#/components/headers/Retry-After'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            type: RATE_LIMIT
            code: RATE_LIMIT_EXCEEDED
            description: Too many requests. Wait 30 seconds before retrying.
            requestId: req_6d2f8b4a
            docUrl: https://docs.telemax.com.au/errors#rate-limit
    InternalServerError:
      description: >
        **500 Internal Server Error** — An unexpected error occurred. Include
        the requestId when contacting support.
      headers:
        X-RateLimit-Limit:
          $ref: '#/components/headers/X-RateLimit-Limit'
        X-RateLimit-Remaining:
          $ref: '#/components/headers/X-RateLimit-Remaining'
        X-RateLimit-Reset:
          $ref: '#/components/headers/X-RateLimit-Reset'
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/ApiError'
          example:
            type: SERVER_ERROR
            code: INTERNAL_ERROR
            description: >-
              An unexpected error occurred. Please try again or contact support
              with the requestId.
            requestId: req_1e5a3c7d
            docUrl: https://docs.telemax.com.au/errors#server-error
  headers:
    X-RateLimit-Limit:
      description: Maximum number of requests allowed per minute for this token.
      schema:
        type: integer
        example: 60
    X-RateLimit-Remaining:
      description: Number of requests remaining in the current rate limit window.
      schema:
        type: integer
        example: 47
    X-RateLimit-Reset:
      description: Unix timestamp (seconds) at which the current rate limit window resets.
      schema:
        type: integer
        example: 1746000060
    Retry-After:
      description: Number of seconds to wait before retrying after a 429 response.
      schema:
        type: integer
        example: 30
  schemas:
    ApiError:
      type: object
      description: Standard error response returned by all API endpoints.
      properties:
        type:
          type: string
          description: >-
            Error category (e.g. AUTHENTICATION, AUTHORIZATION, NOT_FOUND,
            VALIDATION, RATE_LIMIT, SERVER_ERROR).
          example: AUTHENTICATION
        code:
          type: string
          description: Machine-readable error code within the category.
          example: TOKEN_EXPIRED
        description:
          type: string
          description: Human-readable explanation of the error and how to resolve it.
          example: The access token has expired. Request a new token.
        requestId:
          type: string
          description: Unique request identifier for support correlation.
          example: req_7f3a2b1c
        docUrl:
          type: string
          format: uri
          description: Link to the relevant error documentation page.
          example: https://docs.telemax.com.au/errors#token-expired
      required:
        - type
        - code
        - description
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT
      description: >
        JWT Bearer token obtained from `POST /api/authentication/token/user` or
        `POST /api/authentication/token/api-key`.


        **Lifetime:** ~24 hours (86,399 seconds). Cache the token and reuse it.
        Re-authenticate 5 minutes before expiry.


        **Scoping:**

        - User tokens are scoped to a single company.

        - API key tokens may restrict access to a vehicle allowlist and/or
        action set (see token claims).


        **No refresh endpoint** — re-authenticate with your credentials when the
        token expires.

````