Skip to main content

Documentation Index

Fetch the complete documentation index at: https://mintlify.com/diarpicu2022-commits/backend-AgroPulse/llms.txt

Use this file to discover all available pages before exploring further.

The user management endpoints allow privileged operations on user accounts: listing all users, changing a user’s role, updating greenhouse access, and upserting Google-authenticated users. Most of these operations are restricted to administrators and require the X-Admin-Email request header.
All admin operations validate the X-Admin-Email request header against the AGROPULSE_ADMIN_EMAIL environment variable configured on the server. Requests that omit this header, or supply an email that does not match, receive 403 Forbidden.

GET /api/auth/users

Returns a list of all registered users. Requires admin access.

Request headers

X-Admin-Email
string
required
Must match the value of the AGROPULSE_ADMIN_EMAIL environment variable on the server.

Response

users
object[]
required
Array of user objects.

Example

curl --request GET \
  --url http://localhost:8080/api/auth/users \
  --header 'X-Admin-Email: admin@agropulse.io'
{
  "users": [
    {
      "id": 1,
      "username": "admin",
      "fullName": "Admin User",
      "email": "admin@agropulse.io",
      "phone": null,
      "avatar": null,
      "role": "ADMIN",
      "active": true,
      "createdAt": "2024-01-10T08:00:00",
      "greenhouseIds": []
    }
  ]
}

PUT /api/auth/users//role

Changes the role of an existing user. Requires admin access.

Path parameters

id
number
required
The integer ID of the user to update.

Request headers

X-Admin-Email
string
required
Must match the value of the AGROPULSE_ADMIN_EMAIL environment variable on the server.

Request body

role
string
required
Target role. Valid values are ADMIN, AGRONOMIST, OPERATOR, VIEWER, and USER. Unrecognized values are mapped to OPERATOR.

Response

Returns the updated user object (same shape as the user objects in GET /api/auth/users).
Passing an unrecognized role string does not produce an error — it silently maps to OPERATOR.

Error responses

StatusCause
403Missing or non-matching X-Admin-Email header.
404No user found with the specified id.

Example

curl --request PUT \
  --url http://localhost:8080/api/auth/users/7/role \
  --header 'Content-Type: application/json' \
  --header 'X-Admin-Email: admin@agropulse.io' \
  --data '{
    "role": "ADMIN"
  }'
{
  "id": 7,
  "username": "jane_doe",
  "fullName": "Jane Doe",
  "email": "jane@example.com",
  "phone": null,
  "avatar": null,
  "role": "ADMIN",
  "active": true,
  "createdAt": "2024-03-15T11:05:00",
  "greenhouseIds": []
}

PUT /api/auth/users//greenhouses

Replaces the greenhouse access list for a user. Requires admin access.

Path parameters

id
number
required
The integer ID of the user to update.

Request headers

X-Admin-Email
string
required
Must match the value of the AGROPULSE_ADMIN_EMAIL environment variable on the server.

Request body

ids
number[]
required
Array of greenhouse integer IDs to assign to the user. Pass an empty array ([]) to revoke all access. Any non-array value clears the list.

Response

ids
number[]
required
The updated list of greenhouse IDs now stored on the user.

Error responses

StatusCause
403Missing or non-matching X-Admin-Email header.
404No user found with the specified id.

Example

curl --request PUT \
  --url http://localhost:8080/api/auth/users/7/greenhouses \
  --header 'Content-Type: application/json' \
  --header 'X-Admin-Email: admin@agropulse.io' \
  --data '{
    "ids": [1, 2, 5]
  }'
{
  "ids": [1, 2, 5]
}

POST /api/auth/sync-google-user

Upserts a Google-authenticated user. If a user with the given email already exists, the existing record is returned unchanged. Otherwise a new account is created with the provided details.
This endpoint does not require the X-Admin-Email header. It is intended for server-side OAuth sync flows, not direct user-facing login — use POST /api/auth/login for that.

Request body

email
string
required
The Google account email address. Used as the unique lookup key.
username
string
Desired username for the new account. Defaults to email if omitted.
full_name
string
Display name. Defaults to email if omitted.
avatar
string
URL of the Google profile picture.
role
string
Initial role for a newly created account. Defaults to OPERATOR if omitted or unrecognized.

Response

Returns the user object for the existing or newly created account (same shape as the user objects in GET /api/auth/users).

Error responses

Statuserror valueCause
400email requeridoThe email field is missing from the request body.

Example

curl --request POST \
  --url http://localhost:8080/api/auth/sync-google-user \
  --header 'Content-Type: application/json' \
  --data '{
    "email": "jane@example.com",
    "username": "jane_google",
    "full_name": "Jane Doe",
    "avatar": "https://lh3.googleusercontent.com/photo.jpg",
    "role": "OPERATOR"
  }'
{
  "id": 12,
  "username": "jane_google",
  "fullName": "Jane Doe",
  "email": "jane@example.com",
  "phone": null,
  "avatar": "https://lh3.googleusercontent.com/photo.jpg",
  "role": "OPERATOR",
  "active": true,
  "createdAt": "2024-03-20T09:00:00",
  "greenhouseIds": []
}

Build docs developers (and LLMs) love