Upload a new template
One of the main features of FastReport Corporate Server is storing templates, reports and other data in the cloud. This article will describe a way to upload your ready template to FastReport Corporate Server templates storage.
Getting started
You will need the following tools and features:
Knowledge on how to use API key in FastReport Corporate Server.
This article does not include the information about authentication and authorization.
The curl tool.
Any other REST client will work, however, the examples are provided for curl.
A report template.
It can be prepared using free software FastReport Community Designer.
Active FastReport Corporate Server subscription.
Internet access.
Instructions
You need to get the subscription root directory identifier. This identifier will never change, so you can save it and not make a request every time before loading a new template.
To request the root directory, make a
GET
request tohttps://fastreport.cloud/api/rp/v1/Templates/Root
.curl -X GET "https://fastreport.cloud/api/rp/v1/Templates/Root" -H "accept: text/plain"
In this case, the default subscription directory will be returned. You can specify a certain subscription by passing the
subscriptionId
parameter.curl -X GET "https://fastreport.cloud/api/rp/v1/Templates/Root?subscriptionId=your_subscription_id" -H "accept: text/plain"
A sample response.
{ "name": "RootFolder", "parentId": null, "tags": [], "icon": "", "type": "Folder", "size": 16384, "subscriptionId": "5fa919fa292a8300019349bc", "status": "None", "id": "5fa919f9292a8300019349b9", "createdTime": "2020-11-09T10:29:13.928Z", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "2020-11-13T15:58:45.69Z", "editorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491" }
The directory identifier from the example above is
5fa919f9292a8300019349b9
.To upload the required template, make a
POST
request tohttps://fastreport.cloud/api/rp/v1/Templates/Folder/{id}/File
, substituting{id}
with the directory identifier, and send JSON in the request body according to the scheme below.{ "name": "string", "content": "base64encoded(template.frx)" }
name
— the name of the file to be displayed in the user panel.Add the extension
.frx
to the file name manually.content
— file content encoded in base64.
A sample request.
curl -X POST "https://fastreport.cloud/api/rp/v1/Templates/Folder/5fa919f9292a8300019349b9/File" -H "accept: text/plain" -H "Content-Type: application/json-patch+json" -d "{ \"name\": \"template.frx\", \"content\": \"77u/PD94bWwgdmVyc2lvbj0iMS4wIiBlbmNvZGluZz0idXRmLTgiPz4NCjxSZXBvcnQgU2NyaXB0TGFuZ3VhZ2U9IkNTaGFycCIgUmVwb3J0SW5mby5DcmVhdGVkPSIxMi8wNC8yMDIwIDEwOjU4OjU3IiBSZXBvcnRJbmZvLk1vZGlmaWVkPSIxMi8wNC8yMDIwIDExOjAwOjIwIiBSZXBvcnRJbmZvLkNyZWF0b3JWZXJzaW9uPSIyMC4yMC40LjEiPg0KICA8RGljdGlvbmFyeS8+DQogIDxSZXBvcnRQYWdlIE5hbWU9IlBhZ2UxIiBXYXRlcm1hcmsuRm9udD0iQXJpYWwsIDYwcHQiPg0KICAgIDxSZXBvcnRUaXRsZUJhbmQgTmFtZT0iUmVwb3J0VGl0bGUxIiBXaWR0aD0iNzE4LjIiIEhlaWdodD0iMzcuOCIvPg0KICAgIDxQYWdlSGVhZGVyQmFuZCBOYW1lPSJQYWdlSGVhZGVyMSIgVG9wPSI0MSIgV2lkdGg9IjcxOC4yIiBIZWlnaHQ9IjI4LjM1Ii8+DQogICAgPERhdGFCYW5kIE5hbWU9IkRhdGExIiBUb3A9IjcyLjU1IiBXaWR0aD0iNzE4LjIiIEhlaWdodD0iNzUuNiI+DQogICAgICA8VGV4dE9iamVjdCBOYW1lPSJUZXh0MSIgV2lkdGg9IjcxOC4yIiBIZWlnaHQ9Ijc1LjYiIFRleHQ9IkhlbGxvLCBGYXN0UmVwb3J0IENsb3VkISEhIiBIb3J6QWxpZ249IkNlbnRlciIgVmVydEFsaWduPSJDZW50ZXIiIEZvbnQ9IkFyaWFsLCAxMHB0Ii8+DQogICAgPC9EYXRhQmFuZD4NCiAgICA8UGFnZUZvb3RlckJhbmQgTmFtZT0iUGFnZUZvb3RlcjEiIFRvcD0iMTUxLjM1IiBXaWR0aD0iNzE4LjIiIEhlaWdodD0iMTguOSIvPg0KICA8L1JlcG9ydFBhZ2U+DQo8L1JlcG9ydD4NCg==\"}"
A sample response.
{ "reportInfo": { "author": null, "created": "2020-12-04T10:58:57", "creatorVersion": "20.20.4.1", "description": null, "modified": "2020-12-04T11:00:20", "name": null, "picture": null, "previewPictureRatio": 0, "saveMode": "All", "savePreviewPicture": false, "tag": null, "version": null }, "name": "template.frx", "parentId": "5fa919f9292a8300019349b9", "tags": null, "icon": null, "type": "File", "size": 17159, "subscriptionId": "5fa919fa292a8300019349bc", "status": "Success", "id": "5fc9ece6b792c90001d94b13", "createdTime": "2020-12-04T08:01:42.7087229+00:00", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "2020-12-04T08:01:42.7087112+00:00", "editorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491" }
Now this template can be used to prepare (build) a report and export.