Routines

A routine is a way to automate recurring tasks in the OpenDrives Ecosystem.

Basic Operations

Basic operations of Create, Read, Update, and Destroy are available

List all Routines

Call to /routine to get all routines

Request Object

+ URL
  /api/v2/routine/

+ Method
  GET

+ Headers
  Content-Type: application/json
  token: ThisIsNotARealTokenGenerateYourOwnToken

+ Body
  {}

Response Object

Sending this should get you back a valid response, an array of each routine in the system.

+ Headers
  X-Powered-By: OpenDrives
  Access-Control-Allow-Origin: *
  Content-Type: application/json; charset=utf-8

+ Body
  [{
      "id": "36608e21-4b6b-4cf6-87df-257d7fc64beb",
      "updatedAt": "2020-08-12T17:00:07.512Z",
      "createdAt": "2020-08-12T16:55:31.877Z",
      "hostid": "811fea00",
      "name": "BwCtrlOff",
      "enabled": true,
      "data": {
        "jobs": [
          "ce5ab11f-5b54-470f-af52-bbfeb8c60fb5"
        ],
        "triggers": [
          "94227782-0662-4ae1-bcc1-57d5766b681c"
        ]
      }
    },
    {
      "id": "81412803-1836-4f37-a250-7c0b4c1bb737",
      "updatedAt": "2020-08-12T17:36:47.403Z",
      "createdAt": "2020-08-12T16:55:00.216Z",
      "hostid": "811fea00",
      "name": "BWCtrlOn",
      "enabled": true,
      "data": {
        "jobs": [
          "b2ebdf7e-a3c9-42ab-9fab-e56dbc827085"
        ],
        "triggers": [
          "83d63c7b-a970-42aa-996d-86e75c20cda4",
          "900a031e-bea9-4e84-987b-1abb1ddb4c1b"
        ]
      }
    }
  ]

Get a specific Routine

Like many other places in the API, we have a route for if you only want info on one specific routine

Request Object

+ URL
  /api/v2/routine/$ROUTINE_ID/details

+ Method
  GET

+ Parameters
  routine id (string, required, URL param) - the id of the routine you'd like back

+ Headers
  Content-Type: application/json
  token: ThisIsNotARealTokenGenerateYourOwnToken

+ Body
  {}

Response Object

Sending this should get you back a valid response, an array of each routine in the system.

+ Headers
  X-Powered-By: OpenDrives
  Access-Control-Allow-Origin: *
  Content-Type: application/json; charset=utf-8

+ Body
  [
    {
      "id": "36608e21-4b6b-4cf6-87df-257d7fc64beb",
      "updatedAt": "2020-08-12T17:00:07.512Z",
      "createdAt": "2020-08-12T16:55:31.877Z",
      "hostid": "811fea00",
      "name": "BwCtrlOff",
      "enabled": true,
      "data": {
        "jobs": [
          "ce5ab11f-5b54-470f-af52-bbfeb8c60fb5"
        ],
        "triggers": [
          "94227782-0662-4ae1-bcc1-57d5766b681c"
        ]
      }
    }
  ]

Create a new Routine

Creating a Routine through the API looks messy, but it’s pretty easy.

Request Object

+ URL
  /api/v2/job/create

+ Method
  POST

+ Parameters
  name (string, required, BODY) - the name you'd like to give to the job
  enabled (boolean, required, BODY) - if a job should be utilized or not
  data (JSON object, required, BODY) - the data of this routine, containing jobs and triggers

+ Headers
  Content-Type: application/json
  token: ThisIsNotARealTokenGenerateYourOwnToken

+ Body
  {
    "name": "myFirstRoutine",
    "enabled": "true",
    "data": {
        "triggers": ["dc47cc24-5abb-4f9a-b806-ba0b4b1b7e1e"],
        "jobs": ["01d23a39-2149-4a02-ad51-853076936d7a"]
    }
  }

Response Object

Sending this should get you back a valid response, an echo of your new routine

+ Headers
  X-Powered-By: OpenDrives
  Access-Control-Allow-Origin: *
  Content-Type: application/json; charset=utf-8

+ Body
  [{
    "id": "18fcc069-c732-4fc5-8091-0645b8c598b1",
    "updatedAt": "2020-08-17T17:05:53.053Z",
    "createdAt": "2020-08-17T17:05:53.053Z",
    "hostid": "811fea00",
    "name": "myFirstRoutine",
    "enabled": true,
    "data": {
      "jobs": [
        "01d23a39-2149-4a02-ad51-853076936d7a"
      ],
      "triggers": [
        "dc47cc24-5abb-4f9a-b806-ba0b4b1b7e1e"
      ]
    }
  }]

Update a Routine

To update a routine, simply call the route with the routine’s ID and updated fields

Request Object

+ URL
  /api/v2/routine/$ROUTINE_ID/update

+ Method
  POST

+ Parameters
  routine id (string, required, URL params) - the id of the routine to update
  name (string, optional, BODY) - the name you'd like to give to the routine
  enabled (boolean, optional, BODY) - if a routine should be utilized or not
  data (JSON object, required, BODY) - the data of this routine, containing jobs and triggers

+ Headers
  Content-Type: application/json
  token: ThisIsNotARealTokenGenerateYourOwnToken

+ Body
  {
    "name": "my Awesome Routine"
  }

