---
# System prepended metadata

title: Test tube result API routes
tags: [work, api, aiib]

---

---
tags: api,aiib,work
---
AiiB API doc
---

[toc]

---
# Test tube result API routes

## Route: `/api/result`

### Methods:`POST`

#### Description: Add the encrypted test tube data

Request Header:
```
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJhaWliLWRldi05c2FtIiwiaWF0IjoxNjEwNjI0NzkwLCJleHAiOjE5MjU5ODQ3OTB9.0KJ7urMl7Z1br5d4n6anCmHtO5fv8JGshQNizjwP1II
```

Request URL:
```
 https://aiib-api-dev.7ha7ha.life/api/result
```
Request sample json:
```json=
{
  "deviceId": "9283jf33f",
  "cuvetteId": "9823jf932",
  "encryptedData" : "asdfeawfew873whf89hw3898f3"
}
```

Response
```json=
{
  "result": {
    "deviceId": "9283jf33f",
    "cuvetteId": "9823jf932",
    "createdAt": "2021-01-15T12:01:05.201Z",
  }
}
```
Error:
```json=
{
  "message": "Error"
}
```

## Route: `/api/result/{id}`

### Methods:`PATCH`

#### Description: Update a specific test tube result by ID


Request Header:
```
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJhaWliLWRldi05c2FtIiwiaWF0IjoxNjEwNjI0NzkwLCJleHAiOjE5MjU5ODQ3OTB9.0KJ7urMl7Z1br5d4n6anCmHtO5fv8JGshQNizjwP1II
```

Request URL:
```
https://url/api/result/1
```

Request sample json:
```json=
{
  "deviceId": "9283jf33f",
  "cuvetteId": "9823jf932",
  "encryptedData" : "dhjsdjhkjgfaosdfknkl"
}
```

Response
```json=
{
    "result": {
        "id": 1,
        "deviceId": "9283jf33f",
        "cuvetteId": "9823jf932",
        "encryptedData": "dhjsdjhkjgfaosdfknkl",
        "transactionHash": "0x8c7494493daa13803e0a7f310dff047b41507b801dbc9ace29766e9a79a54b55",
        "createdAt": "2021-01-15T12:00:38.061Z",
        "updatedAt": "2021-01-15T12:00:44.000Z"
    }
    
}
```
Error:
```json=
  "message": "id does not exist"
```

## Route: `/api/result/{id}`

### Methods: `GET`

#### Description: Get a specific test tube result by ID

Request Header:
```
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJhaWliLWRldi05c2FtIiwiaWF0IjoxNjEwNjI0NzkwLCJleHAiOjE5MjU5ODQ3OTB9.0KJ7urMl7Z1br5d4n6anCmHtO5fv8JGshQNizjwP1II
```

Request URL:
```
 https://aiib-api-dev.7ha7ha.life/api/result/1
```
Response
```json=
{
    "result": {
        "id": 1,
        "deviceId": "9283jf33f",
        "cuvetteId": "9823jf932",
        "encryptedData": "asdfeawfew873whf89hw3898f3",
        "transactionHash": "0xf2e6ea36ecb9bb59a15f034f5f6a86cbabb421b8395762777a7ffa4e446acf4b",
        "createdAt": "2021-01-15T12:01:05.201Z",
        "updatedAt": "2021-01-15T12:01:14.000Z"
    }
}
```
Error:
```json=
  "message": "id does not exist"
```

## Route: `/api/eth/transaction/{transactionHash}`

### Methods: `GET`

#### Description: Get transaction from transaction hash

Request Header:
```
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJhaWliLWRldi05c2FtIiwiaWF0IjoxNjEwNjI0NzkwLCJleHAiOjE5MjU5ODQ3OTB9.0KJ7urMl7Z1br5d4n6anCmHtO5fv8JGshQNizjwP1II
```

Request URL:
```
 https://aiib-api-dev.7ha7ha.life/api/eth/transaction/0xd92c89df80f43bde608cee4b2310928d90715fda3790c108a98c505910dca1c8
```
Response
```json=
{
    "transaction": {
        "blockHash": "0x38e97c213a060d0e837231c10fbdaceb649eaab83a9e79b943b587d56d2e816e",
        "blockNumber": 321,
        "from": "0xaA4919C3835a5571e79b2606C2bBa35f0ecD97dF",
        "gas": 120575,
        "gasPrice": "1",
        "hash": "0xd92c89df80f43bde608cee4b2310928d90715fda3790c108a98c505910dca1c8",
        "input": "0x0af451b60000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005d7b226465766963654964223a22393238336a66333366222c22637576657474654964223a22393832336a66393332222c22656e6372797074656444617461223a226173646665617766657738373377686638396877333839386633227d000000",
        "nonce": 12,
        "to": "0xcf754518a0af663C39C1504488dAd32cfFc82b93",
        "transactionIndex": 0,
        "value": "0",
        "v": "0x3938",
        "r": "0xd85bf8f97a366c521eb2db39073b262505f6bb372fff3066e361cd5bb736a5e",
        "s": "0x3cd5acec78bd5b2762a8d54159bb64247006af8ba5f8fa9b54700c0f0f61297b"
    }
}
```

