Skip to content

Commit

Permalink
add missing endpoints, edit responses
Browse files Browse the repository at this point in the history
  • Loading branch information
johanohly committed Sep 11, 2024
1 parent d87ada3 commit aaddd24
Show file tree
Hide file tree
Showing 16 changed files with 1,045 additions and 292 deletions.
1 change: 0 additions & 1 deletion source/includes/_account.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,6 @@ This endpoint updates the groups in the company.

```shell
curl https://api.simplyprint.io/{id}/account/GetGroups \
-X GET \
-H 'accept: application/json' \
-H 'X-API-KEY: {API_KEY}'
```
Expand Down
70 changes: 37 additions & 33 deletions source/includes/_api_files.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
# API Files

The base URL for the SimplyPrint Files API is `https://files.simplyprint.io/{id}/`. Use the exact same authentication as the normal api endpoint. It is very important you ensure you send files with the correct file extension. The API will not be able to determine the file type based on the content.
The base URL for the SimplyPrint Files API is `https://files.simplyprint.io/{id}/`. Use the exact same authentication as
the normal api endpoint. It is very important you ensure you send files with the correct file extension. The API will
not be able to determine the file type based on the content.

## Upload a file using the API

<aside class="notice">
This endpoint requires the <b>Print Farm</b> plan.
</aside>

`POST {id}/files/Upload`
`POST /{id}/files/Upload`

> Example request to upload a file less than 100MB
Expand All @@ -18,17 +20,18 @@ curl -X POST "https://files.simplyprint.io/{id}/files/Upload" \
-H "X-API-KEY: {API_KEY}" \
-F "file=@/path/to/file.gcode"
```

> Success response
```json
{
"status":true,
"message": null,
"file": {
"id": "f568ead4bbc2d881efc8a9a05f3bd585334cd8c662347ba2dfad7250176b0abd",
"name": "file.gcode",
"size": 13439
}
"status": true,
"message": null,
"file": {
"id": "f568ead4bbc2d881efc8a9a05f3bd585334cd8c662347ba2dfad7250176b0abd",
"name": "file.gcode",
"size": 13439
}
}
```

Expand All @@ -41,13 +44,14 @@ curl -X POST "https://files.simplyprint.io/{id}/files/Upload" \
-F "file=@/path/to/part1.3mf"
-F "totalSize=3352316"
```

> Success response with continueToken
```json
{
"status":true,
"message":null,
"continueToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzM4NCJ9.eyJ0eXBlIjoiYWN0ao9uX3Rva2VuIiwiYWN0aW9uIjoiZmlsZV9jb250aW51ZV91cGxvYWQiLCJ1c2VyIjo2OTc2LCJjb21wYW55IjoyLCJkYXRhIja7ImJ1Y2tldEhhc2giOiI0MGQ2MzgwNmQwYWUxODhkNjc5YzY0NjA0M2RiYjUxMTc0NTViNTc1NjNlODEzZDc2MGRjMTJkMzVaYjdmY2Y0IiwidG90YWxTaXplIjoxNjc2MTU4NH0sImlhdCI6MTcyNTU2MjEzMywiZXhwIjoxNzI1NjQ4NTMzfQ.9qyNyx9A4Ox_6GrFSxXpxlpLcAKaSr8ln84X3yuWdhT_2O3L8-lGWaXAbQk9VvR-3pu1-a9p40amnt6Fghy49InjzCfNMRp-6-Ft_uMRf6PbmcCCrksvRxNP38ImoXy6"
"status": true,
"message": null,
"continueToken": "eyJ0eXAiOiJKV1QiLCJhbGciOiJFUzM4NCJ9.eyJ0eXBlIjoiYWN0ao9uX3Rva2VuIiwiYWN0aW9uIjoiZmlsZV9jb250aW51ZV91cGxvYWQiLCJ1c2VyIjo2OTc2LCJjb21wYW55IjoyLCJkYXRhIja7ImJ1Y2tldEhhc2giOiI0MGQ2MzgwNmQwYWUxODhkNjc5YzY0NjA0M2RiYjUxMTc0NTViNTc1NjNlODEzZDc2MGRjMTJkMzVaYjdmY2Y0IiwidG90YWxTaXplIjoxNjc2MTU4NH0sImlhdCI6MTcyNTU2MjEzMywiZXhwIjoxNzI1NjQ4NTMzfQ.9qyNyx9A4Ox_6GrFSxXpxlpLcAKaSr8ln84X3yuWdhT_2O3L8-lGWaXAbQk9VvR-3pu1-a9p40amnt6Fghy49InjzCfNMRp-6-Ft_uMRf6PbmcCCrksvRxNP38ImoXy6"
}
```

