Discover the Power of MuleSoft and EDI: Effortless X12 Data Transformations

MuleSoft and EDI, the dynamic duo

Much of the business world runs on business-to-business (B2B) Electronic Data Interchange (EDI) transactions. The data in these EDI transactions is difficult for humans to read, but MuleSoft makes it simple to work with. This example will walk through the straightforward process for converting an input EDI file (an X12 810 Invoice) to and from a more human-readable JSON format. Note: While it isn’t shown here, MuleSoft can handle any additional transformation and orchestration of this data. Whether the EDI data needs to be used to update your ERP, update your CRM, notify a user, or perform any other processing, MuleSoft and EDI enable great solutions.

Design Center

For this MuleSoft and EDI example, we created an API specification in Design Center. This API specification is a standard MuleSoft development practice; it is not the focus of this post. However, note that this example API specification has two endpoints: one for taking in an input X12 810 (Invoice) payload and returning invoice JSON as a response payload, and one for taking input invoice JSON and converting it to an X12 810 (Invoice) response payload. The API specification defines the data structure of the JSON invoices. The spec is named example-edi-papi (for “Example EDI Process API”) and published to Exchange so that it can be imported into Anypoint Studio to develop from.

MuleSoft Design Center

Anypoint Studio Development

In Anypoint Studio, we create a new Mule project and have it import the latest published version of example-edi-papi from Exchange.

New MuleSoft Project screen

This creates a basic MuleSoft project and stubs out Flows for each endpoint in the imported API (so, one for /810-to-invoice-json and one for /invoice-json-to-810).

JSON to 810 project screen

This example requires the X12 Connector from Anypoint Exchange. To get it, go to the Mule Palette -> Search in Exchange -> Search for “X12”. Select the “X12 EDI Connector – Mule 4” and click Finish:

Add an X12 EDI connection to MuleSoft project

This opens up 3 X12-related options in the Mule Palette:

X12 Palette

Read, Write, and Write Batch. This example will use the Read and Write components. (The Write Batch component is useful for merging multiple transactions into a single X12 payload; this example demonstrates a simpler case.) The /810-to-invoice-json flow will use Read as the flow will read the input X12 810 message and transform it (using DataWeave) to JSON. The /invoice-json-to-810 flow will use Write as it will convert the input JSON to a Map object and the Write component will convert the Map object into text formatted as an X12 810 document.

For this MuleSoft and EDI example, the flows will look as follows:

JSON and X12 mapping flow

As shown, the X12 Read component takes the input (the POSTed X12 810 payload) and generates a Map object. A DataWeave Transform is used to convert from the Map object to the specified JSON format. And as shown, the invoice-json-to-810 flow’s DataWeave Transform component takes the input (the POSTed JSON matching API spec format) and generates a Map object. The X12 Write object takes the Map object and generates the X12-810-formatted response.

To get this to work, the X12 components must be configured. In this case, the Read and Write components can both reference the same X12 Connector configuration: X12_810_EDI_Config

X12 Configuration selector

To set up the configuration initially, create a new Connector configuration by clicking the green Plus sign from the prior screen shot. This pops up the X12 EDI Config window. Many settings can be toyed with, but the key setting is Schema definitions. Change this to “Edit inline” and enter a value of “x12/004010/810.esl” and click OK. This sets up the X12 configuration to be pointed at version 004010 of the 810 (Invoice) schema.

X12 EDI connection configurator

Note: To see additional schemas you can choose from, go to your project in Package Explorer and find “X12 EDI”. Expand this and expand x12-schemas-<version>.jar. Inside there are packages for hipaa and x12, each of which contain many folders with different X12 document schemas. These are the schemas being referenced in the “inline” schema definition provided above. Also, custom schemas can be added to src/main/resources of a MuleSoft API if the required .esl schema is not found in the x12-schemas JAR.

JAR file selection

After configuring the X12 EDI Config, set X12_810_EDI_Config as the config for both the X12 Read and the X12 Write component in the application.

With this set up, a very interesting exercise is to simply send a valid X12 810 message to the /810-to-invoice-json endpoint and setting a breakpoint directly after the Read component to examine the Map object generated by the X12 Read.

JSON to X12 Map Object read

MuleSoft Variable and Watches screen

From this object generated by the Read component, a DataWeave transform can be applied to produce the appropriate JSON. This post won’t go into detail on that DataWeave transformation, but just know that it is a standard MuleSoft DataWeave transform. MuleSoft makes the transformation straightforward and even provides helpful examples in Anypoint Exchange in case developers are struggling to get started with these X12 data transformations for MuleSoft and EDI.

Output Payload screen

The invoice-json-to-810 flow does the transformation in the opposite direction, so the DataWeave transformation is the first step of that flow.

Output payload second screen

The details of this DataWeave transformation are not the important piece of this example; the transform details will differ from use case to use case. However, this example shows just how easy it is to work with X12 data in MuleSoft and convert it to and from whatever data types are required to run the business.

JSON POST output

Not only can MuleSoft help transform the data to and from many different formats, but it can be set up to handle the connectivity to downstream systems which require some or all the data contained in the X12 transaction sets. From batch to real time, from JSON to X12, and from API to EDI, MuleSoft is a powerful integration platform with capabilities to easily handle numerous MuleSoft and EDI use cases.

Check out the linked video below to see this in action in a live example.

Talk to the Professionals!

To learn more about our MuleSoft RPA, MuleSoft and EDI, or Salesforce services, please visit our website or fill out a Contact Us form here.

CloudFirst Labs logo