Webhook FetchError

Heyy Speckle community!

Right now I have a little problem getting the webhooks to work. A little background regarding my project: I have a server that needs to be notified whenever a new commit to a stream has been made. The server is written in C# using swagger for the Rest-API.
To get everything running I have been following Izzys tutorial for a python implementation found here: “Use Stream Webhooks To Build a Discord Bot
The solution in this thread: “Webhook is not being called” also didn’t help me out.

The error that I get says: Error: FetchError: Response timeout while trying to fetch myngrokurl/api/v0.1/speckle/commit (over 10000ms)

my server is running on localhost for development and it has an endpoint that accepts a HttpPost-Request with a requestbody that has a single string inside. Baisically my endpoint looks like this →

        [HttpPost("commit")]
        public ActionResult BroadcastCommit([FromBody] string data)
        {
            --- Some Code ---
        }

Any ideas on what I’m doing wrong? otherwise I have to switch to subscriptions for now but I would really like to get this thing working :smiley:

thanks in advance as always!

HI @mgerhardt ,

The error indicates that it doesn’t receive an answer from the provided URL in 10 seconds (the timeout).

If you manually do a POST request to your URL, do you receive a response in 10 sec?

2 Likes

Hallo crist,

ty for the very quick answer. I tested it with postman and I had indeed a problem with my ngrok configuration :slight_smile: I fixed it and am now able to call my endpoints using ngrok. Now I only have the problem that the webhook still runs into an error: Error: HTTP response code: 400

When I remove the [FromBody] part, than the webhook actually reaches my endpoint which is really cool but sadly I dont get any data with an endpoint looking like this:

        [HttpPost("commit")]
        public ActionResult BroadcastCommit(string data)
        {
            --- some code ---
        }

data is empty in this codeblock.
Any ideas?

I am not familiar with the framework that you are using, but here is some technical explanation about the request:

We’re sending the information as a JSON encoded string, passed on a POST parameter named payload.
So the parameter name might be important, it’s called payload and has a string value.

You can then parse that json to get the full information about the event

1 Like

I actually got it working this morning :slight_smile:
Using Swagger in C# I had to define my endpoint like this:

        [HttpPost("commit")]
        public ActionResult BroadcastCommit([FromBody] JsonElement payload)
        {
           --- Code ---
        }

I switched the datatype of the payload parameter from string to JsonElement and it worked.
awesome!

2 Likes

Do I understand the webhooks wrong? Because I dont get the actual data in my endpoint that has been commited. I’m talking about the Base-Object here which is the only thing that I actually need in my server.

Indeed, you only get the metadata of the commit, as the actual contents can be very large and it depends a lot on what you are trying to achieve.

If you are interested in doing processing on the data itself, you can use the .net sdk to fetch that commit from the server

The current main goal of webhooks is to just trigger external workloads, which can use the SDK (.net or python) to interact with the data.

But as this is a common usecase (to do some processing on the incoming data), we had some internal discussions on improving this (cloud functions / other form of data pipelining), but we’re still waiting for more usecases to make a solid design around it.

Can you describe your usecase in more detail? Like is the output of your processing stored in another Speckle stream? or is it a final “report” that doesn’t go back to Speckle? or are you processing data from multiple streams at the same time?

Thanks,
Cristi

1 Like

first of all, thank you for the quick and good answers!
Right now I have two clients. One client uses the speckleviewer to display a model in the webbrowser and that colors certain parts of the model in a given color. Which parts should be colored is determined by a second app that commits an id into the speckle stream of the object that needs to be colored next. We dont really want to use custom websockets because then we would need a constant connection between a client a server and our client that displayes the model through the speckleviewer will run constantly once started.

1 Like