Search code examples
autodesk-forgeautodesk-webhooks

Where to handle callback when using Forge Webhooks : server or client side?


I am trying to use Forge Webhooks API to monitor the translation progress of my model with Model Derivative API. I use :

  • C# Web ApiControllers on server side
  • jQuery/JS on client side

I am not sure about where to handle callbacks from Webhooks API. I started writting the callback receiver in the C# ApiController (server side) :

    [HttpPost]
    [Route("api/webhook/callback")]
    public HttpResponseMessage WebhookCallback(dynamic info)
    {
        string urn = info.resourceUrn;

        // do things

        // redirect to root
        HttpResponseMessage res = Request.CreateResponse(HttpStatusCode.Moved /* force redirect */);
        res.Headers.Location = new Uri("/", UriKind.Relative); // back to / (root, default)

        return res;
    }

But then I realized I can't execute JS client side functions from this Controller method, for instance to show the model in the viewer.

Do I need to write the callback receiver in the JS client side part? If so, how?

Thanks in advance for your help.


Solution

  • The webhook need to call a stable URL, so on your server side, which then calls your client side (e.g. using websocket )

    We have a .NET sample here, sorry it doesn’t yet implement the websocket