MENU navbar-image

Introduction

API documentation for hydroponic operations and performance tracking

This documentation aims to provide all the information you need to work with our Hydroponic Farm Operations API.

<aside>As you scroll, you'll see code examples for working with the API in different programming languages in the dark area to the right (or as part of the content on mobile).
You can switch the language used with the tabs at the top right (or from the nav menu at the top left on mobile).</aside>

Authenticating requests

To authenticate requests, include an Authorization header with the value "Bearer {YOUR_JWT_TOKEN}".

All authenticated endpoints are marked with a requires authentication badge in the documentation below.

You can retrieve your JWT token by logging in via the /api/login endpoint.

Authentication

APIs for user authentication

Login

Authenticate a user and return JWT tokens.

Example request:
curl --request POST \
    "http://localhost/api/login" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"email\": \"admin@example.com\",
    \"password\": \"password\"
}"
const url = new URL(
    "http://localhost/api/login"
);

const headers = {
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "email": "admin@example.com",
    "password": "password"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (200):


{
    "user": {
        "id": "uuid",
        "name": "Admin User",
        "role": "SUPER_ADMIN",
        "email": "admin@example.com",
        "farm_id": null,
        "permissions": []
    },
    "access_token": "jwt-token",
    "token_type": "bearer",
    "expires_in": 3600
}
 

Example response (401):


{
    "error": "Invalid credentials"
}
 

Request      

POST api/login

Headers

Content-Type        

Example: application/json

Accept        

Example: application/json

Body Parameters

email   string     

The user's email. Example: admin@example.com

password   string     

The user's password. Example: password

Register

requires authentication

Register a new user.

Example request:
curl --request POST \
    "http://localhost/api/register" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"name\": \"John Doe\",
    \"email\": \"john@example.com\",
    \"password\": \"password123\",
    \"role\": \"FARMER\",
    \"farm_id\": \"uuid\",
    \"permissions\": [
        \"consequatur\"
    ]
}"
const url = new URL(
    "http://localhost/api/register"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "name": "John Doe",
    "email": "john@example.com",
    "password": "password123",
    "role": "FARMER",
    "farm_id": "uuid",
    "permissions": [
        "consequatur"
    ]
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (201):


{
    "id": "uuid",
    "name": "John Doe",
    "email": "john@example.com",
    "role": "FARMER",
    "permissions": []
}
 

Request      

POST api/register

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Body Parameters

name   string     

The user's name. Example: John Doe

email   string     

The user's email. Example: john@example.com

password   string     

The user's password. Example: password123

role   string     

The user's role. Example: FARMER

farm_id   string  optional    

optional The farm ID. Example: uuid

permissions   string[]  optional    

optional The user's permissions.

Refresh token

requires authentication

Refresh the JWT token.

Example request:
curl --request POST \
    "http://localhost/api/refresh" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/refresh"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};


fetch(url, {
    method: "POST",
    headers,
}).then(response => response.json());

Example response (200):


{
    "access_token": "new-jwt-token",
    "token_type": "bearer",
    "expires_in": 3600
}
 

Request      

POST api/refresh

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Logout

requires authentication

Invalidate the user's token.

Example request:
curl --request POST \
    "http://localhost/api/logout" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/logout"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};


fetch(url, {
    method: "POST",
    headers,
}).then(response => response.json());

Example response (200):


{
    "message": "Successfully logged out"
}
 

Request      

POST api/logout

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Get current user

requires authentication

Get the authenticated user's information.

Example request:
curl --request GET \
    --get "http://localhost/api/me" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/me"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};


fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "id": "uuid",
    "name": "Admin User",
    "email": "admin@example.com",
    "role": "SUPER_ADMIN",
    "farm_id": null,
    "permissions": []
}
 

Request      

GET api/me

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Farms

APIs for managing farms

List farms

requires authentication

Get a list of all farms.

Example request:
curl --request GET \
    --get "http://localhost/api/farms" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/farms"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};


fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


