Create report
Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher
This article describes the process of creating a report from a template using the Service solutions report processor.
Getting started
You will need the following tools and facilities:
Know how to use API key in Service solutions.
This article will skip over additional information on authentication and authorization.
Curl tool.
Any other REST client will work, but the examples will be built for curl.
Report template.
To learn how to upload a report template, refer to the Upload a new template article.
Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.
Internet access.
Instruction
To create a template, you need its ID. Execute
GETrequest to{host_name}/api/rp/v1/Templates/Rootto retrieve the root directory.Example request:
curl -X GET "{host_name}/api/rp/v1/Templates/Root" -H "accept: text/plain"Example answer:
{ "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" }Directory ID from the example above:
5fa919f9292a8300019349b9.To get a list of files in the directory, execute
GETrequest to{host_name}/api/rp/v1/Templates/Folder/{id}/ListFiles?skip=0&take=10, where the directory ID should be used instead of{id}.Example request:
curl -X GET "{host_name}/api/rp/v1/Templates/Folder/5fa919f9292a8300019349b9/ListFiles?skip=0&take=10" -H "accept: text/plain"Example answer:
[ { "reportInfo": { "author": null, "created": "2020-12-04T10:58:57Z", "creatorVersion": "20.20.4.1", "description": null, "modified": "2020-12-04T11:00:20Z", "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.708Z", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "2020-12-04T08:01:42.708Z", "editorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491" } ]Template ID from the example above:
5fc9ece6b792c90001d94b13.To create a report, you will need a directory to store the report in. Request the root report directory by executing
GETrequest to{host_name}/api/rp/v1/Reports/Root.Example request:
curl -X GET "{host_name}/api/rp/v1/Reports/Root" -H "accept: text/plain"Example answer:
{ "name": "RootFolder", "parentId": null, "tags": null, "icon": null, "type": "Folder", "size": 16384, "subscriptionId": "5fa919fa292a8300019349bc", "status": "None", "id": "5fa919f9292a8300019349ba", "createdTime": "2020-11-09T10:29:13.993Z", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "0001-01-01T00:00:00Z", "editorUserId": null }Directory ID from the example above:
5fa919f9292a8300019349ba.To create a report, execute the
POSTrequest to{host_name}/api/rp/v1/Templates/File/{id}/Prepare, where the template ID should be used instead of{id}.In the request body, pass JSON according to the scheme below.
{ "name": "string", "folderId": "string", "reportParameters": { "additionalProp1": "string", "additionalProp2": "string", "additionalProp3": "string" } }folderId— ID of the directory where the report will be placed.name— name of the resulting file. Add.fpxextension manually.reportParameters— parameters that are specified in the report itself via the report designer, they are not needed in this example.
If you do not specify folderId, the generated report will be saved to the root folder.
Example request:
curl -X POST "{host_name}/api/rp/v1/Templates/File/5fc9ece6b792c90001d94b13/Prepare" -H "accept: text/plain" -H "Content-Type: application/json-patch+json" -d "{ \"name\": \"awesome_report.fpx\", \"folderId\": \"5fa919f9292a8300019349ba\"}"Example answer:
{ "templateId": "5fc9ece6b792c90001d94b13", "reportInfo": null, "name": "awesome_report.fpx", "parentId": "5fa919f9292a8300019349ba", "tags": null, "icon": null, "type": "File", "size": 16384, "subscriptionId": "5fa919fa292a8300019349bc", "status": "InQueue", "id": "5fe4614bcd7c55000148e4c6", "createdTime": "2020-12-24T09:37:15.7169531+00:00", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "2020-12-24T09:37:15.7169582+00:00", "editorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491" }Pay attention to the status of the
InQueuefile, it means that the task for generation has been created and then it has been added to the builder’s queue. Already at this stage the report has received its ID for work:5fe4614bcd7c55000148e4c6.
You should wait a while for the report to be generated. You can call the method of getting the report in a loop every few milliseconds and check the report status.
For information about the report, execute the
GETrequest to{host_name}/api/rp/v1/Reports/File/{id}, where the report ID should be used instead of{id}.Example request:
curl -X GET "{host_name}/api/rp/v1/Reports/File/5fe4614bcd7c55000148e4c6" -H "accept: text/plain"Example answer:
{ "templateId": "5fc9ece6b792c90001d94b13", "reportInfo": null, "name": "awesome_report.fpx", "parentId": "5fa919f9292a8300019349ba", "tags": null, "icon": null, "type": "File", "size": 16927, "subscriptionId": "5fa919fa292a8300019349bc", "status": "Success", "id": "5fe4614bcd7c55000148e4c6", "createdTime": "2020-12-24T09:37:15.716Z", "creatorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491", "editedTime": "2020-12-24T09:37:15.716Z", "editorUserId": "5af5a8dc-8cb0-40f9-ac99-ca2533fa4491" }Note the status of the
Successfile. The report was successfully generated.To download the report, execute the
GETrequest to{host_name}/download/r/{id}, where the report ID should be passed instead of{id}.Example request:
curl -X GET "{host_name}/download/r/5fe4614bcd7c55000148e4c6" -H "accept: text/plain"The file will be received in the response.
What next?
Note! In the examples there may be no Authorization header because a cookie-based authentication model is used. For more information about authorization, read the Authentication and authorization section.