Response Object

Sending this should get you back a valid response, an echo of your updated job

+ Headers
  X-Powered-By: OpenDrives
  Access-Control-Allow-Origin: *
  Content-Type: application/json; charset=utf-8

+ Body
  {
    "id": "18fcc069-c732-4fc5-8091-0645b8c598b1",
    "updatedAt": "2020-08-17T17:11:19.335Z",
    "createdAt": "2020-08-17T17:05:53.053Z",
    "hostid": "811fea00",
    "name": "my Awesome Routine",
    "enabled": true,
    "data": {
      "jobs": [
        "01d23a39-2149-4a02-ad51-853076936d7a"
      ],
      "triggers": [
        "dc47cc24-5abb-4f9a-b806-ba0b4b1b7e1e"
      ]
    }
  }

Destroy a Routine

To destroy a routine, call the route with the routine’s ID

Request Object

+ URL
  /api/v2/routine/$ROUTINE_ID/destroy

+ Method
  POST

+ Parameters
  routine id (string, required, URL params) - the id of the routine to destroy

+ Headers
  Content-Type: application/json
  token: ThisIsNotARealTokenGenerateYourOwnToken

+ Body
  {}

Response Object

Sending this should get you back a valid response, and the ID of the routine we destroyed

+ Headers
  X-Powered-By: OpenDrives
  Access-Control-Allow-Origin: *
  Content-Type: application/json; charset=utf-8

+ Body
  [
    "18fcc069-c732-4fc5-8091-0645b8c598b1"
  ]

Logs

All routines generate an unique log whenever they are run.

List or view Routine logs

Call to /routine/$ROUTINE_ID/log to get all routine logs, or, call /routine/$ROUTINE_ID/log/$LOG_ID for a single log

Request Object

+ URL
  /api/v2/routine/$ROUTINE_ID/log/$LOG_ID

+ Method
  POST

+ Parameters
  routine id (string, required, URL params) - the id of the routine to view logs
  log id (string, optional, URL params) - the id of the log to view
  limit (number, optional, BODY) - the maxiumum number of logs to get from the DB
  startMoment (string of zulu time, optional, BODY) - the moment to use as the start time for getting jobs from the db. In this format "2020-08-17T16:05:24.683Z"
  endMoment (string of zulu time, optional, BODY) - the moment to use as the stop time for getting jobs from the db. In this format "2020-08-17T16:05:24.683Z"

+ Headers
  Content-Type: application/json
  token: ThisIsNotARealTokenGenerateYourOwnToken

+ Body
  {}

Response Object

Sending this should get you back a valid response, an array of each routine log in the system matching your query.

+ Headers
  X-Powered-By: OpenDrives
  Access-Control-Allow-Origin: *
  Content-Type: application/json; charset=utf-8

+ Body
  [{
      "id": "4430efbd-f810-4233-8e52-80a81279a57b",
      "pid": 15762,
      "routine_id": "0bbdaa56-8571-47e2-8d3d-4834c031c735",
      "updatedAt": "2020-08-17T04:00:30.281Z",
      "createdAt": "2020-08-17T04:00:21.642Z",
      "hostid": "811fea00",
      "status": "ready",
      "log": {
        "1597636821654": "Rtn [0bbdaa56: TestTrix ] recieves info on Trigger Log ID from Trigger dc47cc24-5abb-4f9a-b806-ba0b4b1b7e1e",
        "1597636821659": "Rtn [0bbdaa56: TestTrix ] recieves info on Job Log ID from Job 94b9f4c8-6aed-4508-be09-8e92ba2632f6",
        "1597636821686": "Rtn [0bbdaa56: TestTrix ] recieves info on Trigger Log ID from Trigger cf75eca5-118e-4965-a911-64dbd846f247"
      }
    },
    {
      "id": "b694af15-ebf2-407b-ae61-866075c151e5",
      "pid": 15762,
      "routine_id": "0bbdaa56-8571-47e2-8d3d-4834c031c735",
      "updatedAt": "2020-08-17T04:00:20.280Z",
      "createdAt": "2020-08-16T04:00:05.253Z",
      "hostid": "811fea00",
      "status": "success",
      "log": {
        "1597550405260": "Rtn [0bbdaa56: TestTrix ] recieves info on Trigger Log ID from Trigger dc47cc24-5abb-4f9a-b806-ba0b4b1b7e1e",
        "1597550405261": "Rtn [0bbdaa56: TestTrix ] recieves info on Job Log ID from Job 94b9f4c8-6aed-4508-be09-8e92ba2632f6",
        "1597550405292": "Rtn [0bbdaa56: TestTrix ] recieves info on Trigger Log ID from Trigger cf75eca5-118e-4965-a911-64dbd846f247",
        "1597636808130": "Rtn [0bbdaa56: TestTrix ] Trigger [It is 9pm] has been triggered!",
        "1597636808134": "Job run states: [false - ready]",
        "1597636808135": "Rtn [0bbdaa56: TestTrix ] runs Job [Now 9pm] ",
        "1597636813768": "Rtn [0bbdaa56: TestTrix ] recieves Job finished! 94b9f4c8-6aed-4508-be09-8e92ba2632f6",
        "1597636813769": "Job run states: [true - success]",
        "1597636813772": "Rtn [0bbdaa56: TestTrix ] has finished"
      }
    }
  ]