Skip to main content

Overview

The Project Resources API allows you to manage the assignment, tracking, and release of equipment and services for projects. You can add resources to projects, update their configuration, release them when no longer needed, and query available resources.

Endpoints

Get Available Resources

Retrieve a list of all available equipment and resources that can be assigned to projects.
GET /api/projects/resources/available/

Query Parameters

type_equipment
string
Filter by equipment type (e.g., BTSNHM, LVMNOS, SERVIC)
status_equipment
string
Filter by equipment status (e.g., FUNCIONANDO, DAÑADO)
Search by equipment code or name
exclude_services
boolean
default:"true"
Exclude service-type resources from results

Response

success
boolean
Indicates if the request was successful
count
integer
Total number of available resources
data
array
Array of available resource objects

Example Request

curl -X GET "https://api.mantis.example/api/projects/resources/available/?type_equipment=BTSNHM&status_equipment=FUNCIONANDO" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "success": true,
  "count": 2,
  "data": [
    {
      "id": 5,
      "code": "BS-001",
      "name": "Batería Sanitaria Hombre",
      "display_name": "Batería Sanitaria Hombre - BATERIA SANITARIA HOMBRE",
      "type_equipment": "BTSNHM",
      "type_equipment_display": "BATERIA SANITARIA HOMBRE",
      "brand": "ACME",
      "model": "BS-2024",
      "status_equipment": "FUNCIONANDO",
      "status_disponibility": "DISPONIBLE",
      "available": true,
      "current_location": "BASE PEISOL",
      "capacity_gallons": "500.00",
      "assigned_project": null,
      "is_selected": false,
      "is_confirm_delete": false
    }
  ]
}

Add Resource to Project

Assign one or more resources to a project with cost and scheduling information.
POST /api/projects/resources/add/

Request Body

The request body should be an array of resource objects to add:
project_id
integer
required
ID of the project to assign resources to
resource_id
integer
required
ID of the resource item to assign
cost
decimal
required
Rental or service cost
maintenance_cost
decimal
Maintenance cost (creates a separate maintenance service entry)
frequency_type
string
default:"DAY"
Frequency type for scheduling: DAY, WEEK, or MONTH
interval_days
integer
Number of days between occurrences (used when frequency_type is DAY)
weekdays
array
Days of the week (0=Monday, 6=Sunday). Used when frequency_type is WEEK
monthdays
array
Days of the month (1-31). Used when frequency_type is MONTH
operation_start_date
string
required
Start date for resource operation (YYYY-MM-DD)
operation_end_date
string
End date for resource operation (YYYY-MM-DD)
physical_equipment_code
integer
ID of physical equipment this service is associated with
detailed_description
string
Detailed description of the resource assignment
commitment_date
string
Date when equipment is committed to the project

Response

data
array
Array of created project resource assignments

Example Request

curl -X POST "https://api.mantis.example/api/projects/resources/add/" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '[
    {
      "project_id": 1,
      "resource_id": 5,
      "cost": 150.00,
      "maintenance_cost": 50.00,
      "frequency_type": "DAY",
      "interval_days": 7,
      "operation_start_date": "2025-10-05",
      "operation_end_date": "2025-12-31",
      "commitment_date": "2025-10-05"
    }
  ]'

Example Response

{
  "data": [
    {
      "id": 10,
      "project_id": 1,
      "project_name": "Proyecto 1 - Empresa XYZ",
      "resource_item_id": 5,
      "resource_item_name": "Batería Sanitaria Hombre",
      "type_resource": "EQUIPO",
      "detailed_description": "ALQUILER / BS-001 / BATERIA SANITARIA HOMBRE",
      "cost": 150.00,
      "interval_days": 7,
      "operation_start_date": "2025-10-05",
      "operation_end_date": "2025-12-31",
      "is_retired": false,
      "retirement_date": null,
      "retirement_reason": null,
      "is_active": true,
      "is_deleted": false,
      "created_at": "2025-10-05T10:30:00Z",
      "updated_at": "2025-10-05T10:30:00Z"
    },
    {
      "id": 11,
      "project_id": 1,
      "project_name": "Proyecto 1 - Empresa XYZ",
      "resource_item_id": 100,
      "resource_item_name": "Servicio General",
      "type_resource": "SERVICIO",
      "detailed_description": "MANTENIMIENTO / BS-001",
      "cost": 50.00,
      "interval_days": 7,
      "operation_start_date": "2025-10-05",
      "operation_end_date": "2025-12-31",
      "is_retired": false,
      "retirement_date": null,
      "retirement_reason": null,
      "is_active": true,
      "is_deleted": false,
      "created_at": "2025-10-05T10:30:00Z",
      "updated_at": "2025-10-05T10:30:00Z"
    }
  ]
}
Automatic Status Updates: When equipment is added to a project:
  • stst_status_disponibility changes to RENTADO
  • stst_current_location updates to project location
  • stst_current_project_id set to the project ID
  • stst_commitment_date set to operation start date

