{
  "openapi": "3.1.0",
  "info": {
    "title": "TRAK Asset Pre-Start notification webhook",
    "description": "TRAK delivers to the HTTPS endpoint configured on the notification route. The route selects exactly one method for each delivery. The receiver chooses its own URL.",
    "version": "1.0.0"
  },
  "webhooks": {
    "assetPreStartLifecycleNotification": {
      "post": {
        "operationId": "postAssetPreStartNotification",
        "summary": "Receive a notification with POST",
        "parameters": [
          {
            "name": "X-TRAK-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "asset_prestart_lifecycle_notification"
            },
            "description": "Event family"
          },
          {
            "name": "X-TRAK-Notification-UUID",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Logical notification identifier, shared by attempts"
          },
          {
            "name": "X-TRAK-Delivery-Attempt-UUID",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Identifier of this attempt"
          },
          {
            "name": "X-TRAK-Signature",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^hmac-sha256-v1=[0-9a-f]{64}$"
            },
            "description": "Default header name for optional HMAC-SHA256 over the exact transmitted JSON bytes. The route can select another header name."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Notification"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Delivery marked SENT. The response body is not used for acknowledgement."
          },
          "default": {
            "description": "Delivery marked FAILED. Failed attempts record a retry deadline."
          }
        }
      },
      "put": {
        "operationId": "putAssetPreStartNotification",
        "summary": "Receive a notification with PUT",
        "parameters": [
          {
            "name": "X-TRAK-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "asset_prestart_lifecycle_notification"
            },
            "description": "Event family"
          },
          {
            "name": "X-TRAK-Notification-UUID",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Logical notification identifier, shared by attempts"
          },
          {
            "name": "X-TRAK-Delivery-Attempt-UUID",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Identifier of this attempt"
          },
          {
            "name": "X-TRAK-Signature",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^hmac-sha256-v1=[0-9a-f]{64}$"
            },
            "description": "Default header name for optional HMAC-SHA256 over the exact transmitted JSON bytes. The route can select another header name."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Notification"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Delivery marked SENT. The response body is not used for acknowledgement."
          },
          "default": {
            "description": "Delivery marked FAILED. Failed attempts record a retry deadline."
          }
        }
      },
      "patch": {
        "operationId": "patchAssetPreStartNotification",
        "summary": "Receive a notification with PATCH",
        "parameters": [
          {
            "name": "X-TRAK-Event",
            "in": "header",
            "required": true,
            "schema": {
              "const": "asset_prestart_lifecycle_notification"
            },
            "description": "Event family"
          },
          {
            "name": "X-TRAK-Notification-UUID",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Logical notification identifier, shared by attempts"
          },
          {
            "name": "X-TRAK-Delivery-Attempt-UUID",
            "in": "header",
            "required": true,
            "schema": {
              "type": "string",
              "format": "uuid"
            },
            "description": "Identifier of this attempt"
          },
          {
            "name": "X-TRAK-Signature",
            "in": "header",
            "required": false,
            "schema": {
              "type": "string",
              "pattern": "^hmac-sha256-v1=[0-9a-f]{64}$"
            },
            "description": "Default header name for optional HMAC-SHA256 over the exact transmitted JSON bytes. The route can select another header name."
          }
        ],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "$ref": "#/components/schemas/Notification"
              }
            }
          }
        },
        "responses": {
          "2XX": {
            "description": "Delivery marked SENT. The response body is not used for acknowledgement."
          },
          "default": {
            "description": "Delivery marked FAILED. Failed attempts record a retry deadline."
          }
        }
      }
    }
  },
  "components": {
    "schemas": {
      "Notification": {
        "type": "object",
        "properties": {
          "event": {
            "const": "asset_prestart_lifecycle_notification"
          },
          "schema_version": {
            "const": 1
          },
          "sent_at_utc": {
            "type": "string",
            "pattern": "^\\d{4}-\\d{2}-\\d{2} \\d{2}:\\d{2}:\\d{2}$",
            "description": "UTC without a timezone suffix."
          },
          "company_id": {
            "type": "integer"
          },
          "notification": {
            "type": "object",
            "properties": {
              "id": {
                "type": "integer"
              },
              "uuid": {
                "type": "string",
                "format": "uuid"
              },
              "type_code": {
                "type": "string"
              },
              "severity_code": {
                "type": "string"
              },
              "message_text": {
                "type": "string"
              },
              "state_code": {
                "type": "string"
              }
            },
            "required": [
              "id",
              "uuid",
              "type_code",
              "severity_code",
              "message_text",
              "state_code"
            ]
          },
          "subject": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string"
              },
              "id": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "asset_id": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "case_id": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "finding_id": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "defect_id": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "work_order_id": {
                "type": [
                  "integer",
                  "null"
                ]
              },
              "restriction_id": {
                "type": [
                  "integer",
                  "null"
                ]
              }
            },
            "required": [
              "type",
              "id",
              "asset_id",
              "case_id",
              "finding_id",
              "defect_id",
              "work_order_id",
              "restriction_id"
            ]
          },
          "delivery": {
            "type": "object",
            "properties": {
              "attempt_id": {
                "type": "integer"
              },
              "attempt_uuid": {
                "type": "string",
                "format": "uuid"
              },
              "attempt_number": {
                "type": "integer"
              },
              "channel_code": {
                "const": "WEBHOOK"
              },
              "recipient_role_code": {
                "type": "string"
              },
              "recipient_expression": {
                "type": "string"
              },
              "route_label": {
                "type": "string"
              },
              "signature_algorithm": {
                "enum": [
                  "",
                  "hmac-sha256-v1"
                ]
              }
            },
            "required": [
              "attempt_id",
              "attempt_uuid",
              "attempt_number",
              "channel_code",
              "recipient_role_code",
              "recipient_expression",
              "route_label",
              "signature_algorithm"
            ]
          }
        },
        "required": [
          "event",
          "schema_version",
          "sent_at_utc",
          "company_id",
          "notification",
          "subject",
          "delivery"
        ]
      }
    }
  }
}
