Acumatica Webhooks

  • 9 December 2023
  • 5 replies
  • 548 views

Userlevel 7
Badge +17

Introduction

In the dynamic landscape of modern business, staying ahead requires more than just robust software it demands seamless integration and real-time data exchange. Enter Acumatica webhooks, the game-changing technology that empowers businesses to connect, communicate, and respond instantaneously.

In our latest exploration into the world of Acumatica, we delve into the realm of webhooks and how they revolutionize data interaction. Whether you're a business owner aiming for agility, a developer seeking efficient integrations, or an IT enthusiast passionate about cutting-edge solutions, this blog post is your gateway to understanding the power and potential of Acumatica webhooks.

Join us as we unravel the intricacies of this innovative feature, exploring its applications, benefits, and practical implementation. Discover how Acumatica webhooks act as the conduit between your business processes, enabling you to receive real-time updates, trigger actions, and enhance overall operational efficiency. I have developed Acumatica webhooks for many clients and would like to share them with you today.

What is an Acumatica Webhook?

  • A Webhook is an HTTP request, which is triggered by an event in a source system and sent to a destination system.
  • Within Acumatica, webhooks work as a (POST) REST web service endpoint. The external system triggers the webhook using the configured unique URL when an event occurs.

 

When to use Acumatica Webhooks?

Acumatica webhooks are a powerful tool designed to enhance connectivity and automate processes within the Acumatica ERP ecosystem. Knowing when to leverage this technology can significantly impact the efficiency and responsiveness of your business operations. Here are key scenarios where Acumatica webhooks shine:

Real-time Data Updates: 

  • Scenario: Your business relies on up-to-the-minute data for critical decision-making.
  • Use Case: Utilize Acumatica webhooks to receive instant notifications when specific data fields are updated. This ensures that decision-makers have access to the latest information without manual intervention.

Integrated Systems:

  • Scenario: Your organization uses various software applications like Magento/Shopify/BigCommerce, and seamless integration is crucial.
  • Use Case: Leverage Acumatica webhooks to facilitate real-time communication between Acumatica and other systems (Magento/Shopify/BigCommerce). This ensures that data is synchronized across platforms, eliminating the need for manual data entry and reducing the risk of errors.

Custom Alerts and Notifications:

  • Scenario: Your team needs immediate alerts for specific conditions or exceptions.
  • Use Case: Set up webhooks to generate custom alerts and notifications based on predefined criteria. For instance, receive an instant alert when inventory levels fall below a certain threshold, allowing your team to take proactive measures.

Advantages and Disadvantages of using Webhooks.

Advantages:

  • Real-time Notifications
    • Webhooks enable real-time communication, ensuring that data updates trigger immediate actions, leading to timelier decision-making.
  • Enhanced Connectivity:
    • With webhooks, Acumatica can seamlessly integrate with other applications and systems, fostering better connectivity and information exchange.
  • Customize the webhooks easily:
    • We can customize the Acumatica webhooks very easily by inheriting the IWebhookHandler interface.
  • Acumatica supports Webhooks from Acumatica 2020 R1.

Disadvantages:

  • Unreliable:
    • Webhooks can be considered unreliable in situations where either the source or destination system experiences downtime. In such cases, if either system is offline, webhook requests may not be processed.
  • Security Concerns:
    • Insufficient security measures can pose risks, including unauthorized access to webhook endpoints or potential exposure of sensitive data during communication. Implementing robust security practices is essential to mitigate these concerns.
  • Delivery Assurance:
    • Unlike traditional message queues, webhooks do not guarantee message delivery. If the receiving system is unavailable or experiences issues, there is no built-in mechanism to ensure the reliable delivery of webhook payloads.
  • Limited Error Handling:
    • Webhooks may have limited error handling capabilities. If an error occurs during the processing of a webhook request, there may be challenges in identifying and resolving issues, potentially leading to data inconsistencies.

