How to setup webhooks in Outsystems?

How to setup webhooks in Outsystems?

  

Since a day or to I have been experimenting with REST API, mainly with MailChimp and EcWid. So far so good.


Now I want to start using webhooks in order to be notified of things changing in either environment. Both have the capability for using webhooks.


But I'm not sure how to setup webhooks in Outsystems. Tried to look at the GitHub webhook listner example but I still don't get it (https://www.outsystems.com/forge/component-details/525/GitHub+Webhooks+Listener/).


Can anybody please explain how to setup webhooks in Outsystems? Thanks in advance,


Rikki

Hi Rikki.

I don't know your use cases, but the easiest way to implement webhooks in Outsystems is by using a common empty screen (which will serve as the endpoint for your webhook) and you'll implement your specific logic inside the screen Preparation.

Another way you can do this is by creating specific REST APIs for each method you need and then use each endpoint on the webhooks.

Personally, this second approach is way better and more correct.

Cheers,

GM

Thanks for your quick reply Gonçalo.

I want to implement your second proposed method. Unfortunately I don't know how to create this specific type of REST API. How can I configure this?

- Do I need to choose 'Consume REST API" or "Expose REST API" (I think the latter?)

- And then I have to add a method of type 'Post'?

- If so, where can I configure request and response JSON structure?

As you may have noticed I'm almost completely in the dark here. Tried looking for a good example but unfortunately I didn't find any. Can you please give me a run-through on how to do webhooks properly in Outsystems, preferably with Mailchimp webhooks? Would be very much appreciated, thank you very much in advance,

Cheers, Rikki

Hello Rikki.

Sorry about the delay on the reply.

- You must choose Expose REST API.

- The type of method will depend on the methods you're implementing, just like any REST API, this is nothing to do with the Outsystems platform. 

See a simple example I just did to test it:


Currently, I don't have any example to send you since the only thing I have is very business specific and is a product I have no permissions to share, for legal reasons.

Hope it helps.

Cheers,

GM

Hello Gonçalo,


Thanks for your reply and effort! I tried to replicate your example but somehow the REST API isn't fired when an email-adress is changed in MailChimp. Strangely enough, when I set the same thing up as a webpage servicing as webhook-endpoint it works well. The only time the REST API is triggered is when I administer the webhook in Mailchimp. After saving the webhook-entry the REST API is triggered once, but with a blank HTTP-request.

I have set up a listner outside outsystems (RequestBin) to verify that MailChimp is sending the trigger properly. It does. In RequestBin I can validate it receives a raw-textstring like: 

type=upemail&fired_at=2017-06-20+14%3A13%3A34&data%5Bnew_id%5D=f255d8a172&data%5Bnew_email%5D=erik.geelhuijzen%40hotmail.com&data%5Bold_email%5D=erik_geelhuijzen%40hotmail.com&data%5Blist_id%5D=a73a8a9d41

With the webpage and using GetRequestContent (with 'Include Headers' to false) I can receive the raw-textstring in Outsystems.


But then another problem I'm having: I'm not sure how to handle this raw textstring and convert it into something useful. I would like to change this into a Structure after which I can use this structure to make changes to records in my database. After I have received the trigger and read the HTTP-request with GetRequestContent I'm not sure what to do with the resulting text-string. I tried to change it with ardoJSON  (using JSON2RecordList) and JSON Deserialise but they give me errors. I took a look at the demo for ardoJSON (https://ardoric.s3.amazonaws.com/ardoJSON/ardoJSONDemo.oml) and think I have set things up according example 06: Reading a JSON Object, but that gives my an error 'Unable to cast object of type 'ssMailChimp.ENChangeEmailMailChimpEntityRecord' to type 'OutSystems.HubEdition.RuntimePlatform.Db.IOSList'.' I have created the structure according to definition as found on website Mailchimp:

"type": "upemail",
"fired_at": "2009-03-26 22:15:09",
"data[list_id]": "a6b5da1054",
"data[new_id]": "51da8c3259",
"data[new_email]": "api+new@mailchimp.com",
"data[old_email]": "api+old@mailchimp.com"


So basically I still have two problems:

1. the REST API isn't triggered (but thankfully there is an ugly backup-plan that works)

2. I don't know how to change the raw received text into something useful in Outsystems

I really hope you will, once again, take the effort to help me, much appreciated! Thanks in advance,


Cheers Rikki


Hi Rikki.

I'll try to check your first issue later because now I really don't have time.

About your second issue, I would suggest creating an extension (C# or Java, depending on your platform stack) with a method that receives the Raw data you get and there you'll parse it and return the values and structure you need.

Cheers,

GM

Hi Gonçalo,


Again, thanks for suggestions. I was wondering why that is needed? RequestBin is able to interpret the raw data without any programming and translates the raw data into something usefull on the fly.

On the top left you can see the automatically generated output from the raw body that is also shown at the bottom. This output matches the definition given by Mailchimp on there website (see http://developer.mailchimp.com/documentation/mailchimp/guides/about-webhooks/#event-sources for details).


What am I missing here? Isn't there a simpler way to accomplish the same within OutSystems?

Cheers, Rikki

Solution

Hi Rikki.

I did a quick test and was able to do the communication.

Also used the method GetFormValue from the extension HTTPRequestHandler to get the values as you needed.

I got something like this:

Since it was a very quick test, I had to do a small workaround (I'm pretty sure there's an elegant way to do that), which was to create the Rest method as Get, added it to Mailchimp and then changed it to Post and it worked.

Hope it helps.

Cheers,

GM

Solution

Hi Gonçalo,

Thank you so much for your efforts. With your latest suggestions I was able to make it work. I now have my first working webhook SOAP API!


Could not have done it without you! Thanks again.

Cheers, Rikki

Thanks for your quick reply Gonçalo.

I want to implement your second proposed method. Unfortunately I don't know how to create this specific type of REST API. How can I configure this?

- Do I need to choose 'Consume REST API" or "Expose REST API" (I think the latter?)

- And then I have to add a method of type 'Post'?

- If so, where can I configure request and response JSON structure?

As you may have noticed I'm almost completely in the dark here. Tried looking for a good example but unfortunately I didn't find any. Can you please give me a run-through on how to do webhooks properly in Outsystems, preferably with Mailchimp webhooks? Would be very much appreciated, thank you very much in advance,