Update Resource Item

Update the cost, frequency, or dates for a resource assigned to a project.
PUT /api/projects/resources/update/

Request Body

id
integer
required
ID of the ProjectResourceItem to update
cost
decimal
Updated rental or service cost
frequency_type
string
Frequency type: DAY, WEEK, or MONTH
interval_days
integer
Number of days between occurrences (for DAY frequency)
weekdays
array
Days of the week (0=Monday, 6=Sunday) for WEEK frequency
monthdays
array
Days of the month (1-31) for MONTH frequency
detailed_description
string
Updated detailed description
operation_start_date
string
Updated start date (YYYY-MM-DD)
operation_end_date
string
Updated end date (YYYY-MM-DD)
maintenance_cost
decimal
Updated maintenance cost (updates linked service if it exists)
is_retired
boolean
Set to true to retire the resource
retirement_date
string
Date of retirement (required if is_retired is true)
retirement_reason
string
Reason for retirement (required if is_retired is true)

Response

message
string
Success message
data
object
Updated project resource object with all fields

Example Request

curl -X PUT "https://api.mantis.example/api/projects/resources/update/" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{
    "id": 10,
    "cost": 175.00,
    "frequency_type": "WEEK",
    "weekdays": [1, 3, 5],
    "maintenance_cost": 60.00
  }'

Example Response

{
  "message": "Recurso del proyecto actualizado correctamente.",
  "data": {
    "id": 10,
    "project_id": 1,
    "type": "BTSNHM",
    "resource_item_id": 5,
    "resource_item_code": "BS-001",
    "resource_item_name": "Batería Sanitaria Hombre",
    "detailed_description": "ALQUILER / BS-001 / BATERIA SANITARIA HOMBRE",
    "cost": 175.00,
    "frequency_type": "WEEK",
    "interval_days": 0,
    "weekdays": [1, 3, 5],
    "monthdays": null,
    "operation_start_date": "2025-10-05",
    "operation_end_date": "2025-12-31",
    "is_active": true,
    "type_resource": "EQUIPO",
    "is_retired": false,
    "retirement_date": null,
    "retirement_reason": null,
    "notes": null
  }
}
Linked Service Updates: When updating maintenance_cost for equipment, any linked maintenance service will automatically have its cost and frequency synchronized.

Delete Resource from Project

Permanently remove a resource assignment from a project.
DELETE /api/projects/resources/delete/<id_project_resource>/

Path Parameters

id_project_resource
integer
required
ID of the ProjectResourceItem to delete

Response

Returns HTTP 204 No Content on success.

Error Responses

error
string
Error message if deletion fails
404 Not Found: Resource not found 400 Bad Request: Resource cannot be deleted (e.g., used in custody chain)

Example Request

curl -X DELETE "https://api.mantis.example/api/projects/resources/delete/10/" \
  -H "Authorization: Bearer YOUR_TOKEN"
Custody Chain Protection: Resources that have been used in a custody chain cannot be deleted. The API will return an error with status 400.
Resource Liberation: When a resource is deleted:
  • Physical equipment status changes back to DISPONIBLE
  • stst_current_project_id is cleared
  • The ProjectResourceItem record is permanently deleted

Release Resource from Project

Release (retire) a resource from a project without permanently deleting it.
POST /api/projects/resources/release/

Request Body

id
integer
required
ID of the ProjectResourceItem to release

