Get spare parts and supplies of an asset

Returns the (paginated) list of spare parts and supplies associated with an asset, with their code, description, quantity, unit of measure, status and origin (asset record or task plan). The asset is identified by its code.

Add-on required

General use — no specific add-on.

GET https://app.fracttal.com/api/items_spare_parts/
GET https://app.fracttal.com/api/items_spare_parts/{code}

The asset code is also accepted as part of the path. If it is sent both in the path and as the code parameter, the path value takes precedence.

Input parameters — Required

Sent as query params (or code in the path).

ParameterTypeRequiredDescription
codetextYesAsset code. It is a text value: leading zeros are preserved. The search is exact and case-sensitive, and spaces are significant.

Input parameters — Optional

ParameterTypeRequiredDescription
item_typetextNo (recommended)Asset type, from 1 to 5: 1 Locations, 2 Equipment, 3 Tools, 4 Spare parts and supplies, 5 Digital. An asset code is not unique and can be repeated across types; if the code matches more than one asset and item_type is not sent, the API responds 400 and returns no data. Always sending it is recommended.
starttextNoRecord from which the query starts. Default 0. A negative or non-numeric value responds 400.
limittextNoNumber of records per page. Default and maximum 100. A value lower than 1, greater than 100 or non-numeric responds 400.

An empty value in any of these parameters is treated as if it had not been sent.

Required permissions

The application authenticates with OAuth2 (client_credentials). Its permission group must have view on the assets module for Locations, Equipment and Spare Parts and Supplies, and in particular on the type of the queried asset. Without that permission the API responds with an authorization error (see the errors section).

What the query returns

  • Only spare parts and supplies are returned. Tools and other resource types of a task plan do not appear.
  • From the asset's task plan, only active, non-stopped tasks of active plans are included.
  • The same spare part can appear several times: once for the asset record and once for each plan task that uses it. Use origin and task to tell them apart. Quantities are never added together.
  • Inactive spare parts are also returned; they are identified by is_active = false.
  • Rows are sorted by origin (asset before task_plan) and then by code.
  • The API does not paginate automatically: if total is greater than the number of rows received, repeat the query by increasing start by the value of limit.

Output parameters

ParameterTypeDescription
successbooleantrue if the query was successful.
messagetext"200" on success; error code or message otherwise.
totalintegerTotal number of rows for the asset, before pagination — not the size of the returned page.
dataarray of objectsPage of results. See the structure in the next table.

Structure of each element in data:

ParameterTypeDescription
codetextSpare part or supply code.
descriptiontextSpare part or supply description.
qtynumberQuantity (decimals allowed). With origin = asset it is the quantity recorded in the asset record; with origin = task_plan it is the quantity per execution of the task.
unittextUnit of measure. null if the spare part has no unit.
is_activebooleantrue if the spare part is active.
origintextasset: comes from the asset record. task_plan: comes from a task plan of the asset.
tasktextDescription of the plan task that uses the resource. null when origin is asset.

Errors

CodeCause
400code is missing; item_type is outside the 1 to 5 range; start or limit are invalid; or the code matches more than one asset (send item_type). Details are in data[0].ERROR.
401The application does not have view permission on the type of the queried asset. It arrives with data.Error = "UNAUTHORIZED_ENDPOINT".
404The code does not exist in the company. Details are in data[0].ERROR.
INVALID_TOKENInvalid token, or not authorized for the company.
INVALID_ENDPOINTThe service is not enabled for the application.
UNAUTHORIZED_ENDPOINTThe application's permission group does not meet the required permission.
UNAUTHORIZED_USEThe company does not have API usage enabled.
ERROR_SQLUnhandled internal error.

Note on authorization errors

A permissions error can arrive in two forms: with message: "401" and data.Error = "UNAUTHORIZED_ENDPOINT", or with message: "UNAUTHORIZED_ENDPOINT" and data: null. In both cases it means the application's permission group does not have the required permission. In 400 and 404 error responses, the total field arrives as text ("0").


Example

Request

GET https://app.fracttal.com/api/items_spare_parts/?code=EQ-0042&item_type=2&start=0&limit=50

Response 200

{
  "success": true,
  "message": "200",
  "total": 3,
  "data": [
    {
      "code": "REP-001",
      "description": "Rodamiento 6002 { REP-001 }",
      "qty": 2,
      "unit": "Unidad",
      "is_active": true,
      "origin": "asset",
      "task": null
    },
    {
      "code": "REP-002",
      "description": "Filtro de aceite { REP-002 }",
      "qty": 1,
      "unit": "Litros",
      "is_active": true,
      "origin": "task_plan",
      "task": "Mantenimiento cada 250 hr"
    },
    {
      "code": "REP-002",
      "description": "Filtro de aceite { REP-002 }",
      "qty": 4,
      "unit": "Litros",
      "is_active": false,
      "origin": "task_plan",
      "task": "Mantenimiento anual"
    }
  ]
}

Response — Asset without spare parts (200)

{
  "success": true,
  "message": "200",
  "total": 0,
  "data": []
}

Response — Missing code (400)

{
  "success": false,
  "message": "400",
  "total": "0",
  "data": [
    { "ERROR": "code is required" }
  ]
}

Response — Repeated code without item_type (400)

{
  "success": false,
  "message": "400",
  "total": "0",
  "data": [
    { "ERROR": "code matches more than one item, item_type is required: EQ-0042" }
  ]
}

Response — Code does not exist (404)

{
  "success": false,
  "message": "404",
  "total": "0",
  "data": [
    { "ERROR": "code does not exist: EQ-9999" }
  ]
}

Response — No permission on the asset type (401)

{
  "success": false,
  "message": "401",
  "data": { "Error": "UNAUTHORIZED_ENDPOINT" }
}

OpenAPI definition

{
  "openapi": "3.1.0",
  "info": {
    "title": "Spare parts and supplies of an asset",
    "version": "2-En"
  },
  "servers": [
    { "url": "https://app.fracttal.com/api/items_spare_parts" }
  ],
  "security": [{}],
  "paths": {
    "/": {
      "get": {
        "summary": "Get spare parts and supplies of an asset",
        "description": "",
        "operationId": "get-spare-parts-and-supplies-of-an-asset",
        "deprecated": false,
        "security": []
      }
    }
  },
  "x-readme": {
    "headers": [],
    "explorer-enabled": false,
    "proxy-enabled": true
  },
  "x-readme-fauxas": true
}
Path Params
string
required
Response
200
Language
LoadingLoading…