Resources (Machines)
Resources represent the logical machines and devices managed by 2log (e.g. a laser cutter, a 3D printer, or a suction system). Each resource is a bundle that combines a controller, a resource state, and a set of aspects that add capabilities like billing, logging, or QR code authentication.
Permissions
- Admins (
IS_ADMIN): full read/write access to all resource objects and properties. - All authenticated users: read-only access to a subset of public properties (see below).
Resource list
All resources are stored as a synchronized list at 2log.resources. This list is readable by any authenticated user, but only admins can add or remove entries.
List all resources
curl http://your-server/api/lists/2log.resources \
-H "Authorization: Bearer $TOKEN"
The response is a JSON array. Each item contains a data object with the resource properties and a uuid:
[
{
"data": {
"displayName": "Laser Cutter",
"resourceUid": "laser-cutter-01",
"systemType": "machines",
"controllerType": "genericPrimaryBundle",
"controllerState": 0,
"resourceState": 0,
"userName": "",
"userType": "",
"bundleType": "genericPrimaryBundle"
},
"uuid": "laser-cutter-01"
}
]
Public properties (visible to all authenticated users):
| Field | Type | Description |
|---|---|---|
displayName |
string | Human-readable name of the resource |
controllerState |
int | Current state of the controller |
systemType |
string | Resource category (e.g. machines, suctions) |
userType |
string | User-facing machine type label (free-form, e.g. Lasercutter, 3D-Drucker). Unlike systemType, this is a display label that can be chosen freely. |
resourceUid |
string | Unique resource identifier |
Admin-only properties (additionally visible to admins):
| Field | Type | Description |
|---|---|---|
controllerType |
string | Bundle type (e.g. genericPrimaryBundle, prusa3DPrinterBundle) |
resourceState |
int | Current resource state |
userName |
string | Name of the currently logged-in user |
bundleType |
string | Bundle type identifier |
Get a single resource
curl http://your-server/api/lists/2log.resources/laser-cutter-01 \
-H "Authorization: Bearer $TOKEN"
Resource objects (admin only)
Each resource bundle and its sub-components are also available as individual object resources. These endpoints require IS_ADMIN permission.
Resource bundle
Returns all properties of a resource bundle as an object:
curl http://your-server/api/objects/2log.resources.laser-cutter-01 \
-H "Authorization: Bearer $TOKEN"
The response wraps each property in a data field (standard QuickHub object format):
{
"displayName": {"data": "Laser Cutter"},
"resourceUid": {"data": "laser-cutter-01"},
"systemType": {"data": "machines"},
"controllerType": {"data": "genericPrimaryBundle"},
"controllerState": {"data": 0},
"resourceState": {"data": 0},
"userName": {"data": ""},
"userType": {"data": ""},
"imageScale": {"data": 1.0},
"imageCenterX": {"data": 0},
"imageCenterY": {"data": 0}
}
Resource sub-object
Returns the resource state object:
curl http://your-server/api/objects/2log.resources.laser-cutter-01.resource \
-H "Authorization: Bearer $TOKEN"
Controller sub-object
Returns the controller state object:
curl http://your-server/api/objects/2log.resources.laser-cutter-01.controller \
-H "Authorization: Bearer $TOKEN"
Aspects
Aspects are modular capabilities attached to a resource. Each aspect is accessible as an object resource at 2log.resources.{resourceUid}.{aspectName}. All aspect endpoints require IS_ADMIN permission.
The available aspects depend on the bundle type:
| Aspect name | genericPrimaryBundle |
prusa3DPrinterBundle |
genericSecondaryBundle |
Description |
|---|---|---|---|---|
billing |
yes | yes | – | Usage-based billing |
dblogs |
yes | yes | – | Database logging |
permissioncheck |
yes | yes | – | Permission validation |
dot |
yes | yes | – | 2log Dot hardware enabler |
qrcode |
yes | yes | – | QR code authentication |
secondary |
yes | – | – | Companion/secondary resource control |
billing – Usage-based billing
The billing aspect controls how usage of a resource is charged.
curl http://your-server/api/objects/2log.resources.laser-cutter-01.billing \
-H "Authorization: Bearer $TOKEN"
Properties:
| Property | Type | Description |
|---|---|---|
payingMode |
int | Billing mode (see table below) |
pricePerUnit |
int | Price per unit in cents |
unitDuration |
int | Duration of one billing unit (in seconds) |
employeesForFree |
bool | If true, employees (empl role) are not charged |
minimumCreditBalance |
int | Minimum credit balance required to start a session (in cents) |
Billing modes (payingMode):
| Value | Mode | Description |
|---|---|---|
| 0 | DISABLED | No billing |
| 1 | BILLING_BY_SESSION_TIME | Charged based on total session time |
| 2 | BILLING_BY_PRODUCTIVE_TIME | Charged based on productive (active) time only |
| 3 | BILLING_PER_JOB | Flat fee per job |
| 4 | BILLING_WHEN_ENABLED | Charged upon activation |
To update billing settings:
curl -X PUT http://your-server/api/objects/2log.resources.laser-cutter-01.billing/payingMode \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"data": 1}'
qrcode – QR code authentication
The QR code aspect manages how users authenticate at a machine using QR codes (scanned via the 2log mobile app).
curl http://your-server/api/objects/2log.resources.laser-cutter-01.qrcode \
-H "Authorization: Bearer $TOKEN"
Properties:
| Property | Type | Description |
|---|---|---|
mode |
int | QR code mode (see table below) |
code |
string | Current QR code value |
QR code modes (mode):
| Value | Mode | Description |
|---|---|---|
| 0 | DISABLED | QR code authentication is off |
| 1 | STATIC | A fixed QR code is used (defaults to the resource UID) |
| 2 | DYNAMIC | The server generates a new random code (12 characters) periodically |
Reading the current QR code
To read the current QR code value for a machine:
curl http://your-server/api/objects/2log.resources.laser-cutter-01.qrcode/code \
-H "Authorization: Bearer $TOKEN"
{"data": "A3xK9mP2qR7w"}
In static mode the code value stays the same (typically the resourceUid). In dynamic mode the server generates a new 12-character code automatically. To get the current code, simply read this property – the server always returns the currently valid value.
Tip
If you want to display a machine’s QR code in your own application or on an external display, poll thecode property periodically in dynamic mode to stay up to date. For real-time updates, consider using the QuickHub WebSocket protocol to subscribe to the 2log/resources/{resourceUid}/qrcode object resource.
Changing the QR code mode
curl -X PUT http://your-server/api/objects/2log.resources.laser-cutter-01.qrcode/mode \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"data": 2}'
dblogs – Database logging
The logging aspect tracks resource usage and writes log entries to the database.
curl http://your-server/api/objects/2log.resources.laser-cutter-01.dblogs \
-H "Authorization: Bearer $TOKEN"
| Property | Type | Description |
|---|---|---|
dbref |
string | Database reference identifier for this resource’s logs |
This aspect works together with the billing aspect: when a session ends, the billing information is automatically written as a log entry. The resulting logs can be queried via the getLogs service method.
permissioncheck – Permission validation
The permission check aspect verifies whether a user has the required permissions to use a resource. It works asynchronously – when a user attempts to authenticate, it queries the configured permission service and returns the result.
curl http://your-server/api/objects/2log.resources.laser-cutter-01.permissioncheck \
-H "Authorization: Bearer $TOKEN"
secondary – Companion resource control
The companion controller aspect links a primary resource to a secondary resource (e.g. linking a suction system to a laser cutter so that the suction starts automatically).
curl http://your-server/api/objects/2log.resources.laser-cutter-01.secondary \
-H "Authorization: Bearer $TOKEN"
Properties:
| Property | Type | Description |
|---|---|---|
resourceUid |
string | UID of the linked secondary resource |
interceptWhenNotRunning |
bool | Block the primary resource if the secondary is not running |
desiredResourceState |
int | Target state for the secondary resource |
forceInterception |
bool | Force interception regardless of state |
ready |
bool | Whether the secondary resource is ready |
dot – 2log Dot hardware enabler
The Dot aspect integrates with the physical 2log Dot device (an NFC/RFID reader attached to the machine).
curl http://your-server/api/objects/2log.resources.laser-cutter-01.dot \
-H "Authorization: Bearer $TOKEN"
| Property | Type | Description |
|---|---|---|
dotDeviceMapping |
string | Mapping identifier for the associated Dot hardware device |
Aspect lists
You can retrieve a flat list of all aspects of a given type across all resources. This is useful for getting an overview (e.g. all billing configurations or all QR codes at once).
The endpoint is a synchronized list at 2log.resources.{aspectType}:
# Get all billing aspects across all resources
curl http://your-server/api/lists/2log.resources.billing \
-H "Authorization: Bearer $TOKEN"
# Get all QR code aspects across all resources
curl http://your-server/api/lists/2log.resources.qrcode \
-H "Authorization: Bearer $TOKEN"
The valid aspect type values are: billing, dblogs, permissioncheck, secondary, dot, qrcode.
Creating and deleting resources
Resources are managed via the resources service. See the Service Reference for details.
Create a resource
curl -X POST http://your-server/api/services/resources/newController \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{
"name": "Laser Cutter",
"type": "machines",
"uid": "laser-cutter-01"
}'
Delete a resource
curl -X POST http://your-server/api/services/resources/deleteController \
-H "Authorization: Bearer $TOKEN" \
-H "Content-Type: application/json" \
-d '{"uid": "laser-cutter-01"}'