Response

message
string
Success message
data
object
Released project resource object
IDs of related services that were also released (equipment only)
Number of related services released (equipment only)

Example Request

curl -X POST "https://api.mantis.example/api/projects/resources/release/" \
  -H "Content-Type: application/json" \
  -H "Authorization: Bearer YOUR_TOKEN" \
  -d '{
    "id": 10
  }'

Example Response (Equipment)

{
  "message": "Equipo liberado correctamente.",
  "data": {
    "id": 10,
    "project_id": 1,
    "type_resource": "EQUIPO",
    "resource_item_id": 5,
    "resource_item_code": "BS-001",
    "resource_item_name": "Batería Sanitaria Hombre",
    "detailed_description": "ALQUILER / BS-001 / BATERIA SANITARIA HOMBRE",
    "physical_equipment_code": 0,
    "cost": "175.00",
    "is_active": true,
    "is_retired": true,
    "operation_start_date": "2025-10-05",
    "operation_end_date": "2025-12-31"
  },
  "related_services_released": [11],
  "related_services_count": 1
}

Example Response (Service)

{
  "message": "Servicio liberado correctamente.",
  "data": {
    "id": 11,
    "project_id": 1,
    "type_resource": "SERVICIO",
    "resource_item_id": 100,
    "resource_item_code": "PEISOL-SERV00",
    "resource_item_name": "Servicio General",
    "detailed_description": "MANTENIMIENTO / BS-001",
    "physical_equipment_code": 5,
    "cost": "60.00",
    "is_active": true,
    "is_retired": true,
    "operation_start_date": "2025-10-05",
    "operation_end_date": "2025-12-31"
  }
}
Difference from Delete: Release marks resources as retired (is_retired=true) and preserves the historical record, while Delete permanently removes the assignment.
Automatic Service Release: When equipment is released, all associated maintenance and services are automatically retired as well.

Get Project Resources

Retrieve all resources assigned to a specific project.
GET /api/projects/<project_id>/resources/

Path Parameters

project_id
integer
required
ID of the project

Response

data
array
Array of project resource objects

Example Request

curl -X GET "https://api.mantis.example/api/projects/1/resources/" \
  -H "Authorization: Bearer YOUR_TOKEN"

Example Response

{
  "data": [
    {
      "id": 10,
      "project_id": 1,
      "type": "BTSNHM",
      "type_equipment_display": "BATERIA SANITARIA HOMBRE",
      "resource_item_id": 5,
      "resource_item_code": "BS-001",
      "resource_item_name": "Batería Sanitaria Hombre",
      "detailed_description": "ALQUILER / BS-001 / BATERIA SANITARIA HOMBRE",
      "cost": 175.00,
      "frequency_type": "WEEK",
      "interval_days": 0,
      "weekdays": [1, 3, 5],
      "monthdays": null,
      "operation_start_date": "2025-10-05",
      "operation_end_date": "2025-12-31",
      "is_active": true,
      "is_selected": false,
      "type_resource": "EQUIPO",
      "is_retired": false,
      "retirement_date": null,
      "retirement_reason": null,
      "is_confirm_delete": false,
      "is_deleteable": true,
      "notes": null
    }
  ]
}

Error Codes

The Project Resources API uses standard HTTP status codes:
200
OK
Request successful
201
Created
Resource successfully created
204
No Content
Resource successfully deleted
400
Bad Request
Invalid request parameters or validation error
  • Missing required fields
  • Invalid date format
  • Resource already rented
  • Resource used in custody chain (cannot delete)
  • Invalid frequency configuration
404
Not Found
  • Project not found or inactive
  • Resource not found or inactive
  • ProjectResourceItem not found
500
Internal Server Error
Unexpected server error (check logs)

Validation Rules

Adding Resources

  • project_id, resource_id, cost, and operation_start_date are required
  • Resource must have status_disponibility of DISPONIBLE (not RENTADO)
  • Dates must be in YYYY-MM-DD format
  • operation_end_date cannot be earlier than operation_start_date
  • For frequency_type="DAY": interval_days must be ≥ 1
  • For frequency_type="WEEK": weekdays array must have at least one value (0-6)
  • For frequency_type="MONTH": monthdays array must have at least one value (1-31)

