1

Hi I'm looking to create a simple webhook receiver and dump the data into a table.

This is for receiving SMS using Zipwhip. Zipwhip will send a post with JSON.

Need to receive the JSON and process.

What is a simple way to accomplish this.

Thanks in advance.

Mark Ren
  • 21
  • 1
  • 3
  • 1
    Hi Mark, you should include include all context in your question like what the JSON payload of the callback is, what table you want to store it in, etc. The more context you can provide, the better others will be able to answer your question. To Downvoters/closers please don't just downvote/close on first time askers, leave a comment that can help direct them on asking better questions, punishing questions without comment is discouraging and hostile to new users. – mythz Oct 31 '19 at 20:13

2 Answers2

1

In ServiceStack your callback would just need to match the shape of your Response DTO, e.g:

[Route("/path/to/callback")]
public class CorpNotes
{
    public int Departments { get; set; }

    public string Note { get; set; }

    public DateTime WeekEnding { get; set; }
}

// Example of OrmLite POCO Data Model 
public class MyTable {} 

public class MyServices : Service
{
    public object Any(CorpNotes request)
    {
        //... 
        Db.Insert(request.ConvertTo<MyTable>());
    }
}

Example uses Auto Mapping Utils to populate your OrmLite POCO datamodel, you may want to do additional processing before saving the data model.

If the callback can send arbitrary JSON Responses in the payload you can use an object property to accept arbitrary JSON however we'd recommend using Typed DTOs wherever possible.

mythz
  • 141,670
  • 29
  • 246
  • 390
0

This can be what the receiving method in your controller can look like on the receiving side. Make sure that your receiving and sending json object match.

    [HttpPost]
    [Route("Edit")]
    public JsonResult Edit([FromBody] CorpNotes newMessage)

        {return Json(TotalWeekNoteSearch);}

public class CorpNotes
{
    public int Departments { get; set; }

    public string Note { get; set; }

    public DateTime WeekEnding { get; set; }
}

I am actually working on a .net project receiving Json from a Angular front end, so this should be the same concept. Also make sure that what you are receiving is truly a workable object such as.

    {Departments: 4, Note: "This is notes 2020Q1W13", WeekEnding: "2020-01-25T00:00:00"}

Also try looking into this example which would be helpful in regards to webhooks.

public class MyWebHookHandler : WebHookHandler
{
    public MyWebHookHandler()
    {
        this.Receiver = "custom";
    }

    public override Task ExecuteAsync(string generator, WebHookHandlerContext context)
    {
        CustomNotifications notifications = context.GetDataOrDefault<CustomNotifications>();
        foreach (var notification in notifications.Notifications)
        {
            ...
        }
        return Task.FromResult(true);
    }
}

The type of the data is typically JSON or HTML form data, but it is possible to cast to a more specific type if desired.

JSkyS
  • 413
  • 6
  • 14
  • Thank You @JSkyS. What type of project do i need to create? it is not going to do anything else. We set up a IIS Server just for this. – Mark Ren Oct 31 '19 at 19:47
  • Are you using ASP.net Webhooks? I couldn't find proper documentation for it. – Mark Ren Oct 31 '19 at 19:48