Best Practices for the Webhooks implementation

  • Secure the Webhooks
    • Before processing any webhook request, it is essential to adhere to best security practices by validating the request's authenticity. This involves confirming that the request originates from the correct source. Additionally, it is highly recommended to enhance security further by transmitting an encrypted token from the source. Acumatica should then validate this token, ensuring that only legitimate and authorized requests are processed.
  • Error Handling and Logging:
    • Implement robust error-handling mechanisms to gracefully manage exceptions. Log detailed information about webhook activities, including successful deliveries and any encountered errors, to facilitate troubleshooting and monitoring.
  • Send Acknowledgment
    • Upon the successful processing of a webhook request, it is strongly advised to promptly send an acknowledgment to the source system. This acknowledgment serves as a confirmation, enabling the source system to comprehend the outcome of the request and take appropriate actions as needed. Establishing this feedback loop is a best practice, enhancing the overall reliability and transparency of the integration process. It ensures that both systems remain synchronized and facilitates a seamless flow of information between them.

Working with Acumatica Webhook Example

using System;
using System.Net.Http;
using System.Threading;
using System.Threading.Tasks;
using PX.Data;
using Newtonsoft.Json;
using System.Web.Http.Results;
using PX.Objects.SO;
using PX.Api.Webhooks;

namespace WebhookDemoProject
{
public class KNWebhookDemo : IWebhookHandler
{
public System.Web.Http.IHttpActionResult ProcessRequest(
HttpRequestMessage request, CancellationToken cancellationToken)
{
using (var scope = GetAdminScope())
{
if (request.Method == HttpMethod.Post)
{
try
{
var result = request.Content.ReadAsStringAsync().Result;
RootShipmenDetails shipmentDetails = JsonConvert.DeserializeObject<RootShipmenDetails>(result);
if (shipmentDetails != null && !string.IsNullOrEmpty(shipmentDetails.ShipmentNbr))
{
SOShipmentEntry shipmentGraph = PXGraph.CreateInstance<SOShipmentEntry>();
shipmentGraph.Document.Current = shipmentGraph.Document.Search<SOShipment.shipmentNbr>(shipmentDetails.ShipmentNbr);
if (shipmentGraph.Document.Current != null)
{
foreach (Pacakge item in shipmentDetails.Pacakges)
{
SOPackageDetailEx pkg = new SOPackageDetailEx();
pkg.Confirmed = item.Confirmed;
pkg.BoxID = item.BoxId;
pkg.Description = item.Description;
pkg.TrackNumber = item.TrackingNbr;
shipmentGraph.Packages.Cache.Insert(pkg);
}
shipmentGraph.Save.Press();
shipmentGraph.confirmShipmentAction.Press();

PXLongOperation.WaitCompletion(shipmentGraph.UID);
}
}
}
catch (Exception ex)
{
throw new PXException(Convert.ToString(ex.Message));
}
}
}
return new OkResult(request);

}

public Task HandleAsync(WebhookContext context, CancellationToken cancellation)
{
throw new NotImplementedException();
}
private IDisposable GetAdminScope()
{
var userName = "admin";
if (PXDatabase.Companies.Length > 0)
{
var company = PXAccess.GetCompanyName();
if (string.IsNullOrEmpty(company))
{
company = PXDatabase.Companies[0];
}
userName = userName + "@" + company;
}
return new PXLoginScope(userName);
}
}
}

 

23 R2 Changes in Webhooks

  • In 23 R2, Acumatica has removed Legacy Webhook Interface - PX.Data.Webhooks.IWebhookHandler.
  • We cannot publish the customization packages in 23 R2 with the Legacy Webhooks.
  • Developers should modify their solutions to work with webhooks that implement the PX.Api.Webhooks.IWebhookHandler interface.

Summary

In conclusion, Acumatica webhooks are a vital tool for modern businesses. They enable real-time integration, automation, and efficiency gains, making your Acumatica ERP even more powerful.