## Route: `/api/eth/transactions`

### Methods: `GET`

#### Description: Get all transactions

Request Header:
```
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJhaWliLWRldi05c2FtIiwiaWF0IjoxNjEwNjI0NzkwLCJleHAiOjE5MjU5ODQ3OTB9.0KJ7urMl7Z1br5d4n6anCmHtO5fv8JGshQNizjwP1II
```

#### Example 1 - get all transactions from ethereum:
Request URL:
```
 https://aiib-api-dev.7ha7ha.life/api/eth/transactions
```
Response
```json=
{
  "transaction": [
    {
      "address": "0x8b8d623E16C58e6C2BdC1CA5fc9C748780035b8f",
      "topics": [
        "0x950a6ce29810da09d5d5f06a268b81f898fd9c4c2dd444f5f452f6e7839082bc"
      ],
      "data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005d7b226465766963654964223a22393238336a66333366222c22637576657474654964223a22393832336a66393332222c22656e6372797074656444617461223a226173646665617766657738373377686638396877333839386633227d000000",
      "blockNumber": 53,
      "transactionHash": "0xe34d874b63c8a6587766844b4f209a73d9ef8a8cedf142b6ab7b367bebe879c2",
      "transactionIndex": 0,
      "blockHash": "0xbecf0c930a85862a12ff281625f40dcdc78b89c37e226745fdf8195946845a11",
      "logIndex": 0,
      "removed": false,
      "id": "log_2df63c5b"
    },
    {
      "address": "0x8b8d623E16C58e6C2BdC1CA5fc9C748780035b8f",
      "topics": [
        "0x950a6ce29810da09d5d5f06a268b81f898fd9c4c2dd444f5f452f6e7839082bc"
      ],
      "data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000907b226372656174656444617465223a22323032312d30312d32375430353a35363a35302e3433365a222c226465766963654964223a22393237376a66333366222c22637576657474654964223a22393832376a66393336222c22656e6372797074656444617461223a22617364666561776665773837337768663839687733383964777164777164777164386633227d00000000000000000000000000000000",
      "blockNumber": 83810,
      "transactionHash": "0x142bc69de3ae9301d561652842e12593f6d89fd329c655974768f28fd0ef4225",
      "transactionIndex": 0,
      "blockHash": "0x0874aa38cf91478c893b603a717bc2a6eb236bc2d60cfabaa42da16b4edbb9d1",
      "logIndex": 0,
      "removed": false,
      "id": "log_86fa642d"
    },
    {
      "address": "0x8b8d623E16C58e6C2BdC1CA5fc9C748780035b8f",
      "topics": [
        "0x950a6ce29810da09d5d5f06a268b81f898fd9c4c2dd444f5f452f6e7839082bc"
      ],
      "data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000897b226372656174656444617465223a22323032312d30312d32375430363a30373a33372e3934385a222c226465766963654964223a22393238336a66333366222c22637576657474654964223a22393832653365333332222c22656e6372797074656444617461223a226173646665617766657738376461326461326461676777333839386633227d0000000000000000000000000000000000000000000000",
      "blockNumber": 83875,
      "transactionHash": "0xdaccbe2cb43198ffb5ba6dbaa66a3051c8040cc9243847d6be43c70d846406b7",
      "transactionIndex": 0,
      "blockHash": "0x852e970bb9d55f1e2eb6589031fb446df07a3d38de717f1ff3e7fcda96b26c90",
      "logIndex": 0,
      "removed": false,
      "id": "log_d375a9df"
    }
  ]
}
```