Expand All @@ -65,33 +69,33 @@ curl -X POST "https://files.simplyprint.io/{id}/files/Upload" \
```json
{
"status":true,
"message":null,
"file": {
"id": "f568ead4bbc2d881efc8a9a05f3bd585334cd8c662347ba2dfad7250176b0abd",
"name": "part1.3mf",
"size": 3352316
}
"status": true,
"message": null,
"file": {
"id": "f568ead4bbc2d881efc8a9a05f3bd585334cd8c662347ba2dfad7250176b0abd",
"name": "part1.3mf",
"size": 3352316
}
}
```

### Request

| Parameter | Type | Required | Description |
| --------------- | ------- | -------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `file` | file | yes | Uploaded file (Max 100mb) |
| `continueToken` | string | no | Optional token you'll get if you need to continue the upload for files greater than 100MB. |
| `totalSize` | integer | no | Send this if you want a continueToken, by providing the total size of the entire file you want to upload |
| Parameter | Type | Required | Description |
|-----------------|---------|----------|----------------------------------------------------------------------------------------------------------|
| `file` | file | yes | Uploaded file (Max 100mb) |
| `continueToken` | string | no | Optional token you'll get if you need to continue the upload for files greater than 100MB. |
| `totalSize` | integer | no | Send this if you want a continueToken, by providing the total size of the entire file you want to upload |

### Response

| Parameter | Type | Description |
| ------------ | ------- | -------------------------------------------------------------|
| `status` | boolean | True if the request was successful. |
| `message` | string | Error message if `status` is false. |
| `continueToken` | string | For every subsequent request that still has some pending size based on the total size this will be returned instead of the file. |
| `file.*` | object | Final file object after entire file has been uploaded |
| `file.id` | string | The API File ID you'll need to use other SimplyPrint APIs |
| `file.name` | string | Name used to reference the file |
| `file.size` | int | Total size of uploaded file |
| Parameter | Type | Description |
|-----------------|---------|----------------------------------------------------------------------------------------------------------------------------------|
| `status` | boolean | True if the request was successful. |
| `message` | string | Error message if `status` is false. |
| `continueToken` | string | For every subsequent request that still has some pending size based on the total size this will be returned instead of the file. |
| `file.*` | object | Final file object after entire file has been uploaded |
| `file.id` | string | The API File ID you'll need to use other SimplyPrint APIs |
| `file.name` | string | Name used to reference the file |
| `file.size` | int | Total size of uploaded file |

263 changes: 263 additions & 0 deletions source/includes/_custom_fields.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,263 @@
# Custom Fields

<aside class="notice">
This feature requires the <b>Print Farm</b> plan.
</aside>

Custom Fields allow you to add your own data-fields inside SimplyPrint.

