Search Results for

    Show / Hide Table of Contents

    Save over Webhook

    In this article, let's look at how to send a webhook report. Instructions on how to work with tasks are described in the General information section.

    Getting started

    You will need the following tools and facilities:

    1. Know how to use API key in FastReport Corporate Server.

      This article will skip over additional information on authentication and authorization.

    2. .NET SDK.

    3. C# code editor or text editor, e.g., Visual Studio Code.

    4. Report template.

      It can be generated in the free FastReport Community Designer program.

    5. Active FastReport Corporate Server subscription.

    6. Internet access.

    7. Client application receiving requests.

    Important! These guides assume that you already know how to develop your application in the C# programming language.

    Note. The items above describe recommended tools.

    Important! This guide assumes that you have a client application, that receives and processes incoming webhooks.

    Create task

    Let’s look at creating a task to send a template over webhook and then running it:

    // Object initialization
    CreateWebhookTaskVM webhookTaskVM = new CreateWebhookTaskVM
    {
        Name = "Webhook send task",
        InputFile = new InputFileVM
        {
            EntityId = "{template ID}",
            Type = FileKind.Template
        },
        Url = new Uri("https://example.com/"),
        Headers = new Dictionary<string, string> {
            { "Authorization", "Bearer <token>" },
            { "Content-Length", "1238" }
        },
        SubscriptionId = "{workspace ID}"
    };
    
     // Create a task
     TaskBaseVM webhookTask = await tasksClient.CreateTaskAsync(webhookTaskVM);
    
     // Start a task by ID
     await tasksClient.RunTaskByIdAsync(webhookTask.Id);
    

    Important! Real object identifiers should be written to the EntityId and SubscriptionId fields. Otherwise, the task will be terminated with an error.

    Important! The EntityId can be passed in the template, report, and export ID.

    Execute task from the request body

    // Run a task from the request body
     await tasksClient.RunTaskAsync(new RunWebhookTaskVM
     {
         InputFile = new RunInputFileVM
         {
             EntityId = "{template ID}",
             Type = FileKind.Template
         },
         Url = new Uri("https://example.com/"),
         Headers = new Dictionary<string, string> {
             { "Authorization", "Bearer <token>" },
             { "Content-Type", "multipart/form-data" }
         },
         SubscriptionId = "{workspace ID}"
     });
    

    Important! In this case, this request will send the webhook and the task will not be saved in the database.

    Update task by ID

    await tasksClient.UpdateTaskAsync("{old task ID}", new UpdateWebhookTaskVM()
     {
         InputFile = new RunInputFileVM
         {
             EntityId = "{updated template ID}",
             Type = FileKind.Template
         },
         Url = new Uri("{updated address}"),
         Headers = new Dictionary<string, string> {
             { "{updated header}", "{updated value}" },
         }
     });
    

    Example 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"
        }
      }
    }
    
    Back to top 2025.2.6 © 1998-2025 Copyright Fast Reports Inc.