---
# System prepended metadata

title: Machine Management API

---

# Machine Management API

## 1. User Token API

```json
API URL: http://172.104.163.254:8000/api/v1/users/token/
METHOD: POST
REQUEST BODY:
{
	"username": "shafik",
	"password": "shafik"
}

RESPONSE:
{
  "success": true,
  "message": "Status OK",
  "data": {
    "token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VyX2lkIjoyLCJ1c2VybmFtZSI6InNoYWZpayIsImV4cCI6MTYyNzY1ODc3NywiZW1haWwiOm51bGwsIm9yaWdfaWF0IjoxNjI3NjU4NDc3fQ.4ZXXT_Wvh8VSbn0kJaKS2GNrN_Svanb6B9_OL7X2RF8",
    "groups": [
      "Employee"
    ]
  }
}
```

> **All APIs will be called with the token in authorization header:**
> **Example: Authorization: jwt <token>**


## 2. Machine List API

```json
API URL: http://172.104.163.254:8000/api/v1/machines
METHOD: GET
RESPONSE: (NO PAGIANTION)
{
  "success": true,
  "message": "Status OK",
  "data": [
    {
      "name": "Cleaning Machine",
      "machine_no": 1
    },
    {
      "name": "Blending Machine",
      "machine_no": 2
    },
    {
      "name": "Lap Former",
      "machine_no": 3
    },
    {
      "name": "Carding",
      "machine_no": 4
    },
    {
      "name": "Drawing Machin",
      "machine_no": 5
    },
    {
      "name": "Simplex Machine",
      "machine_no": 6
    },
    {
      "name": "Ring Frame",
      "machine_no": 7
    }
  ]
}
```

## 3. Machine Data API
```json
API URL: http://172.104.163.254:8000/api/v1/machines/data
METHOD: GET

Pagination Query Params:
    for page size limit use -> page_size . exmaple: ?page_size=12
    for page number use -> page. exmaple: ?page=1
Filtering Query Params:
    -start=<isoformat> example: start=2021-11-25T14:00:00
    -end=<isoformat> example: start=2021-11-26T23:00:00
    -machine_no=<can be select multiple machine no and will be seperated by hyphen(-). example: machine_no=3-5-11
    -machine_status=on or off. exmaple: machine_status=on
Response:
{
  "success": true,
  "meta_data": {
    "count": 10,
    "page_size": 12,
    "next": null,
    "previous": null
  },
  "data": [
    {
      "machine_no": 1,
      "machine_status": "off",
      "start": "2021-07-29T20:03:49.004069",
      "end": "2021-07-29T20:03:56.173286",
      "total_minutes": 0.12
    },
    {
      "machine_no": 4,
      "machine_status": "on",
      "start": "2021-07-29T20:04:29.978241",
      "end": "2021-07-29T20:04:44.619855",
      "total_minutes": 0.24
    },
    {
      "machine_no": 1,
      "machine_status": "on",
      "start": "2021-07-29T20:04:15.648089",
      "end": "2021-07-29T20:33:44.991878",
      "total_minutes": 29.49
    },
    {
      "machine_no": 2,
      "machine_status": "on",
      "start": "2021-07-29T20:04:22.447368",
      "end": "2021-07-29T20:34:57.146777",
      "total_minutes": 30.58
    },
    {
      "machine_no": 3,
      "machine_status": "on",
      "start": "2021-07-29T20:04:26.332287",
      "end": "2021-07-29T20:36:19.414754",
      "total_minutes": 31.88
    },
    {
      "machine_no": 3,
      "machine_status": "off",
      "start": "2021-07-29T20:36:26.112025",
      "end": "2021-07-29T21:22:00.186622",
      "total_minutes": 45.57
    },
    {
      "machine_no": 3,
      "machine_status": "on",
      "start": "2021-07-29T21:32:56.985757",
      "end": "2021-07-29T21:32:56.985757",
      "total_minutes": 5.0
    },
    {
      "machine_no": 4,
      "machine_status": "off",
      "start": "2021-07-29T21:34:41.900169",
      "end": "2021-07-29T21:34:41.900169",
      "total_minutes": 5.0
    },
    {
      "machine_no": 2,
      "machine_status": "off",
      "start": "2021-07-29T21:37:20.675614",
      "end": "2021-07-29T21:37:20.675614",
      "total_minutes": 5.0
    },
    {
      "machine_no": 5,
      "machine_status": "on",
      "start": "2021-07-29T21:37:52.883013",
      "end": "2021-07-29T21:37:52.883013",
      "total_minutes": 5.0
    }
  ]
}
```


## 4. Machine Data Analytics API

```json
API URL: http://172.104.163.254:8000/api/v1/machines/analytics

METHOD: GET

Filtering Query Params:
    -start=<isoformat> example: start=2021-11-25T14:00:00
    -end=<isoformat> example: start=2021-11-26T23:00:00
    -machine_no=<can be select multiple machine no and will be seperated by hyphen(-). example: machine_no=3-5-11
    -order=asc/desc | asc = least to most, desc = most to least
    
RESPONSE:
{
  "success": true,
  "message": "Status OK",
  "data": [
    {
      "machine_no": 1,
      "total_on_time": 29.49,
      "total_off_time": 0.12,
      "efficiency": 99.59473150962513
    },
    {
      "machine_no": 2,
      "total_on_time": 30.58,
      "total_off_time": 5.0,
      "efficiency": 85.94716132658797
    },
    {
      "machine_no": 3,
      "total_on_time": 36.879999999999995,
      "total_off_time": 45.57,
      "efficiency": 44.7301394784718
    },
    {
      "machine_no": 4,
      "total_on_time": 0.24,
      "total_off_time": 5.0,
      "efficiency": 4.580152671755725
    },
    {
      "machine_no": 5,
      "total_on_time": 5.0,
      "total_off_time": null,
      "efficiency": null
    }
  ]
}
```
## 5.Offline Devices API
```json
API URL: http://172.104.163.254:8000/api/v1/machines/data?status=offline
METHOD: GET
RESPONSE:
{
  "success": true,
  "meta_data": {
    "count": 10,
    "page_size": 12,
    "next": null,
    "previous": null
  },
  "data": [
    {
      "machine_no": 1,
      "machine_status": "off",
      "start": "2021-07-29T20:03:49.004069",
      "end": "2021-07-29T20:03:56.173286",
      "total_minutes": 0.12
    },
    {
      "machine_no": 4,
      "machine_status": "on",
      "start": "2021-07-29T20:04:29.978241",
      "end": "2021-07-29T20:04:44.619855",
      "total_minutes": 0.24
    }
  ]
 }
    
```

## 6. Machine Data Total Efficency API

```json
API URL: http://172.104.163.254:8000/api/v1/machines/total-analytics

METHOD: GET

Filtering Query Params:
    -start=<isoformat> example: start=2021-11-25T14:00:00
    -end=<isoformat> example: start=2021-11-26T23:00:00
    -machine_no=<can be select multiple machine no and will be seperated by hyphen(-). example: machine_no=3-5-11
    -is_order=true (for ordering most efficent machine to least efficent machine)


Response:
{
  "success": true,
  "message": "Status OK",
  "data": {
    "total_on_time": 102.19,
    "total_off_time": 55.69,
    "efficiency": 64.73,
    "start": "2021-07-29T20:03:49.004069",
    "end": "2021-07-29T21:37:52.883013"
  }
}
```