Create subtasks in a task of a task plan

Allows creating one or more subtasks within an existing task of a task plan (maintenance form), without depending on the Fracttal UI.

POST https://app.fracttal.com/api/tasks_subtasks

Input parameters — Required

Sent in the request body.

ParameterTypeRequiredDescription
id_taskintegerYesId of the existing task within the task plan where the subtasks will be created. Obtained from the plan's task list/detail.
is_cyclicalbooleanYesIndicates whether the task handles iterations. Must match the task's actual state — if it doesn't, the request is rejected with 409.
num_iterationsintegerYes, only if is_cyclical = trueNumber of iterations of the task. Integer greater than 0.
subtasksarray of objectsYesArray with at least one element; each element is the configuration of a subtask. The array order determines the assigned order_number. See subtasks parameters below for each element's fields.

Input parameters — Optional

None at the top level — all optional fields of this endpoint are part of each subtasks element (see below).


subtasks parameters

Each element of the subtasks array represents a subtask to create, with the following fields:

Required

ParameterTypeRequiredDescription
id_task_form_item_typeintegerYesType of subtask to create. Determines which other fields apply — see the Subtask types table below. Valid values: 1 to 8.
descriptionstringYesText shown as the label/question of the subtask when executing the task (e.g. "Describe el procedimiento realizado"). Cannot be empty.

Subtask types (id_task_form_item_type)

IdTypeRelevant additional fields
1TextNone.
2Yes/NoNone.
3NumberNone.
4CheckboxNone.
5Meter readingRequires id_unit or unit_description (see Optional). If the task has linked assets, the response may include message: "ERROR_CONFIG_METERS_ASSETS".
6GPS locationNone.
7ListRequires dropdown_options with at least 2 elements (see Optional).
8Date and timeNone.

Optional

ParameterTypeRequiredDescription
is_requiredbooleanOptionalDefault: false.
attachments_requiredbooleanOptionalDefault: false.
task_form_item_group_descriptionstringOptionalGroup/section name. If provided, a similar group is looked up (fuzzy match); if none exists, it's created automatically.
id_unitintegerOptional (required if id_task_form_item_type = 5 and unit_description is not sent)Unit of measure id in companies.units. If it doesn't exist, returns 422.
unit_descriptionstringOptional (required if id_task_form_item_type = 5 and id_unit is not sent)Unit description; if there's no match by similarity, it's created automatically.
dropdown_optionsarrayOptional (required if id_task_form_item_type = 7, minimum 2 elements)Each element: { "description": string }.
iterationsobjectOptionalOnly applies if is_cyclical = true (at the request level). Format: { "iteration_1": true, "iteration_3": true, ... }. If any iteration_n has n > num_iterations, returns 400. If omitted or sent empty, the subtask does not participate in any iteration.

Output parameters

ParameterTypeDescription
idintegerId generated for the created subtask.
id_taskintegerId of the task it belongs to.
id_task_form_item_typeintegerSubtask type.
descriptionstringSubtask description.
order_numberintegerOrder automatically assigned by the server.
is_requiredbooleanWhether the subtask is mandatory.
attachments_requiredbooleanWhether it requires attachments.
id_task_form_item_groupintegerId of the associated group/section (created or reused).
iterationsobjectIterations in which the subtask participates.
dropdown_optionsarrayList options (type 7 only).
messagestringERROR_CONFIG_METERS_ASSETS when the task has linked assets and a type 5 (meter) subtask is added; requires additional per-asset configuration.
totalintegerNumber of affected assets — present only together with ERROR_CONFIG_METERS_ASSETS.

Errors

CodeCause
400id_task not provided; is_cyclical not provided; is_cyclical=true without num_iterations; num_iterations ≤ 0; subtasks empty or missing; id_task_form_item_type outside 1–8; empty description; type 5 without id_unit nor unit_description; type 7 with fewer than 2 dropdown_options or an option without description; some iteration_n with n > num_iterations.
401No authentication.
403No edit permission on TASKS > PLAN_TASKS.
404id_task does not exist.
409is_cyclical or num_iterations in the body doesn't match the task's actual state.
415Content-Type other than application/json.
422id_unit does not exist in companies.units.

Example

Request body (cyclical task, 4 iterations)

