Quick Start Guide
This guide will help you install, configure, and make your first API request to MaqAgr.Prerequisites
Before you begin, ensure you have the following installed:Node.js
v24.13.0 or higherJavaScript runtime
PostgreSQL
v12 or higherRelational database
npm/pnpm
Latest versionPackage manager
Installation
Install dependencies
Install all required Node.js packages:
The project uses ES modules (
"type": "module" in package.json), so all imports use ES6 syntax.Configure environment variables
Create a Required environment variables:
.env file in the root directory with your configuration:If
.env.example doesn’t exist, create a .env file manually with the variables shown below..env
Set up the database
Create the PostgreSQL database and import the schema:
The schema files create all necessary tables, relationships, and indexes for the API.
Your First API Request
Let’s walk through a complete authentication flow and make your first authenticated request.Register a new user
Create a new user account by sending a POST request to Password requirements:
/api/auth/register:cURL
- Minimum 8 characters
- At least one uppercase letter
- At least one number
- At least one special character
New users are assigned
role_id: 2 (regular user) by default. The response includes a JWT token valid for 24 hours.Save your token
Copy the
token value from the registration response. You’ll need this for authenticated requests.The token payload contains:Make an authenticated request
Use your token to access a protected endpoint. Let’s fetch your user profile:Response (200 OK):
cURL
Common Errors
Here are some common errors you might encounter and how to resolve them:Missing or Invalid Token
Authorization: Bearer <token> header in your request.
Expired Token
Validation Error
errors array for specific validation requirements.
Email Already Registered
Testing the API
The project includes comprehensive tests:Swagger Documentation
The API includes interactive Swagger documentation. Once the server is running, visit:- Explore all endpoints interactively
- View request/response schemas
- Test endpoints directly from your browser
- See detailed parameter descriptions
Health Check
Verify the API is running correctly:Next Steps
Authentication Deep Dive
Learn more about JWT authentication, token structure, and security
API Reference
Explore all available endpoints and their parameters
Calculations
Learn how to perform power calculations and get recommendations
Error Handling
Understand error responses and how to handle them