[Read more about Custom Fields on our Helpdesk](https://help.simplyprint.io/en/article/all-about-the-custom-fields-feature-4dd5if/)

## List custom fields

`POST /{id}/custom_fields/Get`

> Example request
```shell
curl -X POST https://api.simplyprint.io/{id}/custom_fields/Get \
-H 'accept: application/json' \
-H "X-API-KEY: {API_KEY}" \
-F "page=1" -F "page_size=10"
```

> Example response
```json
{
"status": true,
"message": null,
"data": [
{
"id": 7,
"fieldId": "student_id",
"fieldLabel": "Student ID",
"fieldDescription": "",
"fieldPlaceholder": null,
"fieldType": "text",
"fieldOptions": null,
"category": "print",
"subCategory": [
"user_file",
"print_queue",
"print_job"
],
"required": false,
"enabled": true,
"defaultValue": null,
"visibleRequiredPermissions": null,
"editRequiredPermissions": null,
"visibleToGroups": [],
"editableByGroups": [],
"validation": null,
"createdByUser": -1,
"user": "John Doe",
"forPrinters": [],
"forModels": [],
"forGroups": [],
"showOnRegistration": null,
"showBeforeStartPrint": null,
"position": 0,
"created": "2024-09-07T13:46:59+00:00",
"updated": "2024-09-07T13:46:59+00:00"
}
],
"page_amount": 1,
"total": 1
}
```

### Request

| Parameter | Type | Required | Description |
|-------------|---------|----------|-----------------------------------------------------------------------------------------------------------------|
| `page` | integer | yes | Which page to show |
| `page_size` | integer | yes | Amount of items per page (1-100) |
| `search` | string | no | The search filter to apply |
| `sort_id` | string | no | What key to sort on (id, fieldId, fieldLabel, fieldDescription, fieldType, category, enabled, created, updated) |
| `sort_dir` | string | no | Sort direction (`asc`, `desc`) |

### Response

| Parameter | Type | Description |
|-----------|---------|-------------------------------------|
| `status` | boolean | True if the request was successful. |
| `message` | string | Error message if `status` is false. |
| `data` | array | List of custom fields. |

## Create or update a custom field

`POST /{id}/custom_fields/Save`

> Example request
```shell
curl -X POST https://api.simplyprint.io/{id}/custom_fields/Save \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'X-API-KEY: {API_KEY}' \
-d '{"category":"print","subCategory":["user_file","print_queue","print_job"],"fieldType":"text","fieldId":"student_id","fieldLabel":"Student ID","required":false,"enabled":true}'
```

> Example response
```json
{
"status": true,
"message": null
}
```

### Request

| Parameter | Type | Required | Description |
|------------------------|---------|----------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| `id` | integer | no | If you want to update an existing custom field, specify this |
| `category` | string | yes | One of `print`, `user`, `printer`, `filament` |
| `subCategory` | array | no | Array of subcategories. Valid subcategories: `print_queue`, `print_job`, `user_file` |
| `fieldId` | string | yes | ID of the field |
| `fieldType` | string | yes | One of `boolean`, `text`, `longtext`, `number`, `date`, `datetime`, `phone`, `email`, `url`, `select`, `multiselect`, `radio`, `checkbox` |
| `fieldLabel` | string | yes | Label of the field |
| `fieldOptions` | object | no | Field options. An object with one entry, `options`, whose value is an array of `{label: string, value: string}` |
| `FieldDescription` | string | no | Description of the field |
| `fieldPlaceholder` | string | no | Placeholder text for the field |
| `required` | boolean | yes | Whether the field is required |
| `defaultValue` | object | no | Default value of the field. Object key should be either `string`, `number`, `boolean`, `date`, `options`, with the appropriate value type |
| `validation` | object | no | Validation rules for the field. Object keys can be any of `stringRegex`, `stringMinLength`, `stringMaxLength`, `numberAllowDecimals`, `numberMinValue`, `numberMaxValue`, `validationMessage` |
| `forPrinters` | array | no | Array of printer IDs the field should be visible for |
| `forModels` | array | no | Array of model IDs the field should be visible for |
| `forGroups` | array | no | Array of group IDs the field should be visible for |
| `showOnRegistration` | boolean | no | Whether the field should be shown on registration |
| `showBeforeStartPrint` | boolean | no | Whether the field should be shown before starting a print |

### Response

| Parameter | Type | Description |
|-----------|---------|-------------------------------------|
| `status` | boolean | True if the request was successful. |
| `message` | string | Error message if `status` is false. |

## Enable or disable a custom field

`POST /{id}/custom_fields/SetEnabled`

> Example request
```shell
curl -X POST https://api.simplyprint.io/{id}/custom_fields/SetEnabled \
-H 'accept: application/json' \
-H 'Content-Type: application/json' \
-H 'X-API-KEY: {API_KEY}' \
-d '{"id": 123, "enabled": true}'
```

> Example response
```json
{
"status": true,
"message": null
}
```

### Request

| Parameter | Type | Required | Description |
|-----------|---------|----------|---------------------------------------------------------------------------|
| `id` | integer | yes | ID of the custom field to enable or disable |
| `enabled` | boolean | yes | Whether the custom field should be enabled (`true`) or disabled (`false`) |

### Response

| Parameter | Type | Description |
|-----------|---------|-------------------------------------|
| `status` | boolean | True if the request was successful. |
| `message` | string | Error message if `status` is false. |

## Delete custom fields

`GET /{id}/custom_fields/Delete`

> Example request
```shell
curl https://api.simplyprint.io/{id}/custom_fields/Delete?id=123 \
-H 'accept: application/json' \
-H 'X-API-KEY: {API_KEY}'
```

> Example request with multiple IDs
```shell
curl https://api.simplyprint.io/{id}custom_fields/Delete?ids=123,124,125 \
-H 'accept: application/json' \
-H 'X-API-KEY: {API_KEY}'
```

> Example response
```json
{
"status": true,
"message": null
}
```

### Request

| Parameter | Type | Required | Description |
|-----------|---------|--------------------------------|----------------------------------------------------------------------------------------------------|
| `id` | integer | yes (if `ids` is not provided) | The ID of the custom field to delete. |
| `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. |

### Response

| Parameter | Type | Description |
|-----------|---------|-------------------------------------|
| `status` | boolean | True if the request was successful. |
| `message` | string | Error message if `status` is false. |

## Custom field submission value

The value of a custom field when submitted via the API is an object with a key corresponding to the field type.
See the examples to the right for the different field types.

> A text field would have a value like this:
```json
{
"string": "1234567890"
}
```

> A number field would have a value like this:
```json
{
"number": 1234567890
}
```

> A date field would have a value like this:
```json
{
"date": "2024-09-07"
}
```

> A select field would have a value like this:
```json
{
"string": "Selected option"
}
```

> A multi-select field would have a value like this:
```json
{
"options": ["Option 1", "Option 2"]
}
```
Loading

0 comments on commit aaddd24

Please sign in to comment.