Table of Contents

Stored Tasks

Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher

As mentioned in the previous section, Service solutions provides the ability to create tasks that are saved in the database and can be run later. These tasks are called stored tasks.

Let's look in detail at how to create, update, and run stored tasks using the REST API.

About ViewModels and Types

When working, you will pass different ViewModels in JSON format. It is important that the first field of any ViewModel should be "$t": "Name". Detailed examples will be provided below in this article.

View Models for Creating Tasks

View Models for creating transformer tasks:

  • CreatePrepareTaskVM
  • CreateExportTemplateTaskVM
  • CreateExportReportTaskVM

View Models for creating transport tasks:

  • CreateEmailTaskVM
  • CreateWebhookTaskVM
  • CreateFTPUploadTaskVM
  • CreateS3UploadTaskVM

View Models for creating other tasks:

  • CreateFetchTaskVM

View Models for Updating Properties of Stored Tasks

View Models for updating transformer tasks:

  • UpdatePrepareTaskVM
  • UpdateExportTemplateTaskVM
  • UpdateExportReportTaskVM

View Models for updating transport tasks:

  • UpdateEmailTaskVM
  • UpdateWebhookTaskVM
  • UpdateFTPUploadTaskVM
  • UpdateS3UploadTaskVM

View Models for updating other tasks:

  • UpdateFetchTaskVM

View Model for Updating Task Permissions:

  • UpdateTaskPermissionsVM

Creating a Task

To create tasks, you should use the CreateTask method. It accepts a View Model for creating tasks.

Let's look at creating a report export task followed by email sending:

 curl -X 'POST' \
  'https://{host_name}/api/tasks/v1/tasks' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "$t": "CreateExportTemplateTaskVM",
  "subscriptionId": "23e0134c816935c1e11b3737",
  "name": "SendViaWebhookExport",
  "inputFile": {
    "entityId": "61e0134c816935c1e11b3787"
  },
  "transports": [
    {
        "$t": "CreateEmailTaskVM",
	    "name": "Email sending task",
	    "from": "admin@company.com",
	    "to": ["user@company.com", "seller@company.com"],
	    "subject": "Important report",
        "body": "An important report is attached to this email.",
	    "EnableSsl": true,
	    "username": "admin@company.com",
	    "password": "parol123",
	    "server": "smtp.company.com",
	    "port": 587
    }
  ],
  "format": "Pdf"
}'

In the EntityId and FolderId fields, you should enter real object identifiers. Otherwise, the task will be terminated with an error.

Note! If you don't specify OutputFile, it will be saved to a temporary folder. If you specify an empty OutputFile - to the root folder. If you specify a folder id - to that folder.

A list of all available ViewModels is available at the link - https://{host_name}/api/swagger/index.html

Running Tasks on Schedule

To configure task execution on a schedule, you need to specify the following fields:

  • cronExpression
  • startsOn
  • ends

cronExpression - a string containing a cron expression that defines the task execution schedule.

startsOn - the date and time from which scheduled task execution begins (in user's timezone).

ends - an object containing the date and time until which the task will be executed on schedule (on) or the number of repetitions (after). The on field is specified in user's timezone. If neither the after nor the on field is specified, the task will run indefinitely.

Example of creating a task that runs on schedule:

 curl -X 'POST' \
  'https://{host_name}/api/tasks/v1/tasks' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "$t": "CreateExportTemplateTaskVM",
  "subscriptionId": "23e0134c816935c1e11b3737",
  "name": "SendViaWebhookExport",
  "inputFile": {
    "entityId": "61e0134c816935c1e11b3787"
  },
  "transportIds": [
                "68767аef184dcf225ca085e1"
            ],
  "format": "Pdf",
  "cronExpression": "*/5 * * * *",  # Run every 5 minutes
  "startsOn": "2025-10-01T00:00:00Z",  # Start from October 1, 2025
  "ends": {
    "on": "2025-12-31T23:59:59Z"  # End on December 31, 2025
  }
}'

In this example, the task will run every 5 minutes, starting from October 1, 2025 and ending on December 31, 2025.

To make the task execute, for example, 10 times, you need to replace the on field with the after field:

"cronExpression": "*/5 * * * *",  # Run every 5 minutes
  "startsOn": "2025-10-01T00:00:00Z",  # Start from October 1, 2025
  "ends": {
   "after": 10  # Execute 10 times"
  }

Getting Task List

 // Getting the first ten tasks from the workspace
 curl -X 'GET' \
  'https://{host_name}/api/tasks/v1/tasks?skip=0&take=10' \
  -H 'accept: application/json'

Editing Task

After a task is created, you can change some of its parameters.

// Editing task
curl --location --request PUT 'https://{host_name}/api/tasks/v1/Tasks/{task id}' \
--header 'accept: application/json' \
--header 'Content-Type: application/json' \
--header 'Authorization: Basic {base64(apikey:api-key-value)}' \
--data '{
    "$t": "UpdateExportTemplateTaskVM",
    "reportParameters": {
        "param1": "val1",
        "param2": "val2"
    },
    "transportIds" : ["{transport task id (email sending, FTP upload, etc.)}"] 
}'

Note that when updating a task, you need to specify transportIds - a list of transport task identifiers (Email, FTP, Webhook, S3), not the tasks themselves. The task itself can be created in advance either separately or when creating a transformer task. For more details on creating them, read the section Creating Transport Tasks.

Executing Task by Specified Identifier

 curl -X 'POST' \
  'https://{host_name}/api/tasks/v1/tasks/42d134ae3130aaad37by345f/run' \
  -H 'accept: */*' \
  -d ''

Deleting Task from Storage

curl -X 'DELETE' \
  'https://{host_name}/api/tasks/v1/tasks/42d134ae3130aaad37by345f' \
  -H 'accept: */*'