Receiving Webhooks

Configure your server to handle webhook requests

Purple gradient wave Purple wave used to give a visual break between the header and body of the page.

Summary

With your webhook created Youmanage will now start to send out event data, but you'll need to set up a means to listen for those event messages. We'll take you through setting up a simple .NET Core application to get you started.

 

Requirements

In order for this example to work, you will need to have a computer that is connected to the internet and is capable of accepting external HTTP requests. There may be some additional configuration steps required if you are behind a router or firewall but that is outwith the scope of this tutorial, however a useful open-source program ngrok may be helpful.

In addition to this, we'll be assuming you have a copy of Visual Studio and the .NET Core SDK installed on your machine.

 

.NET Core Example

In order to process the request and act upon the Json data sent from Youmanage we'll implement a controller with a single action that just takes in the request payload and sends an acknowledgement back in response.

For help getting started with .NET Core 3.1 see the following getting started guide from Microsoft.

using System;
using System.Collections.Generic;
using Microsoft.AspNetCore.Mvc;
using Newtonsoft.Json;

namespace WebhooksSample
{
    public class SampleController : Controller
    {
        public class WebhookModel
        {
            public object Entity { get; set; }

            public string EntityType { get; set; }

            public string Action { get; set; }

            public DateTime OccurredAt { get; set; }

            public Guid IdempotencyKey { get; set; }

            public IDictionary<string, IDictionary<string, object>> Changes { get; set; }
        }

        [Route("")]
        public IActionResult Process([FromBody]WebhookModel payload)
        {
            return Content("We got some content: " + JsonConvert.SerializeObject(payload));
        }
    }
}

In our sample code, we've created a model to capture the information coming from the body of the request and a controller action that will handle the request. The controller simply takes the model and returns the information with a little extra message saying that we got some content.

With this up and running you should be able to see events in Youmanage showing as completed successfully and the contents of the request echoed back. That means you're up and running and can get started processing the information as you see fit!

 

Next up we'll delve into how you can use Youmanage to help test your newly configured server.