> For the complete documentation index, see [llms.txt](https://rapchan.gitbook.io/hyperledger-food-supply-chain/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://rapchan.gitbook.io/hyperledger-food-supply-chain/implementation/api.md).

# API Reference

## Get Product

<mark style="color:blue;">`GET`</mark> `https://localhost:3003/getProduct/:id`

Retrieves information about the product.

#### Path Parameters

| Name | Type   | Description                  |
| ---- | ------ | ---------------------------- |
| id   | string | ID of the product to retieve |

{% tabs %}
{% tab title="200 Product data" %}

```
{
    "result": {
        "barcode": "1234567890",
        "batchQuantity": 1000,
        "category": "Fruits",
        "componentProductIds": [],
        "expirationDate": "2022-06-24T18:25:43.511Z",
        "id": "1001",
        "locationData": {
            "current": {
                "arrivalDate": "2021-06-30T18:00:58.511Z",
                "location": "Markham Farm, Marham, ON, Canada"
            },
            "previous": []
        },
        "misc": "{}",
        "name": "Apples",
        "placeOfOrigin": "Markham, ON, Canada",
        "productionDate": "2021-06-24T18:25:43.511Z",
        "unitPrice": "$5.00",
        "unitQuantity": 300,
        "unitQuantityType": "mg",
        "variety": null
    }
}
```

{% endtab %}
{% endtabs %}

## Create Product

<mark style="color:green;">`POST`</mark> `https://localhost:3003/createProduct`

Creates a new product.

#### Request Body

| Name                  | Type   | Description                      |
| --------------------- | ------ | -------------------------------- |
| locationData.previous | array  |                                  |
| locationData.current  | object |                                  |
| variety               | string |                                  |
| unitQuantityType      | string | E.g., mg, liters etc.            |
| unitQuantity          | number |                                  |
| unitPrice             | string | Currency symbol formatted amount |
| productionDate        | string | ISO Date                         |
| placeOfOrigin         | string |                                  |
| name                  | string |                                  |
| misc                  | object | Miscellaneous information        |
| expirationDate        | string | ISO Date                         |
| componentProductIds   | array  |                                  |
| category              | string |                                  |
| batchQuantity         | number |                                  |
| barcode               | string |                                  |
| id                    | string |                                  |

{% tabs %}
{% tab title="200 " %}

```
{
    "result": {
        "type": "Buffer",
        "data": []
    }
}
```

{% endtab %}
{% endtabs %}

## Get Product With History

<mark style="color:blue;">`GET`</mark> `https://localhost:3003/getProductWithHistory/:id`

Retrieves the product data together with its history.

#### Path Parameters

| Name | Type   | Description               |
| ---- | ------ | ------------------------- |
| id   | string | ID of product to retrieve |

{% tabs %}
{% tab title="200 " %}

```
{
    "result": {
        "barcode": "1234567890",
        "batchQuantity": 1000,
        "category": "Fruits",
        "componentProductIds": [],
        "expirationDate": "2022-06-24T18:25:43.511Z",
        "id": "1001",
        "locationData": {
            "current": {
                "arrivalDate": "2021-07-07T01:11:18.409Z",
                "location": "Waterloo, ON"
            },
            "previous": [
                {
                    "arrivalDate": "2021-06-30T18:00:58.511Z",
                    "location": "Markham Farm, Marham, ON, Canada"
                }
            ]
        },
        "misc": "{}",
        "name": "Apples",
        "placeOfOrigin": "Markham, ON, Canada",
        "productionDate": "2021-06-24T18:25:43.511Z",
        "unitPrice": "$5.00",
        "unitQuantity": 300,
        "unitQuantityType": "mg",
        "variety": null,
        "componentProducts": []
    }
}
```

{% endtab %}
{% endtabs %}

## Product Exists

<mark style="color:blue;">`GET`</mark> `http://localhost:3003/productExists/:id`

Verifies if a product exists or not.

#### Path Parameters

| Name | Type   | Description         |
| ---- | ------ | ------------------- |
| id   | string | Product ID to check |

{% tabs %}
{% tab title="200 " %}

```
{
    "exists": "false"
}
```

{% endtab %}
{% endtabs %}

## Ship Product

<mark style="color:green;">`POST`</mark> `http://localhost:3003/shipProduct`

Sends the product to a new location.

#### Request Body

| Name        | Type   | Description |
| ----------- | ------ | ----------- |
| arrivalDate | string | ISO Date    |
| newLocation | string |             |
| productId   | string |             |

{% tabs %}
{% tab title="200 " %}

```
{
    "status": "Transaction submitted.",
    "txId": ""
}
```

{% endtab %}
{% endtabs %}
