Back to top

Data Management API

This document describes the APIs using DataManager as a standalone process. If used with other dojot’s components, the endpoints might be changed a bit. Check dojot’s documentation to check all of them.

Import / Export

Before describing the DataManager APIs, we must explain the import and export functionality. When you export data from Dojot, a JSON file is generated for you. That JSON file contains all current templates, devices, flows, remote nodes, and cron jobs in your tenant. You can save this file to import this data later. The import functionality uses this file to regenerate data inside Dojot. However, when you import that file, then the templates, devices, flows, remote nodes, and cron jobs will be created in your tenant. It’s important to know that this operation is DESTRUCTIVE. This means that, if you have templates, devices, flows, remote nodes or cron jobs in your tenant, all of them will be deleted during the import process, before they are generated. So, be careful.

Resource Group

Import

Deletes and imports all data
POST/import

Deletes all templates, devices, flows and remote nodes and creates new ones in your tenant.

Example URI

POST http://localhost:3000/import
Request
HideShow
Headers
Content-Type: application/json; charset=utf-8
Authorization: Bearer JWT
Body
{
  "devices": [
    {
      "id": "9bbd77",
      "label": "device",
      "templates": [
        296
      ],
      "attrs": [
        {
          "id": 673,
          "label": "temp",
          "static_value": "",
          "template_id": "296",
          "type": "dynamic",
          "value_type": "float"
        },
        {
          "id": 674,
          "label": "Name",
          "static_value": "Device",
          "template_id": "296",
          "type": "static",
          "value_type": "string"
        }
      ]
    }
  ],
  "templates": [
    {
      "attrs": [
        {
          "id": 673,
          "label": "temp",
          "metadata": [
            {
              "created": "2019-01-09T11:25:04.119784+00:00",
              "id": 675,
              "label": "meta",
              "static_value": "meta",
              "type": "meta",
              "value_type": "string"
            }
          ],
          "static_value": "",
          "template_id": "296",
          "type": "dynamic",
          "value_type": "float"
        },
        {
          "id": 674,
          "label": "Name",
          "static_value": "Name",
          "template_id": "296",
          "type": "static",
          "value_type": "string"
        }
      ],
      "id": 296,
      "label": "Tempalte"
    }
  ],
  "flowRemoteNodes": [
    {
      "id": "kelvin",
      "image": "dojot/kelvin-example:3.0.0-alpha2"
    },
    {
      "id": "arithmetic-mean",
      "image": "dojot/arithmetic-mean-example:3.0.0-alpha2"
    }
  ],
  "flows": [
    {
      "name": "flow",
      "enabled": true,
      "id": "20c6c697-3d3a-4706-8267-72669a6016de",
      "flow": [
        {
          "id": "8a89221c.f5477",
          "type": "tab",
          "label": "Flow 1"
        },
        {
          "id": "1dfbd338.9b187d",
          "type": "device in",
          "z": "8a89221c.f5477",
          "name": "Device",
          "device_source_id": "device (9bbd77)",
          "status": "false",
          "_device_id": "9bbd77",
          "_device_label": "",
          "_device_type": "",
          "x": 147.5,
          "y": 98,
          "wires": [
            [
              "92f3408b.cb051"
            ]
          ]
        },
        {
          "id": "92f3408b.cb051",
          "type": "http",
          "z": "8a89221c.f5477",
          "name": "",
          "method": "GET",
          "ret": "txt",
          "body": "payload",
          "response": "payload.response",
          "url": "http://ptsv2.com/t/03n2y-1547033185/post",
          "x": 254.5,
          "y": 195,
          "wires": [
            []
          ]
        }
      ],
      "created": 1547033210480,
      "updated": 1547033210480
    }
  ],
  "cronJobs": [
    {
      "jobId": "e909e5c5-c0a7-4d91-a60a-5dbfe17fcdad",
      "spec": {
        "time": "0/5 * * * *",
        "timezone": "America/Sao_Paulo",
        "name": "Keep alive",
        "description": "This job sends a keep alive notification to a device every 5 minutes",
        "broker": {
          "subject": "dojot.device-manager.device",
          "message": {
            "event": "configure",
            "data": {
              "attrs": {
                "message": "keepalive"
              },
              "id": "9bbd77"
            },
            "meta": {
              "service": "admin"
            }
          }
        }
      }
    }
  ]
}
Response  201
HideShow
Headers
Content-Type: application/json; charset=utf-8
Body
{
  "message": "data imported!"
}
Response  400
HideShow
Headers
Content-Type: application/json; charset=utf-8
Body
{
  "message": "error message"
}

