Articles in this section

Understand content-based routing for AS2 connections

Content-based routing (CBR) is the way to determine which flow to run when a single AS2 connection is set up for multiple flows. If you configure multiple flows using the same AS2 connection, integrator.io uses content-based routing to determine which flow to run for a given message.

See how files sent with AS2 are synced

To understand how CBR works, and at what point in the integration process it’s used, it’s helpful to understand the routing mechanism of messages transmitted through an AS2 connection on integrator.io, and how they are directed to the intended flow.

We handle messages sent through an AS2 connection in stages that follow this order:

AS2_connection.jpg
  1. Receive a message: There is only one URL integrator.io uses to receive messages: https://api.integrator.io/v1/as2 .

  2. Check the receiver: We look at the unique ID of the recipient. The ID tells us which integrator.io account is meant to receive this message.

    Example: Your partner, Walmart, sends you a file of sales orders. When Walmart sends the file, your unique ID is in one of the headers.

  3. Check the sender: We look at the unique ID of the sender. The combination of the sender and recipient IDs tells us which connection the info belongs to.

    Example: When your partner, Walmart, sends a file of sales orders to you through an AS2 connection, their ID will be in the AS2 message header.

  4. Look at the content (CBR): In the case of a single AS2 connection used in multiple flows, we need to figure out which flow a given message is meant to run. We use the routing rules you define with a small amount of JavaScript to identify the right flow. You will use components from a message from your trading partner, like the form type or a header name, in the code you write. The function output must result in the ID number of the flow you want to route the message to. The message will then run the intended flow. We call this content-based routing.

    Example: You have a flow set up to sync your Walmart sales orders with your NetSuite ERP, and a separate flow that syncs your Walmart change orders with your Shopify shipping orders. We have to look at the content of the message being sent to you from Walmart to know which flow the files should be run through.

  5. Choose the flow: After we’ve identified who the message is to, who it’s from, and what kind of data files are being sent, we send the files to the intended flow.

Understand the CBR rules

In step 4 above, “Look at the content (CBR),” we see at what point in the reception of a message through an AS2 connection CBR would be used. We also see that the routing process is determined by rules that you, the user have pre-set. The way you will set these rules is by writing a small amount of JavaScript in our Routing Rules Editor. You will write the script with components from a message from your trading partner. The output must be the ID of the flow you want the message to run. You can find the flow ID in the URL of the flow.

You will know if and when you need to set rules because integrator.io will prompt you once it recognizes that one AS2 connection is being used in more than one flow. [i]

Understand the Routing Rules Editor

Define the rules that integrator.io will use to send messages from your trading partners to the right flow. Script-based routing rules determine the way inbound files received are sent to the correct flows. Click Launch.

  1. Function: You can change the function name to meet your integration’s needs. Although your script may contain additional functions, only the single entry point specified here is initially called and receives any data passed in the HTTP header and body. The name of the function in the default Handle request stub is <tt>handleRequest</tt>. If you used a different name, you can click Edit script to open it and copy the exact name (without parentheses).You can change the function name to meet your integration’s needs.

  2. Script: You can use a script you’ve already written and saved. If you know you will want to reuse the script that you’ve just written, you can save it by clicking the plus sign next to the Script dropdown. A window will pop up on your screen prompting you to name the script and add a description.

    You will use the Script editor to define the rules that integrator.io will use to send messages from your trading partners to the right flow.

    AS2_CBR_editor.jpg
  3. Insert content-based flow router stub: The stub combines the comment and the sample function in the “Script content” panel. It explains the structure of the ‘options’ argument that will be passed to the function, that you can change the name of the function, and what the output needs to be. Beneath the comment, in multi-colored text, is a sample function. You can delete the stub to write your script. If you need info from the stub, you can reinsert it with this button.

  4. Function input: In this panel, you will find a sample of the type of message you will receive from your trading partner. It will be displayed in the ‘options’ argument structure described in the contentBasedFlowRouter stub. You can modify the content of this panel.

    Example: You can paste an EDI message from your trading partner into this panel. Then, you can use the info from this panel in the functions you write to define your routing criteria. You will write the functions in the “Script content” panel.

  5. Function output: When you have written your script, you can test it by clicking the Preview button at the bottom right of the editor. Your results will appear in this panel.

  6. Either click:

    1. Save: click to save the changes.

    2. Save & close: click to save the changes and exit the script editor panel.

    3. Close: click to exit without saving any new changes.

Set the rules

When you use an existing AS2 connection to build a flow, a message will pop up on your screen.

Note

You’ll need to get the ID for the flow you’re setting you’re setting up rules for from that flow’s URL before you start.

  1. At the bottom right of the pop-up, click Routing Rules Editor. The editor will open on your screen.You can change the rules at any time. Use the Export Form to launch the Routing Rules Editor. The Routing Rules Editor button will be in the middle of the form.

  2. On the right, you can paste sample data from a message from your trading partner into the “Function input” panel. Identify the message components you want to build your functions with.

    Routing_rules_editor.jpg
  3. On the left, write your functions or insert functions from scripts you already have saved in integrator.io.

  4. At the bottom right, click Preview . In the bottom left under “Function output,” make sure that the output is the ID number of the flow you want the message to run

  5. When you’re ready to save your code, at the bottom right, click Accept .

Example to identify the EDI record type

If you configured a purchase order and purchase order change request flow using the same AS2 connection, integrator.io identifies the record type using content-based routing.

Note

In the content-based routing editor, in the script enter the flow ID and export ID manually.

For example, in the below script, ST*850* refers to the purchase order record, and ST*860* refers to the purchase order change record.

Note

In the script below, * refers to the element delimiter separator to differentiate between multiple fields.

function contentBasedFlowRouter (options) {

  let returnObj = null;

  if(options.rawMessageBody.includes('ST*850*')){

  returnObj =
  {
    _flowId: "65278197d0117ae81be23e53", // flow_id is required for downstream processing.
    _exportId: "652781966ea8a2e6a619c7e4" // the '_id' of the listener that should be run.
  }
  }
  else if(options.rawMessageBody.includes('ST*860*'))
   returnObj =
  {
      _flowId: "65278197d0117ae81be23e55", 
      _exportId: "652781966ea8a2e6a619c7xx"
  }
  return returnObj;
}

Find out more on AS2 connections and how to set one up.

Was this article helpful?
1 out of 1 found this helpful

Comments

0 comments

Please sign in to leave a comment.