Loading ...

How to Implement Your Own MVC Controller in Acumatica

Today, I will walk you through how to implement your own MVC controller in Acumatica, specifically for version 24R1 and later. This approach is incredibly useful for creating custom endpoints within Acumatica.

Why Choose an MVC Controller?

  1. Custom API (URL) Creation
    With this method, you can define your own API routes in Acumatica.
  2. An Excellent Alternative to Acumatica Webhooks
    Unlike Acumatica’s webhooks, which lack URL customization and are not static, this approach provides a permanent, static route. If a webhook is deleted, you need to recreate it and update its URL in all integrations. With a static route, your endpoint remains functional as long as your package is published.

Additionally, you can leverage all the powerful parameters available in ASP.NET Core, which are not supported by webhooks.

Setting Up Your MVC Controller in Acumatica

For this demonstration, we will create a new project named DemoProj.

Step 1: Add the Required References

To begin, add the following references to your project:

  • Microsoft.AspNetCore.Mvc.Abstractions
  • Microsoft.AspNetCore.Mvc.Core
  • Microsoft.AspNetCore.Mvc
  • Microsoft.Extensions.DependencyInjection.Abstractions
  • Microsoft.Extensions.Options.ConfigurationExtensions
  • PX.Hosting


Step 2: Create the Configuration Class

Next, create a class named Config.cs to implement the necessary logic for your controller. This class will register your custom routes and handle the required dependencies.



 

 Next, create a class named HtmlResult.cs for demonstration the result


 

Step 3: Implement the Controller Logic

Define a controller method that will handle the incoming requests. For example, using a route like:
http://localhost/<InstanceName>/my-api/demo,
you can create a method like this:


 

The Benefits of a Static Route

By following this approach, you gain a static route that will always exist as long as your package is published. You can confidently rely on it across integrations without worrying about reconfigurations. Additionally, this method opens the door to a wide range of ASP.NET Core features, making it a robust solution for Acumatica customizations.


By implementing your own MVC controller, you unlock flexibility and control over your endpoints, ensuring a seamless experience for your integrations.