{
  "id_task": 1001,
  "is_cyclical": true,
  "num_iterations": 4,
  "subtasks": [
    {
      "id_task_form_item_type": 1,
      "description": "Describe el procedimiento realizado",
      "iterations": { "iteration_4": true },
      "is_required": false,
      "attachments_required": false
    },
    {
      "id_task_form_item_type": 5,
      "description": "Lectura de presión hidráulica",
      "task_form_item_group_description": "Sistema Hidráulico",
      "id_unit": 42,
      "iterations": { "iteration_1": true, "iteration_2": true, "iteration_3": true, "iteration_4": true },
      "is_required": true,
      "attachments_required": false
    },
    {
      "id_task_form_item_type": 7,
      "description": "Estado general del equipo",
      "task_form_item_group_description": "Inspección General",
      "dropdown_options": [
        { "description": "Bueno" },
        { "description": "Regular" },
        { "description": "Malo" }
      ],
      "iterations": { "iteration_2": true, "iteration_4": true },
      "is_required": true,
      "attachments_required": true
    }
  ]
}

Response 200

{
  "success": true,
  "message": "200",
  "data": [
    {
      "id": 501,
      "id_task": 1001,
      "id_task_form_item_type": 1,
      "description": "Describe el procedimiento realizado",
      "order_number": 1,
      "is_required": false,
      "attachments_required": false,
      "id_task_form_item_group": null,
      "iterations": { "iteration_4": true },
      "dropdown_options": null
    },
    {
      "id": 502,
      "id_task": 1001,
      "id_task_form_item_type": 5,
      "description": "Lectura de presión hidráulica",
      "order_number": 2,
      "is_required": true,
      "attachments_required": false,
      "id_task_form_item_group": 12,
      "iterations": { "iteration_1": true, "iteration_2": true, "iteration_3": true, "iteration_4": true },
      "dropdown_options": null
    },
    {
      "id": 503,
      "id_task": 1001,
      "id_task_form_item_type": 7,
      "description": "Estado general del equipo",
      "order_number": 3,
      "is_required": true,
      "attachments_required": true,
      "id_task_form_item_group": 13,
      "iterations": { "iteration_2": true, "iteration_4": true },
      "dropdown_options": [
        { "id": 1, "description": "Bueno" },
        { "id": 2, "description": "Regular" },
        { "id": 3, "description": "Malo" }
      ]
    }
  ],
  "total": 3
}

Response — meter-type subtask on a task with linked assets

{
  "success": true,
  "message": "ERROR_CONFIG_METERS_ASSETS",
  "data": [
    {
      "id": 504,
      "id_task": 1001,
      "id_task_form_item_type": 5,
      "description": "Lectura de nivel de aceite",
      "order_number": 4,
      "is_required": true,
      "attachments_required": false,
      "id_task_form_item_group": null,
      "iterations": {},
      "dropdown_options": null
    }
  ],
  "total": 3
}

OpenAPI definition

{
  "openapi": "3.1.0",
  "info": {
    "title": "tasks",
    "version": "2-En"
  },
  "servers": [
    {
      "url": "https://app.fracttal.com/api/tasks_subtasks"
    }
  ],
  "security": [
    {}
  ],
  "paths": {
    "/": {
      "post": {
        "summary": "Create subtasks in a task of a task plan",
        "description": "",
        "operationId": "create-subtasks-in-a-task-of-a-task-plan",
        "deprecated": false,
        "security": [],
        "requestBody": {
          "required": true,
          "content": {
            "application/json": {
              "schema": {
                "type": "object",
                "required": ["id_task", "is_cyclical", "subtasks"],
                "properties": {
                  "id_task": { "type": "integer" },
                  "is_cyclical": { "type": "boolean" },
                  "num_iterations": { "type": "integer" },
                  "subtasks": {
                    "type": "array",
                    "minItems": 1,
                    "items": {
                      "type": "object",
                      "required": ["id_task_form_item_type", "description"],
                      "properties": {
                        "id_task_form_item_type": { "type": "integer", "minimum": 1, "maximum": 8 },
                        "description": { "type": "string" },
                        "is_required": { "type": "boolean", "default": false },
                        "attachments_required": { "type": "boolean", "default": false },
                        "task_form_item_group_description": { "type": "string" },
                        "id_unit": { "type": "integer" },
                        "unit_description": { "type": "string" },
                        "dropdown_options": {
                          "type": "array",
                          "items": { "type": "object", "properties": { "description": { "type": "string" } } }
                        },
                        "iterations": { "type": "object", "additionalProperties": { "type": "boolean" } }
                      }
                    }
                  }
                }
              }
            }
          }
        },
        "responses": {
          "200": { "description": "Subtasks created successfully" },
          "400": { "description": "Bad Request" },
          "401": { "description": "Unauthorized" },
          "403": { "description": "Forbidden" },
          "404": { "description": "Not Found" },
          "409": { "description": "Conflict" },
          "415": { "description": "Unsupported Media Type" },
          "422": { "description": "Unprocessable Entity" }
        }
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": false,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true
}
Response
200
Language
LoadingLoading…