However, it's essential to be aware of potential challenges and limitations, such as security concerns, and dependency on external systems. By understanding these issues and implementing best practices, you can harness the full potential of webhooks while mitigating associated risks.

 

Happy Coding! 

 


5 replies

Userlevel 7
Badge +8

Great writeup Naveen.  Thanks for sharing! 

Userlevel 7
Badge

Thank you for sharing this great information with the community @Naveen Boga!

Userlevel 4
Badge

Do you have an 23R2 example with the new interfae?

Userlevel 4
Badge

Do you have an 23R2 example with the new interfae?

I have found an example https://help.acumatica.com/(W(1))/Help?ScreenId=ShowWiki&pageid=53fd37eb-6840-4709-a852-68bc6abc0a90 I'm leaving the link for anyone who needs it.

Userlevel 2

Hi @Naveen Boga,

Thank you for writing an article about webhooks in general and Acumatica webhooks in particular.
However, there are several important things not covered by the article.

First of all, while the article itself mentions the importance of security, the code example in the article does not perform security checks and at the same time uses a privileged admin account and updates the data in the database. This is a major security vulnerability. Developers who copy pasted this code introduced this vulnerability to their product.

Second, the recommendation on logging does not consider the already existing Request Log which provides simple webhook logging out of the box, so webhook developers do not need to implement it:
https://help.acumatica.com/Help?ScreenId=ShowWiki&pageid=f4e3f753-3408-409a-b797-1f6d1adf6182

The code example in the article does not provide any example of logging. The error processing logic  in the example does not log errors and is a bit strange:

catch (Exception ex)
{
throw new PXException(Convert.ToString(ex.Message));
}

It is not very useful to just wrap and re-throw the exception.  And there is no reason to convert to string the exception Message which is already string.

Third point is about the recommendation to send acknowledgment to the source system. This is no example in the code.

Moreover, according to one of our architects such requirement is rarely encountered in practice. Sending acknowledgment for a webhook usually means one more webhook which according to this recommendation should also send an acknowledgement. So, one more webhook is needed, and so on. This turns into an endless cycle.

Fourth point is about the incorrect information about Acumatica webhooks, their usage scenarios and their functionality. Here are two particular examples.

Custom Alerts and Notifications:

  • Scenario: Your team needs immediate alerts for specific conditions or exceptions.
  • Use Case: Set up webhooks to generate custom alerts and notifications based on predefined criteria. For instance, receive an instant alert when inventory levels fall below a certain threshold, allowing your team to take proactive measures.

Unfortunately, Acumatica webhooks do not support this scenario.

Customize the webhooks easily:

  • We can customize the Acumatica webhooks very easily by inheriting the IWebhookHandler interface.

Acumatica webhooks are not customizable. Interface implementation is an addition of a new webhook, not a customization of an existing one.

If you use AI tools to polish your articles please make sure that they did not add to the text any inaccurate information.

Finally, I also want to remind that this article describes the old webhook interface (as the article itself mentioned). The support for it was removed in Acumatica 2023R2.

For the description of how to configure webhooks starting from Acumatica 2023 R2 you can read the article from our Help Portal:
https://help.acumatica.com/Help?ScreenId=ShowWiki&pageid=53fd37eb-6840-4709-a852-68bc6abc0a90

You can find an example of a correct webhook implementation including security checks on Acumatica GitHub:
https://github.com/Acumatica/Help-and-Training-Examples/blob/2023R1/IntegrationDevelopment/Help/ConfiguringWebhooks/TogglWebhookHandler_Code/WebhookHandler/TogglWebhookHandler.cs

The implementation also contains an example of security checks for a webhook.

Reply


About Acumatica ERP system
Acumatica Cloud ERP provides the best business management solution for transforming your company to thrive in the new digital economy. Built on a future-proof platform with open architecture for rapid integrations, scalability, and ease of use, Acumatica delivers unparalleled value to small and midmarket organizations. Connected Business. Delivered.
© 2008 — 2024  Acumatica, Inc. All rights reserved