Create Sitefinity connectors using service hooks

Overview

The service hooks in Sitefinity provide a powerful and easy mechanism for creating custom connectors that can update external systems when an event occurs in Sitefinity. For example, you can create a HubSpot contact when a user logs in Sitefinity. To do that you need to create custom triggers and custom actions for the service hooks.

Create custom triggers

You can register your own triggers and actions. They should be registered in custom Sitefinity modules as shown in the sample below. For more information, see Custom modules

To register a trigger, you need to implement IServiceHookTriggerProvider interface in your module. You also need to create a new trigger class that inherits from ServiceHookTriggerSettingsBase

When defining trigger settings, you need to add this data in constructor: 

  • key - unique key for the trigger (can be any string) 
  • triggerTitle - title to be displayed in the UI. 
  • eventType – EventHub event that you want to track 
  • module - name of the module to be displayed in the UI

    Also, you can add additional event filter in the IsMatch function. 

Create custom actions 

To register custom actions, you must implement IServiceHookActionProvider interface in your module. In addition, you need to create new action setting class that inherits from IServiceHookActionSettings or the built-in WebhookActionSettings 

When defining action setting you need to

  • Define unique Key
  • Define action Title that is displayed in UI
  • Define ParametersType property (Can be left null if no parameters are needed for the action). The properties of the provided type will be rendered in the Create screen of the Service hooks page and the configured values will be available later during the execution of the action. How the properties are rendered in the UI depends on their type and provided attributes. For more information, see Create widget designers. The properties values will be stored in Advanced settings. If you’d like to encrypt the data in the configurations you can decorate the property with [Sitefinity.Configuration.SecretData] attribute. And if you’d like to hide the field’s value in the UI you can decorate it with the [DataType(customDataType: KnownFieldTypes.Password)] attribute.

To complete the action, you must implement the ExecuteActionAsync method as shown in the sample

Finally, you need to register the trigger and the action in a Sitefinity module: 

After you have implemented and registered your custom action and trigger you are ready to configure your first service hook using the new connector.

  1. Navigate to Administration » Servicehooks
  2. Click Create.
  3. Select your newly created trigger and action using the selectors. 

Customize UI fields 

By providing a value for the ParemtersType in the trigger and in the action you can easily build custom UI for your connectors. But if the built-in functionalities are not enough you can customize the fields in the create/edit screen using the Admin App extensions. Learn more about custom fields in GitHub.  

 

Increase your Sitefinity skills by signing up for our free trainings. Get Sitefinity-certified at Progress Education Community to boost your credentials.

Get started with Integration Hub | Sitefinity Cloud | Sitefinity SaaS

This free lesson teaches administrators, marketers, and other business professionals how to use the Integration hub service to create automated workflows between Sitefinity and other business systems.

Web Security for Sitefinity Administrators

This free lesson teaches administrators the basics about protecting yor Sitefinity instance and its sites from external threats. Configure HTTPS, SSL, allow lists for trusted sites, and cookie security, among others.

Foundations of Sitefinity ASP.NET Core Development

The free on-demand video course teaches developers how to use Sitefinity .NET Core and leverage its decoupled architecture and new way of coding against the platform.

Was this article helpful?