This document provides a comprehensive reference for all API endpoints in the Resource Tracker application.
All protected endpoints require Discord OAuth authentication via NextAuth.js. An API request is authorized if the user's Discord roles grant them the necessary permissions as defined in the system's role configuration.
- Method: Bearer Token Authentication
- Header:
Authorization: Bearer {session_token}
Endpoints for managing resources.
Retrieves a list of all resources, including their current quantities, status, and metadata.
- Permissions: Contributor
Response 200 OK
[
{
"id": "resource_id",
"name": "Resource Name",
"quantityHagga": 1000,
"quantityDeepDesert": 500,
"description": "Resource description",
"category": "Raw Materials",
"icon": ":resource_icon:",
"imageUrl": "https://example.com/image.png",
"status": "at_target",
"targetQuantity": 1000,
"multiplier": 1.0,
"lastUpdatedBy": "User Name",
"createdAt": "2024-01-01T00:00:00.000Z",
"updatedAt": "2024-01-01T00:00:00.000Z"
}
]Creates a new resource.
- Permissions: Administrator
Request Body
{
"name": "New Resource",
"category": "New Category",
"description": "Optional description",
"targetQuantity": 5000,
"icon": ":new_icon:"
}Updates the metadata of an existing resource (e.g., name, category).
- Permissions: Administrator
Request Body
{
"id": "resource_id_to_update",
"name": "Updated Resource Name",
"category": "Updated Category"
}Deletes a resource and all its associated history.
- Permissions: Administrator
- Parameters:
id(string) - The ID of the resource to delete.
Updates the quantity of a resource at a specific location.
- Permissions: Contributor
- Parameters:
id(string) - The ID of the resource to update.
Request Body
{
"quantity": 1500,
"changeType": "absolute", // or "relative"
"reason": "Weekly inventory update",
"location": "Hagga" // or "Deep Desert"
}Transfers a resource quantity between the two locations.
- Permissions: Contributor
- Parameters:
id(string) - The ID of the resource to transfer.
Request Body
{
"transferAmount": 100,
"transferDirection": "to_deep_desert" // or "to_hagga"
}Updates the target quantity for a resource.
- Permissions: Logistics Manager
- Parameters:
id(string) - The ID of the resource.
Request Body
{
"targetQuantity": 2000
}Retrieves the change history for a specific resource.
- Permissions: Contributor
- Parameters:
id(string) - The ID of the resource. - Query Parameters:
days(number, optional) - Number of days to look back (default: 7).
Response 200 OK
[
{
"id": "history_id",
"resourceId": "resource_id",
"previousQuantityHagga": 800,
"newQuantityHagga": 1000,
"changeAmountHagga": 200,
"previousQuantityDeepDesert": 500,
"newQuantityDeepDesert": 500,
"changeAmountDeepDesert": 0,
"changeType": "relative",
"updatedBy": "User Name",
"reason": "Weekly collection",
"createdAt": "2024-01-01T00:00:00.000Z"
}
]Deletes a specific history entry.
- Permissions: Administrator
- Parameters:
id(string) - The ID of the resource.entryId(string) - The ID of the history entry to delete.
Retrieves a list of all users in the system.
- Permissions: Administrator
Retrieves the activity history for the currently authenticated user or globally if specified.
- Permissions: Contributor
- Query Parameters:
days(number, optional): Number of days to look back (default: 30).global(boolean, optional): If true, shows activity for all users (requires Administrator permissions).limit(number, optional): Maximum number of entries (default: 500).
Retrieves leaderboard rankings.
- Permissions: Contributor
- Query Parameters:
timeFilter(string): "all", "month", "week", "day" (default: "all").limit(number): Maximum entries to return (default: 50).offset(number): Pagination offset (default: 0).
Retrieves detailed contributions and points for a specific user.
- Permissions: Contributor
- Parameters:
userId(string) - The Discord ID of the user.
Exports all data for the currently authenticated user in JSON format.
- Permissions: Contributor
Requests anonymization of all data for the currently authenticated user.
- Permissions: Contributor
All endpoints return consistent error responses.
Example 403 Forbidden
{
"error": "You do not have permission to perform this action.",
"code": "FORBIDDEN"
}200 OK- The request was successful.201 Created- The resource was successfully created.400 Bad Request- The server cannot process the request due to a client error (e.g., malformed request syntax).401 Unauthorized- The client must authenticate itself to get the requested response.403 Forbidden- The client does not have access rights to the content.404 Not Found- The server cannot find the requested resource.500 Internal Server Error- The server has encountered a situation it doesn't know how to handle.