|
| 1 | +# Custom Fields |
| 2 | + |
| 3 | +<aside class="notice"> |
| 4 | + This feature requires the <b>Print Farm</b> plan. |
| 5 | +</aside> |
| 6 | + |
| 7 | +Custom Fields allow you to add your own data-fields inside SimplyPrint. |
| 8 | + |
| 9 | +[Read more about Custom Fields on our Helpdesk](https://help.simplyprint.io/en/article/all-about-the-custom-fields-feature-4dd5if/) |
| 10 | + |
| 11 | +## List custom fields |
| 12 | + |
| 13 | +`POST /{id}/custom_fields/Get` |
| 14 | + |
| 15 | +> Example request |
| 16 | +
|
| 17 | +```shell |
| 18 | +curl -X POST https://api.simplyprint.io/{id}/custom_fields/Get \ |
| 19 | + -H 'accept: application/json' \ |
| 20 | + -H "X-API-KEY: {API_KEY}" \ |
| 21 | + -F "page=1" -F "page_size=10" |
| 22 | +``` |
| 23 | + |
| 24 | +> Example response |
| 25 | +
|
| 26 | +```json |
| 27 | +{ |
| 28 | + "status": true, |
| 29 | + "message": null, |
| 30 | + "data": [ |
| 31 | + { |
| 32 | + "id": 7, |
| 33 | + "fieldId": "student_id", |
| 34 | + "fieldLabel": "Student ID", |
| 35 | + "fieldDescription": "", |
| 36 | + "fieldPlaceholder": null, |
| 37 | + "fieldType": "text", |
| 38 | + "fieldOptions": null, |
| 39 | + "category": "print", |
| 40 | + "subCategory": [ |
| 41 | + "user_file", |
| 42 | + "print_queue", |
| 43 | + "print_job" |
| 44 | + ], |
| 45 | + "required": false, |
| 46 | + "enabled": true, |
| 47 | + "defaultValue": null, |
| 48 | + "visibleRequiredPermissions": null, |
| 49 | + "editRequiredPermissions": null, |
| 50 | + "visibleToGroups": [], |
| 51 | + "editableByGroups": [], |
| 52 | + "validation": null, |
| 53 | + "createdByUser": -1, |
| 54 | + "user": "John Doe", |
| 55 | + "forPrinters": [], |
| 56 | + "forModels": [], |
| 57 | + "forGroups": [], |
| 58 | + "showOnRegistration": null, |
| 59 | + "showBeforeStartPrint": null, |
| 60 | + "position": 0, |
| 61 | + "created": "2024-09-07T13:46:59+00:00", |
| 62 | + "updated": "2024-09-07T13:46:59+00:00" |
| 63 | + } |
| 64 | + ], |
| 65 | + "page_amount": 1, |
| 66 | + "total": 1 |
| 67 | +} |
| 68 | +``` |
| 69 | + |
| 70 | +### Request |
| 71 | + |
| 72 | +| Parameter | Type | Required | Description | |
| 73 | +|-------------|---------|----------|-----------------------------------------------------------------------------------------------------------------| |
| 74 | +| `page` | integer | yes | Which page to show | |
| 75 | +| `page_size` | integer | yes | Amount of items per page (1-100) | |
| 76 | +| `search` | string | no | The search filter to apply | |
| 77 | +| `sort_id` | string | no | What key to sort on (id, fieldId, fieldLabel, fieldDescription, fieldType, category, enabled, created, updated) | |
| 78 | +| `sort_dir` | string | no | Sort direction (`asc`, `desc`) | |
| 79 | + |
| 80 | +### Response |
| 81 | + |
| 82 | +| Parameter | Type | Description | |
| 83 | +|-----------|---------|-------------------------------------| |
| 84 | +| `status` | boolean | True if the request was successful. | |
| 85 | +| `message` | string | Error message if `status` is false. | |
| 86 | +| `data` | array | List of custom fields. | |
| 87 | + |
| 88 | +## Create or update a custom field |
| 89 | + |
| 90 | +`POST /{id}/custom_fields/Save` |
| 91 | + |
| 92 | +> Example request |
| 93 | +
|
| 94 | +```shell |
| 95 | +curl -X POST https://api.simplyprint.io/{id}/custom_fields/Save \ |
| 96 | + -H 'accept: application/json' \ |
| 97 | + -H 'Content-Type: application/json' \ |
| 98 | + -H 'X-API-KEY: {API_KEY}' \ |
| 99 | + -d '{"category":"print","subCategory":["user_file","print_queue","print_job"],"fieldType":"text","fieldId":"student_id","fieldLabel":"Student ID","required":false,"enabled":true}' |
| 100 | +``` |
| 101 | + |
| 102 | +> Example response |
| 103 | +
|
| 104 | +```json |
| 105 | +{ |
| 106 | + "status": true, |
| 107 | + "message": null |
| 108 | +} |
| 109 | +``` |
| 110 | + |
| 111 | +### Request |
| 112 | + |
| 113 | +| Parameter | Type | Required | Description | |
| 114 | +|------------------------|---------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 115 | +| `id` | integer | no | If you want to update an existing custom field, specify this | |
| 116 | +| `category` | string | yes | One of `print`, `user`, `printer`, `filament` | |
| 117 | +| `subCategory` | array | no | Array of subcategories. Valid subcategories: `print_queue`, `print_job`, `user_file` | |
| 118 | +| `fieldId` | string | yes | ID of the field | |
| 119 | +| `fieldType` | string | yes | One of `boolean`, `text`, `longtext`, `number`, `date`, `datetime`, `phone`, `email`, `url`, `select`, `multiselect`, `radio`, `checkbox` | |
| 120 | +| `fieldLabel` | string | yes | Label of the field | |
| 121 | +| `fieldOptions` | object | no | Field options. An object with one entry, `options`, whose value is an array of `{label: string, value: string}` | |
| 122 | +| `FieldDescription` | string | no | Description of the field | |
| 123 | +| `fieldPlaceholder` | string | no | Placeholder text for the field | |
| 124 | +| `required` | boolean | yes | Whether the field is required | |
| 125 | +| `defaultValue` | object | no | Default value of the field. Object key should be either `string`, `number`, `boolean`, `date`, `options`, with the appropriate value type | |
| 126 | +| `validation` | object | no | Validation rules for the field. Object keys can be any of `stringRegex`, `stringMinLength`, `stringMaxLength`, `numberAllowDecimals`, `numberMinValue`, `numberMaxValue`, `validationMessage` | |
| 127 | +| `forPrinters` | array | no | Array of printer IDs the field should be visible for | |
| 128 | +| `forModels` | array | no | Array of model IDs the field should be visible for | |
| 129 | +| `forGroups` | array | no | Array of group IDs the field should be visible for | |
| 130 | +| `showOnRegistration` | boolean | no | Whether the field should be shown on registration | |
| 131 | +| `showBeforeStartPrint` | boolean | no | Whether the field should be shown before starting a print | |
| 132 | + |
| 133 | +### Response |
| 134 | + |
| 135 | +| Parameter | Type | Description | |
| 136 | +|-----------|---------|-------------------------------------| |
| 137 | +| `status` | boolean | True if the request was successful. | |
| 138 | +| `message` | string | Error message if `status` is false. | |
| 139 | + |
| 140 | +## Enable or disable a custom field |
| 141 | + |
| 142 | +`POST /{id}/custom_fields/SetEnabled` |
| 143 | + |
| 144 | +> Example request |
| 145 | +
|
| 146 | +```shell |
| 147 | +curl -X POST https://api.simplyprint.io/{id}/custom_fields/SetEnabled \ |
| 148 | + -H 'accept: application/json' \ |
| 149 | + -H 'Content-Type: application/json' \ |
| 150 | + -H 'X-API-KEY: {API_KEY}' \ |
| 151 | + -d '{"id": 123, "enabled": true}' |
| 152 | +``` |
| 153 | + |
| 154 | +> Example response |
| 155 | +
|
| 156 | +```json |
| 157 | +{ |
| 158 | + "status": true, |
| 159 | + "message": null |
| 160 | +} |
| 161 | +``` |
| 162 | + |
| 163 | +### Request |
| 164 | + |
| 165 | +| Parameter | Type | Required | Description | |
| 166 | +|-----------|---------|----------|---------------------------------------------------------------------------| |
| 167 | +| `id` | integer | yes | ID of the custom field to enable or disable | |
| 168 | +| `enabled` | boolean | yes | Whether the custom field should be enabled (`true`) or disabled (`false`) | |
| 169 | + |
| 170 | +### Response |
| 171 | + |
| 172 | +| Parameter | Type | Description | |
| 173 | +|-----------|---------|-------------------------------------| |
| 174 | +| `status` | boolean | True if the request was successful. | |
| 175 | +| `message` | string | Error message if `status` is false. | |
| 176 | + |
| 177 | +## Delete custom fields |
| 178 | + |
| 179 | +`GET /{id}/custom_fields/Delete` |
| 180 | + |
| 181 | +> Example request |
| 182 | +
|
| 183 | +```shell |
| 184 | +curl https://api.simplyprint.io/{id}/custom_fields/Delete?id=123 \ |
| 185 | +-H 'accept: application/json' \ |
| 186 | +-H 'X-API-KEY: {API_KEY}' |
| 187 | +``` |
| 188 | + |
| 189 | +> Example request with multiple IDs |
| 190 | +
|
| 191 | +```shell |
| 192 | +curl https://api.simplyprint.io/{id}custom_fields/Delete?ids=123,124,125 \ |
| 193 | +-H 'accept: application/json' \ |
| 194 | +-H 'X-API-KEY: {API_KEY}' |
| 195 | +``` |
| 196 | + |
| 197 | +> Example response |
| 198 | +
|
| 199 | +```json |
| 200 | +{ |
| 201 | + "status": true, |
| 202 | + "message": null |
| 203 | +} |
| 204 | +``` |
| 205 | + |
| 206 | +### Request |
| 207 | + |
| 208 | +| Parameter | Type | Required | Description | |
| 209 | +|-----------|---------|--------------------------------|----------------------------------------------------------------------------------------------------| |
| 210 | +| `id` | integer | yes (if `ids` is not provided) | The ID of the custom field to delete. | |
| 211 | +| `ids` | string | yes (if `id` is not provided) | A comma-separated list of custom field IDs to delete. Valid if multiple fields need to be removed. | |
| 212 | + |
| 213 | +### Response |
| 214 | + |
| 215 | +| Parameter | Type | Description | |
| 216 | +|-----------|---------|-------------------------------------| |
| 217 | +| `status` | boolean | True if the request was successful. | |
| 218 | +| `message` | string | Error message if `status` is false. | |
| 219 | + |
| 220 | +## Custom field submission value |
| 221 | + |
| 222 | +The value of a custom field when submitted via the API is an object with a key corresponding to the field type. |
| 223 | +See the examples to the right for the different field types. |
| 224 | + |
| 225 | +> A text field would have a value like this: |
| 226 | +
|
| 227 | +```json |
| 228 | +{ |
| 229 | + "string": "1234567890" |
| 230 | +} |
| 231 | +``` |
| 232 | + |
| 233 | +> A number field would have a value like this: |
| 234 | +
|
| 235 | +```json |
| 236 | +{ |
| 237 | + "number": 1234567890 |
| 238 | +} |
| 239 | +``` |
| 240 | + |
| 241 | +> A date field would have a value like this: |
| 242 | +
|
| 243 | +```json |
| 244 | +{ |
| 245 | + "date": "2024-09-07" |
| 246 | +} |
| 247 | +``` |
| 248 | + |
| 249 | +> A select field would have a value like this: |
| 250 | +
|
| 251 | +```json |
| 252 | +{ |
| 253 | + "string": "Selected option" |
| 254 | +} |
| 255 | +``` |
| 256 | + |
| 257 | +> A multi-select field would have a value like this: |
| 258 | +
|
| 259 | +```json |
| 260 | +{ |
| 261 | + "options": ["Option 1", "Option 2"] |
| 262 | +} |
| 263 | +``` |
0 commit comments