Webhooks C# API Not Working

Algomax
Hi Team,
We have Implemented Webhook APi in C# & Configured URL in Developers Console.
But its Not Listening.

Kindly Guide us on same.
  • tonystark
    Could you post a minimal example code that can reproduce your problem at our end?

    Make sure to remove all account credentials from the code before posting.
  • Algomax
    Hi ,
    Find the Code


    [HttpPost("webhook")]
    [Consumes("application/json")]
    public async Task webhook()
    {
    try
    {
    using (StreamReader reader = new StreamReader(Request.Body, Encoding.UTF8))
    {
    var json = await reader.ReadToEndAsync();
    try
    {
    var userInfo = await _IWebHookService.BotWebHooks(json);
    Console.WriteLine(json);

    }
    catch (Exception e)
    {
    Console.WriteLine("Error: {0}", e.Message);
    return BadRequest();
    }

    }
    return Ok();
    }
    catch (DataValidationException ex)
    {
    return Ok();
    }
    }
  • Algomax
    https://XXXX.co/api/Bot/webhook
    URL we configured in console
  • tonystark
    From your code snippet _IWebHookService.BotWebHooks it looks like this is some kind of a library. Kite Connect clients doesn't need to use any such library or doesn't adhere to specific standards.

    Kite Connect postbacks are simple POST requests to your given URL with json content as the POST body. You can use a simple HTTP handler and try to dump the request body.

    To test your postback handler you can use any API testing tool like Postman or simply curl and make a post request with sample payload from https://kite.trade/docs/connect/v3/postbacks/
  • Algomax
    _IWebHookService.BotWebHooks is just for internal DB Log Service cal .but if i remove also its not listening

    Any thing i missed in code apart?
  • tonystark
    If postbacks never triggers this function then it means issue is in the way you attach URL to this handler. Try to do the testing as I mentioned before by manually make a POST request your handler.
  • Algomax
    Pls see above its hitting n giving response
  • tonystark
    Could you DM me your API key? Also approximate time when you were testing the post backs
Sign In or Register to comment.