Table of Contents

Send to Webhook

Products: FastReport Cloud, FastReport Corporate Server, FastReport Publisher

This article covers how to send a report via webhook. Instructions on how to work with tasks are described in the General Information section.

Getting Started

You will need the following tools and capabilities:

  1. Knowledge of using API key in Service solutions.

    This article will skip additional information on authentication and authorization.

  2. curl tool.

    Any other REST client will work, but examples will be built for curl.

  3. Active subscription to one of the following products: FastReport Cloud, FastReport Corporate Server, or FastReport Publisher.

  4. Internet access.

  5. Client application that accepts requests.

Note! The points above describe recommended tools.

Note! This guide assumes you have a client application that accepts and processes incoming webhooks.

Creating a Task

Let's look at creating a template sending task via webhook:

// Creating a task
curl -X 'POST' \
  'https://{host_name}/api/tasks/v1/Tasks' \
  -H 'accept: application/json' \
  -H 'Content-Type: application/json' \
  -d '{
  "$t": "CreateWebhookTaskVM",
  "name": "Webhook sending task",
  "subscriptionId": "{workspace identifier}",
  "url": "https://example.com/",
  "headers": {
      "Authorization": "Bearer <token>",
      "Content-Type": "multipart/form-data"
  },
  "inputFile": {
    "entityId": "{template identifier}",
    "type": "Template"
  }
}'
// Running task by identifier
curl -X 'POST' \
  'https://{host_name}/api/tasks/v1/Tasks/{task identifier}/run' \
  -H 'accept: */*' \
  -d ''

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

Note! EntityId can contain the identifier of a template, report, or export.

Executing Task from Request Body

curl -X 'POST' \
  'https://{host_name}/api/tasks/v1/Tasks/run' \
  -H 'accept: */*' \
  -H 'Content-Type: application/json' \
  -d '{
  "$t": "RunWebhookTaskVM",
  "name": "Webhook sending task",
  "subscriptionId": "{workspace identifier}",
  "url": "https://example.com/",
  "headers": {
     "Authorization": "Bearer <token>",
     "Content-Type": "multipart/form-data",
     "Content-Length": "1278"
  },
  "inputFile": {
    "entityId": "{template identifier}",
    "type": "Template"
  }
}'

Note! In this case, sending via webhook will be performed directly by this request and the task will not be saved in the database.

Example of a request that will come to the webhook endpoint:

{
  "startedDateTime": "2024-06-07 08:37:09",
  "request": {
    "method": "POST",
    "url": "https://example.com/6e259560-25e5-482b-a7b2-8c5267ba6ae3/",
    "headers": [
      {
        "name": "connection",
        "value": "close"
      },
      {
        "name": "content-length",
        "value": "1421"
      },
      {
        "name": "content-type",
        "value": "multipart/form-data; boundary=\"62ec6524-9360-4e91-834f-e9531e2d2c30\""
      },
      {
        "name": "host",
        "value": "example.com"
      }
    ],
    "bodySize": 0,
    "postData": {
      "mimeType": "application/json",
      "text": ""
    }
  },
  "response": {
    "status": 200,
    "httpVersion": "HTTP/1.1",
    "headers": [
      {
        "name": "Content-Type",
        "value": "text/html"
      }
    ],
    "content": {
      "size": 145,
      "text": "This URL has no default content configured.",
      "mimeType": "text/html"
    }
  }
}

Note! The examples don't have the Authorization header because an authentication model based on cookies is used. For more details about authorization, read the section Authentication and Authorization.