module vs provider to call external api

Ivan Louw asked on July 26, 2021 08:38

Hi Guys, I have the following scenario: After form submission from certain pages, I have to call and external API, where some custom business logic is applied before calling the api. There is also a security aspect as some the data is classified as sensitive.

Is the best place to do in a custom provider or module.

Thanks, Ivan

Correct Answer

Sean Wright answered on August 11, 2021 02:34

A global event can be fire and forget, but it only works within the process of the application that starts the event.

This means starting a global event (built-in or custom) in the Content Management application would not be seen by the Content Delivery application (this is why global event handlers need to be deployed to both applications to work for all triggered events).

You might want to look at custom web farm tasks to transfer data to other instances of the application when an event occurs.

Another non-Kentico Xperience specific option would be to use something like an external queue service that the Content Management app could insert messages into and the Content Delivery application could de-queue from.

0 votesVote for this answer Unmark Correct answer

Recent Answers


Dmitry Bastron answered on July 26, 2021 10:54

Hi Ivan,

I guess you mean form built via Form Builder, right? In this case I would recommend using Global Events for Forms and implementing your logic in either Insert Before or After events.

What do you mean exactly by "sensitive data"? If this is personal data, you can use Data Protection module to register these fields and implement GDPR policies for right to be forgotten and right to access, check out the docs. Or do you mean you cannot store this data in the database at all?

2 votesVote for this answer Mark as a Correct answer

Sean Wright answered on July 27, 2021 03:51

Ivan,

I agree with Dmitry - Global Events are the best option here.

Note that these events will execute in both the Content Management (Administration) and Content Delivery (MVC) applications. Whether or not your custom Global Event handling code executes depends on whether or not your code is deployed to either application.

If you don't want code to execute while the form is being saved to the database (which could delay form submission) you can also create a custom scheduled task that would only be executed in the Content Management application, out of band from the form submission.

This task could submit data to an external API.

1 votesVote for this answer Mark as a Correct answer

Ivan Louw answered on August 5, 2021 04:49

Hi Guys, Sorry for only getting back to you now, was out off office.

I already have some global event subscriptions, so I will hook this up there as well.

Just an other requirement that has come through, what if I need to call that service from an other page that does not have a form.

Do I need to create a form event, or is there another better way to access the api form various sources?

0 votesVote for this answer Mark as a Correct answer

Sean Wright answered on August 5, 2021 06:29

Maybe you can centralize the API call business logic in a service that is accessed through a shared library?

Call the service from the global event and from the page that doesn't have the Form.

0 votesVote for this answer Mark as a Correct answer

Ivan Louw answered on August 11, 2021 02:12

Hi Sean, The service is in a shared library. So a custom event should work.

but I dont want the service to accessible through the front end website, I want to force the call through the admin site as it more secure.

An other thing I will need to do is return some data to front end site. Is this possible using a global event, is a global event not just a fire and forget?

0 votesVote for this answer Mark as a Correct answer

Ivan Louw answered on August 11, 2021 02:39

Hi Sean, I will need to write a POC and she which one works best. Thanks for the info, will get back to you should I need more info. Ivan

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.