#### Example 2 - filter by blockNumber:
Request URL:
```
 https://aiib-api-dev.7ha7ha.life/api/eth/transactions?fromBlock=53&toBlock=83810
```
Response:
```json=
{
  "transaction": [
    {
      "address": "0x8b8d623E16C58e6C2BdC1CA5fc9C748780035b8f",
      "topics": [
        "0x950a6ce29810da09d5d5f06a268b81f898fd9c4c2dd444f5f452f6e7839082bc"
      ],
      "data": "0x0000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000005d7b226465766963654964223a22393238336a66333366222c22637576657474654964223a22393832336a66393332222c22656e6372797074656444617461223a226173646665617766657738373377686638396877333839386633227d000000",
      "blockNumber": 53,
      "transactionHash": "0xe34d874b63c8a6587766844b4f209a73d9ef8a8cedf142b6ab7b367bebe879c2",
      "transactionIndex": 0,
      "blockHash": "0xbecf0c930a85862a12ff281625f40dcdc78b89c37e226745fdf8195946845a11",
      "logIndex": 0,
      "removed": false,
      "id": "log_2df63c5b"
    },
    {
      "address": "0x8b8d623E16C58e6C2BdC1CA5fc9C748780035b8f",
      "topics": [
        "0x950a6ce29810da09d5d5f06a268b81f898fd9c4c2dd444f5f452f6e7839082bc"
      ],
      "data": "0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000907b226372656174656444617465223a22323032312d30312d32375430353a35363a35302e3433365a222c226465766963654964223a22393237376a66333366222c22637576657474654964223a22393832376a66393336222c22656e6372797074656444617461223a22617364666561776665773837337768663839687733383964777164777164777164386633227d00000000000000000000000000000000",
      "blockNumber": 83810,
      "transactionHash": "0x142bc69de3ae9301d561652842e12593f6d89fd329c655974768f28fd0ef4225",
      "transactionIndex": 0,
      "blockHash": "0x0874aa38cf91478c893b603a717bc2a6eb236bc2d60cfabaa42da16b4edbb9d1",
      "logIndex": 0,
      "removed": false,
      "id": "log_86fa642d"
    }
  ]
}
```

## Route: `/api/results`

### Methods:`GET`

#### Description: Get all existing test tube results from blockchain


Request Header:
```
Authorization: Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJhaWliLWRldi05c2FtIiwiaWF0IjoxNjEwNjI0NzkwLCJleHAiOjE5MjU5ODQ3OTB9.0KJ7urMl7Z1br5d4n6anCmHtO5fv8JGshQNizjwP1II
```

Query Parameters:
```json=
device_id (optional)
cuvette_id (optional)
```

#### Example 1:

Request:
```
 https://aiib-api-dev.7ha7ha.life/api/results?cuvetteId=9283jf33f&startDay=2020-11-11&endDay=2021-01-30
```

Response
```json=
{
  "results": [
    {
      "createdDate": "2021-01-26T10:42:50.145Z",
      "cuvetteId": "9283jf33f",
      "deviceId": "9823jf932",
      "encryptedData": "asdfeawfew873whf89hw3898f3"
    },
    {
      "createdDate": "2021-01-26T10:46:02.887Z",
      "cuvetteId": "9283jf33f",
      "deviceId": "9823jf932",
      "encryptedData": "asdfeawfew873whf89hw3898f3"
    },
    {
      "createdDate": "2020-11-21T00:00:00.000Z",
      "cuvetteId": "9283jf33f",
      "deviceId": "9823jf932",
      "encryptedData": "asdfeawfew873whf89hw3898f3"
    }
  ]
}
```
Error:
```json=
  "message": "something went wrong"
```

#### Example 2:

Request:
```
 https://aiib-api-dev.7ha7ha.life/api/results?cuvetteId=9283jf33f
```

Response
```json=
{
  "results": [
    {
      "createdDate": "2021-01-26T10:42:50.145Z",
      "cuvetteId": "9283jf33f",
      "deviceId": "9823jf932",
      "encryptedData": "asdfeawfew873whf89hw3898f3"
    },
    {
      "createdDate": "2021-01-26T10:46:02.887Z",
      "cuvetteId": "9283jf33f",
      "deviceId": "9823jf932",
      "encryptedData": "asdfeawfew873whf89hw3898f3"
    },
    {
      "createdDate": "2020-11-21T00:00:00.000Z",
      "cuvetteId": "9283jf33f",
      "deviceId": "9823jf932",
      "encryptedData": "asdfeawfew873whf89hw3898f3"
    },
    {
      "createdDate": "2020-10-21T00:00:00.000Z",
      "cuvetteId": "9283jf33f",
      "deviceId": "9823jf932",
      "encryptedData": "asdfeawfew873whf89hw3898f3"
    }
  ]
}
```
Error:
```json=
  "message": "something went wrong"
```

---
