cflow Webhooks

Use webhooks to get instant cflow notifications along with data. You can receive the data in real time and use it in various applications.

You might use webhooks for all events in Cflow.

Events in Cflow:

  • Create a new request.
  • Update a request (Approve or reject).

Start using Cflow webhooks by following the steps below –

Setup webhook in Cflow:

  • Log in to your Cflow account and click security settings from admin tab. Click the Web Services icon.
  • Click on ‘Add your Web Service’ button.
  • Select your workflow and paste the url for receiving webhook notification.

Receive webhook notifications:

  • First you need to create a webhook endpoint on your server.
  • Setup the webhook in Cflow.
  • Once setup completed, you will receive the data when create, update and approve a request in Cflow.
  • Webhook data received in your endpoint as JSON.
  • After parsing the JSON, you can get event name, workflow name, stage name and fields of the stage.

Example Scenario –

Lets say I have a internal Project Calendar application that I use for tracking all employee tasks and would like to mark employee time off as ‘Not Available’. The time off requests are processed in Cflow and I would like to use a webhook to receive notification when a time off request has been approved.

End Point URL – https://democompany.cavintek.com/ProjectCalendarApp/timeoff

Here are the sample output from Cflow

Webhook notification output – Apply a leave in Cflow:

{“Fields”:[{“ID”:”12″,”Employee No”:”E001112″,”Employee Name”:”Steve”,”Submitted Date”:”08/12/2016″,”Leave Type”:”Casual”,”From Date”:”12/12/2016″,”To Date”:”20/12/2016″,”Reason”:”Going vacation to Europe.”,”Manager Notes”:””,”Manager Approval Approved By”:””,”Manager Approval Approved Date”:””,”Manager Approval Status”:”New”,”Manager Approval Comments”:””,”HR Approval Approved By”:””,”HR Approval Approved Date”:””,”HR Approval Status”:”New”,”HR Approval Comments”:””,”END Approved By”:””,”END Approved Date”:””}],”Event”:[{“Event Name”:”Insert”,”Workflow Name”:”Leave Process”,”Stage Name”:”Leave Form”}]}

Webhook notification output – Approved by a manager in Cflow:

{“Fields”:[{“ID”:”12″,”Employee No”:”E001112″,”Employee Name”:”Steve”,”Submitted Date”:”08/12/2016″,”Leave Type”:”Casual”,”From Date”:”12/12/2016″,”To Date”:”20/12/2016″,”Reason”:”Going vacation to Europe.”,”Manager Notes”:”All tasks of Steve given to Martin.”,”Manager Approval Approved By”:”steve”,”Manager Approval Approved Date”:”08/12/2016″,”Manager Approval Status”:”Approved”,”Manager Approval Comments”:”Happy Journey Steve.”,”HR Approval Approved By”:””,”HR Approval Approved Date”:””,”HR Approval Status”:”New”,”HR Approval Comments”:””,”END Approved By”:””,”END Approved Date”:””}],”Event”:[{“Event Name”:”Update”,”Workflow Name”:”Leave Process”,”Stage Name”:”Manager Approval”}]}

Our goal is when a manager approves the time off request for an employee, we need to check if the event name is ‘Update’ and Manager Approval Status is ‘Approved’. If these conditions are satisfied, we will take the values and update the calendar in our “Project Calendar” app based on the values of Employee No, Employee Name, From Date and To Date.

Here is a sample C# code to achieve read the JSON output and update in the internal Project Calendar App.

[Route(“api/webhooks/incoming/cflow/”)] [System.Web.Http.AcceptVerbs(“GET”, “POST”)] [System.Web.Http.HttpGet] public HttpResponseMessage ReceiveCflowHook(JObject data)
{
try
{
var dataAsString = Newtonsoft.Json.JsonConvert.SerializeObject(data);
switch (data[“Event”][0][“Event Name”].ToString())
{
case “Insert”:
{
break;
}
case “Update”:
{
switch (data[“Event”][0][“Workflow Name”].ToString() + “-” + data[“Event”][0][“Stage Name”].ToString())
{
case “Leave Process-Manager Approval”:
{
if(data[“Fields”][0][“Manager Approval Status”].ToString().ToLower().Equals(“approved”))
{
MarkTimeOff_ProjCalendar(data[“Fields”][0][“Employee No”].ToString(), data[“Fields”][0][“Employee Name”].ToString(), data[“Fields”][0][“From Date”].ToString(), data[“Fields”][0][“To Date”].ToString());
}
break;
}
default:
{
break;
}
}
break;
}
default:
{
break;
}
}
return new HttpResponseMessage()
{
Content = new StringContent(dataAsString, System.Text.Encoding.UTF8, “application/json”)
};
}
catch (Exception ex)
{
new HttpResponseMessage()
{
Content = new StringContent(“error”, System.Text.Encoding.UTF8, “application/json”)
};
}
}
public void MarkTimeOff_ProjCalendar(string Emp_No,string Emp_Name,string From_Date,string To_Date)
{
}