Updating Resources

  • Cannot update retired resources (is_retired=True)
  • Cannot update resources in inactive projects
  • Frequency type changes must include appropriate interval/weekdays/monthdays

Deleting Resources

  • Cannot delete resources used in custody chains
  • Resource must exist and belong to an active project

Releasing Resources

  • Cannot release already retired resources
  • When releasing equipment, all linked services are automatically retired

Data Model: ProjectResourceItem

The ProjectResourceItem model represents the assignment of a resource to a project:
FieldTypeDescription
idIntegerPrimary key
projectForeignKeyReference to Project
resource_itemForeignKeyReference to ResourceItem
type_resourceStringEQUIPO or SERVICIO
detailed_descriptionStringFormatted description
physical_equipment_codeIntegerPhysical equipment ID (for services)
costDecimalCost per period
frequency_typeStringDAY, WEEK, or MONTH
interval_daysIntegerDays between occurrences
weekdaysJSONArray of weekday numbers
monthdaysJSONArray of month day numbers
operation_start_dateDateStart of operation
operation_end_dateDateEnd of operation
is_retiredBooleanRetirement status
retirement_dateDateDate of retirement
retirement_reasonTextReason for retirement
is_activeBooleanActive flag
is_deletedBooleanSoft delete flag

Get Complete Project Information

Retrieve comprehensive information about a project including all work orders, custody chains, sheet details, and metadata.
GET /api/projects/all-info/{project_id}/
project_id
integer
required
ID of the project to retrieve complete information for

Response

Returns a detailed object containing:
success
boolean
Indicates if the request was successful
data
object
Complete project information object
total_custody_chains
integer
Total custody chains across all work orders

Example Response

{
  "success": true,
  "data": {
    "project": {
      "id": 5,
      "partner_id": 1,
      "partner_name": "PETROECUADOR",
      "location": "Camp Site A",
      "cardinal_point": "NORTE",
      "contact_name": "John Doe",
      "contact_phone": "+593987654321",
      "start_date": "2025-03-01",
      "end_date": null,
      "is_closed": false
    },
    "work_orders": [
      {
        "id": 1,
        "series_code": "PSL-PS-2025-0001",
        "issue_date": "2025-03-01",
        "period_start": "2025-03-01",
        "period_end": "2025-03-15",
        "status": "LIQUIDATED",
        "subtotal": "1500.00",
        "tax_amount": "225.00",
        "total": "1725.00",
        "details": [
          {
            "id": 1,
            "equipment": "BATERIA SANITARIA HOMBRE",
            "quantity": 15,
            "unit_price": "50.00",
            "total_line": "750.00",
            "resource_item_code": "BS-001"
          }
        ],
        "details_count": 1,
        "custody_chains": [
          {
            "id": 42,
            "consecutive": 1,
            "activity_date": "2025-03-01",
            "location": "Camp Site A",
            "status": "COMPLETED",
            "total_gallons": "500.00",
            "technical": {
              "id": 3,
              "first_name": "Juan",
              "last_name": "Pérez"
            },
            "vehicle": {
              "id": 7,
              "no_plate": "ABC-123",
              "brand": "Ford",
              "model": "F-150"
            },
            "details_count": 3
          }
        ],
        "custody_chains_count": 1,
        "maintenance_sheets_count": 2
      }
    ],
    "work_orders_count": 1,
    "total_custody_chains": 1
  }
}
This endpoint is useful for generating comprehensive project reports, dashboards, and export functionality. It includes complete nested data structures with metadata for audit purposes.

Best Practices

Use Batch Creation

When adding multiple resources to a project, include them all in a single POST request array for better performance.

Release Instead of Delete

Use the release endpoint to retire resources instead of deleting them to preserve historical records and audit trails.

Check Availability First

Before assigning resources, query the available resources endpoint to ensure equipment is not already in use.

Sync Maintenance Services

When updating equipment frequency or dates, related maintenance services are automatically synchronized.

Handle Date Ranges Carefully

Ensure operation dates fall within the project’s start and end dates for proper scheduling.

Build docs developers (and LLMs) love