Create Template

Creates a new route template. A template defines a reusable sequence of process steps that can later be applied to jobs to generate manufacturing paths. Each step requires a name and optionally a physical location. The system automatically assigns zero-based order values, sets optional to false, and sets dependencyType to "physical" for all steps.

After creating a template, use the Apply Template endpoint to create paths from it on specific jobs.

Request

Request Body

FieldTypeRequiredDescription
namestringYesA human-readable name for the template (e.g. "Standard CNC Machining"). Must be a non-empty string. Leading and trailing whitespace is trimmed.
stepsarrayYesAn ordered array of step definitions. Must contain at least one step. The array order determines the order field on each step.
steps[].namestringYesThe name of the process step (e.g. "CNC Milling", "Inspection").
steps[].locationstringNoThe physical location where this step is performed (e.g. "Bay A", "QC Lab").

Response

201 Created

Returned when the template is successfully created. The response contains the complete TemplateRoute object with server-generated fields.

FieldTypeDescription
idstringServer-generated unique identifier (prefixed with tmpl_)
namestringThe template name as provided (trimmed)
stepsTemplateStep[]The step definitions with server-assigned order, optional, and dependencyType
steps[].namestringStep name as provided
steps[].ordernumberZero-based position assigned from array index
steps[].locationstring | undefinedLocation as provided, if any
steps[].optionalbooleanAlways false for newly created templates
steps[].dependencyType'physical' | 'preferred' | 'completion_gate'Always "physical" for newly created templates
createdAtstringISO 8601 timestamp of when the template was created
updatedAtstringISO 8601 timestamp — same as createdAt for newly created templates

400 Bad Request

Returned when the request body fails validation.

ConditionMessage
name is missing or empty"name is required"
steps is missing or empty array"steps must have at least one item"

500 Internal Server Error

Returned if an unhandled error occurs while persisting the template.

ConditionMessage
Database write failure"Internal Server Error"

Examples

Request — Template with locations

curl -X POST http://localhost:3000/api/templates \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Standard CNC Machining",
    "steps": [
      { "name": "Raw Material Inspection", "location": "QC Lab" },
      { "name": "CNC Milling", "location": "CNC Room" },
      { "name": "Deburring", "location": "Finishing Bay" },
      { "name": "Final Inspection", "location": "QC Lab" }
    ]
  }'

Response — Template with locations

{
  "id": "tmpl_abc123",
  "name": "Standard CNC Machining",
  "steps": [
    {
      "name": "Raw Material Inspection",
      "order": 0,
      "location": "QC Lab",
      "optional": false,
      "dependencyType": "physical"
    },
    {
      "name": "CNC Milling",
      "order": 1,
      "location": "CNC Room",
      "optional": false,
      "dependencyType": "physical"
    },
    {
      "name": "Deburring",
      "order": 2,
      "location": "Finishing Bay",
      "optional": false,
      "dependencyType": "physical"
    },
    {
      "name": "Final Inspection",
      "order": 3,
      "location": "QC Lab",
      "optional": false,
      "dependencyType": "physical"
    }
  ],
  "createdAt": "2024-01-15T10:30:00.000Z",
  "updatedAt": "2024-01-15T10:30:00.000Z"
}

Request — Minimal template (no locations)

curl -X POST http://localhost:3000/api/templates \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Quick Assembly",
    "steps": [
      { "name": "Assembly" },
      { "name": "Test" }
    ]
  }'

Response — Minimal template

{
  "id": "tmpl_def456",
  "name": "Quick Assembly",
  "steps": [
    {
      "name": "Assembly",
      "order": 0,
      "optional": false,
      "dependencyType": "physical"
    },
    {
      "name": "Test",
      "order": 1,
      "optional": false,
      "dependencyType": "physical"
    }
  ],
  "createdAt": "2024-01-15T11:00:00.000Z",
  "updatedAt": "2024-01-15T11:00:00.000Z"
}

Notes

  • The id field is generated server-side using the tmpl_ prefix and cannot be specified in the request body.
  • Step order values are assigned automatically from the array index (0, 1, 2, ...). You cannot specify custom order values in the request.
  • All steps are created with optional: false and dependencyType: "physical" by default. To change these values, use the Update Template endpoint after creation.
  • There is no uniqueness constraint on template name. Multiple templates can share the same name.
  • The name field is trimmed of leading and trailing whitespace before storage.
  • Creating a template does not create any paths or affect any jobs. Templates are inert until applied.