Equetronic API

Introduction

equetronic-api is a repo that handles the API of equetronic and the communication between the EHM device, pusher, live priview, faundDB and syncing to the MySql database. It handles the required Authorization, Endpoints and Request-Response JSON formats for the API.

Authorization

API Token is required to access the api.

In your API ajax request, pass Bearer token in header:

Authorization: 'Bearer [API_TOKEN]'

API token is specific to each user and is found in the backend > users section.

Enpoints

/

Returns api version and alive status

Request Body
None
Response Body
{
    "alive": true,
    "version": "0.1.32"
}

/db

Performs given operation on given collection

Request Body
{
    operation_type: 'create'|'insert'|'read'|'delete'|'insertOrCreate'
    collection_name: String
}
Response Body
Depends on the operation type

/initialize

This api is created to get initial data which is required to hit /api/hrc/send. It should be called only once.

Request Body
{
    horse_rfid: String, // required
    latitude: String, // required
    longitude: String, // required
}
Response Body
{
    "status": "success",
    "data": {
        "training_record_id": 1, 
        "race_course_id": 8,
        "race_course_name": "dubai", 
        "horse_id": 5, 
        "horse_name": "Arabian" 
    }
}

/send

Sends data to pusher and inserts to in the database in eq_ehm_data table.

Request Example
{
    "eq_training_record_id": "7",
    "ehm_id": "234234",
    "horse_rfid": "234234",
    "horse_id": "2",
    "horse_name": "test 2",
    "race_course_id": "1",
    "race_course_name": "Race Course, Dehradun",
    "heart_rate": "2",
    "step_counter": "23",
    "speed": "23",
    "latitude": "18.984738",
    "longitude": "72.820001",
    "battery_voltage": "0.01",
}
Response Example
{
    "status": "success",
    "data": {
        "pusher": {
            "channel_name": "training.h-2-r-1", // pusher channel name
            "event_name": "new.data", // pusher event name
            "data": // data that will be send to pusher 
            {
                "ehm_id": "234234",
                "horse_id": "2",
                "horse_name": "test 2",
                "horse_rfid": "234234",
                "race_course_id": "1",
                "race_course_name": "Race Course, Dehradun",
                "heart_rate": "2",
                "step_counter": "23",
                "speed": "23",
                "latitude": "18.984738",
                "longitude": "72.820001",
                "battery_voltage": "0.01",
                "eq_training_record_id": "7",
                "map_id": "1",
                "map_name": "Race Course, Dehradun"
            }
        },
        "db": // data which is inserted in eq_ehm_data table
        {
            "ehm_id": "234234",
            "horse_id": "2",
            "heart_rate": "2",
            "step_counter": "23",
            "speed": "23",
            "latitude": "18.984738",
            "longitude": "72.820001",
            "battery_voltage": "0.01",
            "map_id": "1",
            "updated_by": 1,
            "updated_at": "2022-02-16 18:37:02",
            "created_by": 1,
            "uuid": "d2716d73-4977-4263-ab36-fff64e2e8036",
            "created_at": "2022-02-16 18:37:02",
            "id": 112
        }
    }
}

/read

Reads and fetch a collection from Fauna DB

Request Example
{
    collection_name: "stage-data-r-234",
    size: 100
}
Response Example
{
  "status": "success",
  "data": {
    "collection_name": "stage-data-r-234",
    "list": [
      {
        "is_initial_input": true,
        "horse_rfid": "99200000037293179",
        "ref": {
          "@ref": {
            "id": "340146785131430473",
            "collection": {
              "@ref": {
                "id": "stage-data-r-234",
                "collection": {
                  "@ref": {
                    "id": "collections"
                  }
                }
              }
            }
          }
        }
      },
      {
        "id": 164259,
        "uuid": "e89c5846-1c84-4908-802d-b50c59102e0b",
        "index": 1,
        "eq_training_record_id": 184,
        "horse_rfid": "99200000037293179",
        "heart_rate": "093",
        "step_counter": "0",
        "speed": "0.0",
        "latitude": "",
        "longitude": "",
        "battery_voltage": "3960",
        "device_time": 1660648107278,
        "device_id": "69794347",
        "parsed_coordinates": {
          "latitude": "",
          "longitude": "",
          "parsed_latitude": null,
          "parsed_longitude": null,
          "dd_latitude": null,
          "dd_longitude": null
        },
        "created_at": "2022-07-30 09:47:11",
        "updated_at": "2022-07-30 09:47:11",
        "extensions": [
          {
            "id": 14497,
            "eq_ehm_data_id": 164259,
            "eq_map_id": 21,
            "index": 1,
            "is_checkpoint": 0,
            "stride": "",
            "created_at": "2022-07-30 09:47:30",
            "updated_at": "2022-07-30 09:47:30"
          }
        ],
        "horse_id": 31,
        "horse_name": "Equetronic",
        "training_center_id": 14,
        "training_center_name": "Lake District Demo",
        "training_record_id": 234,
        "api_timezone": "UTC",
        "api_endpoint_time": 1660648106350,
        "api_endpoint_time_utc": 1660648106350,
        "ref": {
          "@ref": {
            "id": "340146789066736203",
            "collection": {
              "@ref": {
                "id": "stage-data-r-234",
                "collection": {
                  "@ref": {
                    "id": "collections"
                  }
                }
              }
            }
          }
        },
        "current_time": "2023-05-01T05:58:48.702Z",
        "latency_json": {
          "device_time_raw": 1660648107278,
          "api_endpoint_time_raw": 1660648106350,
          "current_time_raw": "2023-05-01T05:58:48.702Z",
          "device_time": "2022-08-16T11:08:27.278Z",
          "api_endpoint_time": "2022-08-16T11:08:26.350Z",
          "current_time": "2023-05-01T05:58:48.702Z",
          "device_time_readable": "2022-08-16 11:08:27",
          "api_endpoint_time_readable": "2022-08-16 11:08:26",
          "current_time_readable": "2023-05-01 05:58:48",
          "device_to_api": -0.93,
          "api_to_app": 22272622.35,
          "overall": 22272621.42
        }
      }
    ]
  }
}

/delete-document

Deletes the given Fauna DB document from a given collection document_id refers to the id of ref object in the Fauna db document

Request Example
{
    "collection_name": "data-r-148",
    document_id: "340146785131430473";
}
Response Example
{
    "status": "success",
    "data": {
        "collection_name": "data-r-148",
        "success_messages": {},
        "errors": {}
    }
}

/delete-collection

Deletes the given Fauna DB collection

Request Example
{
    "collection_name": "data-r-148",
}
Response Example
{
    "status": "success",
    "data": {
        "collection_name": "data-r-148",
        "success_messages": {},
        "errors": {}
    }
}

/pusher

/pusher-and-store

/stream

/live

/pusher-auth

/send-to-pusher