locked
web hook receiver not fire RRS feed

  • Question

  • User-689094057 posted

    in my project need to add web hook receiver come from big commerce , 

    I need to fire bigcommerce webhook so I install Microsoft.AspNet.WebHooks.Receivers.Custom from NuGet into my project then register in webapi.config like this

    config.InitializeReceiveCustomWebHooks();

    After that I am create a Handler file like this

    public class BigcommerceWebHookHandler : WebHookHandler

        {

      public override Task ExecuteAsync(string receiver, WebHookHandlerContext context)

            {

                string action = context.Actions.First();

                JObject data = context.GetDataOrDefault<JObject>(); 

                return Task.FromResult(true);

            }

        }

    Also i set setting in my web.config file like 

    <add key="MS_WebHookReceiverSecret_Custom" value="12345678901234567890123456789012" /> 

    When I create my webhook in bigcommerce I pass the destination URL https://localhost/bigspot/api/webhooks/incoming/custom 

    mainly I create this hook when product delete from my store but nothing happened.

    Where I wrong  please help me  

    Tuesday, November 20, 2018 9:40 AM

Answers

  • User-689094057 posted

    I am simply add a ActionResult in Home Controller not web hooks hit my ActionResult

    [HttpPost]
    [Route("webhooks/incoming/ProductDelete")]
    public ActionResult ProductDelete([System.Web.Http.FromBody] WebhookResponse Response)
    {
    StringBuilder sb = new StringBuilder();
    string filePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/");
    if (!string.IsNullOrEmpty(Response.scope))
    {
    WebhookResponse rsp = new WebhookResponse();
    // rsp = JsonConvert.DeserializeObject<WebhookResponse>(context);
    sb.Append(Response.producer);
    sb.Append("<br/>");
    sb.Append(Response.scope);
    sb.Append("<br/>");
    sb.Append(Response.store_id);
    sb.Append("<br/>");
    sb.Append(Response.data.id);
    sb.Append("<br/>");
    sb.Append(Response.data.type);
    sb.Append("<br/>");
    System.IO.File.AppendAllText(filePath + "productdelete.txt", sb.ToString());

    }
    else
    {
    sb.Append("null data found");
    System.IO.File.AppendAllText(filePath + "productdelete.txt", sb.ToString());

    }
    sb.Clear();

    return new HttpStatusCodeResult(HttpStatusCode.OK);
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 4, 2018 12:14 PM

All replies

  • User283571144 posted

    Hi brajalal,

    According to your description, I found you use " https://localhost/bigspot/api/webhooks/incoming/custom " as the destination URL.

    As far as I know, the webhook will send the request back if the hook fired. But your destination URL is localhost. The localhost means current server. In bigcommerce webhook, it means bigcommerce webhook server, so it couldn't send the request to your application.

    So you should use a public domain or IP address to let the webhook send the request to your application.

    From Registering and Testing Webhooks in bigcommerce, it used the ngrok to generate a public url.

    Best Regards,

    Brando

    Wednesday, November 21, 2018 7:08 AM
  • User-689094057 posted

    Hi Brando ,

    ,

    Thanks for reply i am also try to upload my app in public URL now may destination URL is https://bctest.randemgroup.com.au/api/webhooks/incoming/custom

    but still not get any response for hooks

    Thursday, November 22, 2018 12:12 PM
  • User-689094057 posted

    I am simply add a ActionResult in Home Controller not web hooks hit my ActionResult

    [HttpPost]
    [Route("webhooks/incoming/ProductDelete")]
    public ActionResult ProductDelete([System.Web.Http.FromBody] WebhookResponse Response)
    {
    StringBuilder sb = new StringBuilder();
    string filePath = System.Web.Hosting.HostingEnvironment.MapPath("~/Content/");
    if (!string.IsNullOrEmpty(Response.scope))
    {
    WebhookResponse rsp = new WebhookResponse();
    // rsp = JsonConvert.DeserializeObject<WebhookResponse>(context);
    sb.Append(Response.producer);
    sb.Append("<br/>");
    sb.Append(Response.scope);
    sb.Append("<br/>");
    sb.Append(Response.store_id);
    sb.Append("<br/>");
    sb.Append(Response.data.id);
    sb.Append("<br/>");
    sb.Append(Response.data.type);
    sb.Append("<br/>");
    System.IO.File.AppendAllText(filePath + "productdelete.txt", sb.ToString());

    }
    else
    {
    sb.Append("null data found");
    System.IO.File.AppendAllText(filePath + "productdelete.txt", sb.ToString());

    }
    sb.Clear();

    return new HttpStatusCodeResult(HttpStatusCode.OK);
    }

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, December 4, 2018 12:14 PM