[
    {
        "id": "uuid",
        "name": "Farm 1",
        "status": "ACTIVE",
        "location": "Location 1",
        "created_at": "2023-01-01T00:00:00.000000Z",
        "updated_at": "2023-01-01T00:00:00.000000Z"
    }
]
 

Request      

GET api/farms

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Create farm

requires authentication

Create a new farm.

Example request:
curl --request POST \
    "http://localhost/api/farms" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"name\": \"New Farm\",
    \"status\": \"ACTIVE\",
    \"location\": \"City, Country\"
}"
const url = new URL(
    "http://localhost/api/farms"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "name": "New Farm",
    "status": "ACTIVE",
    "location": "City, Country"
};

fetch(url, {
    method: "POST",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (201):


{
    "id": "uuid",
    "name": "New Farm",
    "status": "ACTIVE",
    "location": "City, Country",
    "created_at": "2023-01-01T00:00:00.000000Z",
    "updated_at": "2023-01-01T00:00:00.000000Z"
}
 

Request      

POST api/farms

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

Body Parameters

name   string     

The farm name. Example: New Farm

status   string  optional    

optional The farm status. Example: ACTIVE

location   string  optional    

optional The farm location. Example: City, Country

Get farm

requires authentication

Get a specific farm by ID.

Example request:
curl --request GET \
    --get "http://localhost/api/farms/uuid" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/farms/uuid"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};


fetch(url, {
    method: "GET",
    headers,
}).then(response => response.json());

Example response (200):


{
    "id": "uuid",
    "name": "Farm 1",
    "status": "ACTIVE",
    "location": "Location 1",
    "created_at": "2023-01-01T00:00:00.000000Z",
    "updated_at": "2023-01-01T00:00:00.000000Z"
}
 

Request      

GET api/farms/{id}

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

URL Parameters

id   string     

The farm ID. Example: uuid

Update farm

requires authentication

Update a specific farm.

Example request:
curl --request PUT \
    "http://localhost/api/farms/uuid" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json" \
    --data "{
    \"name\": \"Updated Farm\",
    \"status\": \"MAINTENANCE\",
    \"location\": \"New City\"
}"
const url = new URL(
    "http://localhost/api/farms/uuid"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};

let body = {
    "name": "Updated Farm",
    "status": "MAINTENANCE",
    "location": "New City"
};

fetch(url, {
    method: "PUT",
    headers,
    body: JSON.stringify(body),
}).then(response => response.json());

Example response (200):


{
    "id": "uuid",
    "name": "Updated Farm",
    "status": "MAINTENANCE",
    "location": "New City",
    "created_at": "2023-01-01T00:00:00.000000Z",
    "updated_at": "2023-01-01T00:00:00.000000Z"
}
 

Request      

PUT api/farms/{id}

PATCH api/farms/{id}

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

URL Parameters

id   string     

The farm ID. Example: uuid

Body Parameters

name   string  optional    

optional The farm name. Example: Updated Farm

status   string  optional    

optional The farm status. Example: MAINTENANCE

location   string  optional    

optional The farm location. Example: New City

Delete farm

requires authentication

Delete a specific farm.

Example request:
curl --request DELETE \
    "http://localhost/api/farms/uuid" \
    --header "Authorization: Bearer {YOUR_JWT_TOKEN}" \
    --header "Content-Type: application/json" \
    --header "Accept: application/json"
const url = new URL(
    "http://localhost/api/farms/uuid"
);

const headers = {
    "Authorization": "Bearer {YOUR_JWT_TOKEN}",
    "Content-Type": "application/json",
    "Accept": "application/json",
};


fetch(url, {
    method: "DELETE",
    headers,
}).then(response => response.json());

Example response (200):


{
    "message": "Farm deleted"
}
 

Request      

DELETE api/farms/{id}

Headers

Authorization        

Example: Bearer {YOUR_JWT_TOKEN}

Content-Type        

Example: application/json

Accept        

Example: application/json

URL Parameters

id   string     

The farm ID. Example: uuid