Export

Get all data to be exported
GET/export

Return all current templates, devices, flows, remote nodes, and cron jobs in your tenant.

Example URI

GET http://localhost:3000/export
Request
HideShow
Headers
Content-Type: application/json; charset=utf-8
Authorization: Bearer JWT
Response  200
HideShow
Headers
Content-Type: application/json; charset=utf-8
Body
{
  "devices": [
    {
      "id": "b65f24",
      "label": "device",
      "templates": [
        776
      ],
      "attrs": [
        {
          "id": 2181,
          "label": "temp",
          "metadata": [
            {
              "created": "2019-01-11T16:49:07.960939+00:00",
              "id": 2183,
              "label": "meta",
              "static_value": "meta",
              "type": "meta",
              "updated": null,
              "value_type": "string"
            }
          ],
          "static_value": "",
          "template_id": "776",
          "type": "dynamic",
          "value_type": "float"
        },
        {
          "id": 2182,
          "label": "Name",
          "static_value": "Device",
          "template_id": "776",
          "type": "static",
          "value_type": "string"
        }
      ]
    }
  ],
  "templates": [
    {
      "attrs": [
        {
          "id": 2181,
          "label": "temp",
          "metadata": [
            {
              "created": "2019-01-11T16:49:07.960939+00:00",
              "id": 2183,
              "label": "meta",
              "static_value": "meta",
              "type": "meta",
              "updated": null,
              "value_type": "string"
            }
          ],
          "static_value": "",
          "template_id": "776",
          "type": "dynamic",
          "value_type": "float"
        },
        {
          "id": 2182,
          "label": "Name",
          "static_value": "Name",
          "template_id": "776",
          "type": "static",
          "value_type": "string"
        }
      ],
      "id": 776,
      "label": "Tempalte"
    }
  ],
  "flowRemoteNodes": [
    {
      "id": "kelvin",
      "image": "dojot/kelvin-example:3.0.0-alpha2"
    },
    {
      "id": "arithmetic-mean",
      "image": "dojot/arithmetic-mean-example:3.0.0-alpha2"
    }
  ],
  "flows": [
    {
      "name": "flow",
      "enabled": true,
      "id": "18f97f09-cec9-47ec-936d-f4389173f2c0",
      "flow": [
        {
          "id": "8a89221c.f5477",
          "type": "tab",
          "label": "Flow 1"
        },
        {
          "id": "1dfbd338.9b187d",
          "type": "device in",
          "z": "8a89221c.f5477",
          "name": "Device",
          "device_source_id": "Device (b65f24)",
          "status": "false",
          "_device_id": "b65f24",
          "_device_label": "",
          "_device_type": "",
          "x": 147.5,
          "y": 98,
          "wires": [
            [
              "92f3408b.cb051"
            ]
          ]
        },
        {
          "id": "92f3408b.cb051",
          "type": "http",
          "z": "8a89221c.f5477",
          "name": "",
          "method": "GET",
          "ret": "txt",
          "body": "payload",
          "response": "payload.response",
          "url": "http://ptsv2.com/t/03n2y-1547033185/post",
          "x": 254.5,
          "y": 195,
          "wires": [
            []
          ]
        }
      ],
      "created": 1547225348029,
      "updated": 1547225348029
    }
  ],
  "cronJobs": [
    {
      "jobId": "e909e5c5-c0a7-4d91-a60a-5dbfe17fcdad",
      "spec": {
        "time": "0/5 * * * *",
        "timezone": "America/Sao_Paulo",
        "name": "Keep alive",
        "description": "This job sends a keep alive notification to a device every 5 minutes",
        "broker": {
          "subject": "dojot.device-manager.device",
          "message": {
            "event": "configure",
            "data": {
              "attrs": {
                "message": "keepalive"
              },
              "id": "9bbd77"
            },
            "meta": {
              "service": "admin"
            }
          }
        }
      }
    }
  ]
}
Response  400
HideShow
Headers
Content-Type: application/json; charset=utf-8
Body
{
  "message": "error message"
}

Generated by aglio on 18 Jan 2021