Encode and decode flat files in Azure Logic Apps

Before you send XML content to a business partner in a business-to-business (B2B) scenario, you might want to encode that content first. By building a logic app workflow, you can encode and decode flat files by using the built-in Flat File actions.

Although no Flat File triggers are available, you can use a different trigger or action to get or feed the XML content from various sources into your workflow for encoding or decoding. For example, you can use the Request trigger, another app, or other connectors supported by Azure Logic Apps. You can use Flat File actions with workflows in the Logic App (Consumption) and Logic App (Standard) resource types.

Note

For Logic App (Standard), the Flat File actions are currently in preview.

This article shows how to add the Flat File encoding and decoding actions to an existing logic app workflow. If you're new to logic apps, review the following documentation:

Prerequisites

  • An Azure account and subscription. If you don't have a subscription yet, sign up for a free Azure account.

  • An integration account resource where you define and store artifacts, such as trading partners, agreements, certificates, and so on, for use in your enterprise integration and B2B workflows. This resource has to meet the following requirements:

    • Is associated with the same Azure subscription as your logic app resource.

    • Exists in the same location or Azure region as your logic app resource.

    • If you're using the Logic App (Consumption) resource type, your integration account requires the following items:

    • If you're using use the Logic App (Standard) resource type, you don't store schemas in your integration account. Instead, you can directly add schemas to your logic app resource using either the Azure portal or Visual Studio Code. You can then use these schemas across multiple workflows within the same logic app resource.

      You still need an integration account to store other artifacts, such as partners, agreements, and certificates, along with using the AS2, X12, and EDIFACT operations. However, you don't need to link your logic app resource to your integration account, so the linking capability doesn't exist. Your integration account still has to meet other requirements, such as using the same Azure subscription and existing in the same location as your logic app resource.

      Note

      Currently, only the Logic App (Consumption) resource type supports RosettaNet operations. The Logic App (Standard) resource type doesn't include RosettaNet operations.

  • The logic app workflow, blank or existing, where you want to use the Flat File action.

    If you have a blank workflow, use any trigger that you want to start the workflow. This example uses the Request trigger.

Limits

Make sure that the contained XML groups in the flat file schema that you generate doesn't have excessive numbers of the max count property set to a value greater than 1. Avoid nesting an XML group with a max count property value greater than 1 inside another XML group with a max count property greater than 1.

Each time that the flat file schema allows the choice of the next fragment, the Azure Logic Apps engine that parses the schema generates a symbol and a prediction for that fragment. If the schema allows too many such constructs, for example, more than 100,000, the schema expansion becomes excessively large, which consumes too much resources and time.

Add Flat File Encoding action

  1. In the Azure portal, open your logic app workflow in the designer.

  2. If you have a blank workflow that doesn't have a trigger, add any trigger you want. Otherwise, continue to the next step.

    This example uses the Request trigger, which is named When a HTTP request is received, and handles inbound requests from outside the logic app workflow. To add the Request trigger, follow these steps:

    1. Under the designer search box, select Built-in. In the designer search box, enter HTTP request.

    2. From the triggers list, select the Request trigger named When an HTTP request is received.

    Tip

    Providing a JSON schema is optional. If you have a sample payload from the inbound request, select Use sample payload to generate schema, enter the sample payload, and select Done. The schema appears in the Request Body JSON Schema box.

  3. Under the step in your workflow where you want to add the Flat File Encoding action, choose an option:

    • To add the Flat File Encoding action at the end of your workflow, select New step.

    • To add the Flat File Encoding action between existing steps, move your pointer over the arrow that connects those steps so that the plus sign (+) appears. Select that plus sign, and then select Add an action.

  4. In the Choose an operation search box, enter flat file. From the actions list, select the action named Flat File Encoding.

    Screenshot showing the Azure portal and Consumption designer with "flat file" in search box and the "Flat File Encoding" action selected.

  5. Click inside the Content box so that the dynamic content list appears. From the list, in the When a HTTP request is received section, select the Body property, which contains the request body output from the trigger and the content to encode.

    Screenshot showing the Consumption designer and the "Content" property with dynamic content list and content selected for encoding.

    Tip

    If the Body property doesn't appear in the dynamic content list, select See more next to the When a HTTP request is received section label. You can also directly enter the content to decode in the Content box.

  6. From the Schema Name list, select the schema that's in your linked integration account to use for encoding, for example:

    Screenshot showing the Consumption designer and the opened "Schema Name" list with selected schema to use for encoding.

    Note

    If no schema appears in the list, your integration account doesn't contain any schema files to use for encoding. Upload the schema that you want to use to your integration account.

  7. Save your workflow. On the designer toolbar, select Save.

  8. To test your workflow, send a request to the HTTPS endpoint, which appears in the Request trigger's HTTP POST URL property, and include the XML content that you want to encode in the request body.

You're now done with setting up your flat file encoding action. In a real world app, you might want to store the encoded data in a line-of-business (LOB) app, such as Salesforce. Or, you can send the encoded data to a trading partner. To send the output from the encoding action to Salesforce or to your trading partner, use the other connectors available in Azure Logic Apps.

Add Flat File Decoding action

  1. In the Azure portal, open your logic app workflow in the designer.

  2. If you have a blank workflow that doesn't have a trigger, add any trigger you want. Otherwise, continue to the next step.

    This example uses the Request trigger, which is named When a HTTP request is received, and handles inbound requests from outside the logic app workflow. To add the Request trigger, follow these steps:

    1. Under the designer search box, select Built-in. In the designer search box, enter HTTP request.

    2. From the triggers list, select the Request trigger named When an HTTP request is received.

    Tip

    Providing a JSON schema is optional. If you have a sample payload from the inbound request, select Use sample payload to generate schema, enter the sample payload, and select Done. The schema appears in the Request Body JSON Schema box.

  3. Under the step in your workflow where you want to add the Flat File Decoding action, choose an option:

    • To add the Flat File Decoding action at the end of your workflow, select New step.

    • To add the Flat File Decoding action between existing steps, move your pointer over the arrow that connects those steps so that the plus sign (+) appears. Select that plus sign, and then select Add an action.

  4. In the Choose an operation search box, enter flat file. From the actions list, select the action named Flat File Decoding.

    Screenshot showing the Azure portal and the Consumption designer with "flat file" in search box and the "Flat File Decoding" action selected.

  5. Click inside the Content box so that the dynamic content list appears. From the list, in the When a HTTP request is received section, select the Body property, which contains the request body output from the trigger and the content to decode.

    Screenshot showing the Consumption designer and the "Content" property with dynamic content list and content selected for decoding.

    Tip

    If the Body property doesn't appear in the dynamic content list, select See more next to the When a HTTP request is received section label. You can also directly enter the content to decode in the Content box.

  6. From the Schema Name list, select the schema that's in your linked integration account to use for decoding, for example:

    Screenshot showing the Consumption designer and the opened "Schema Name" list with selected schema to use for decoding.

    Note

    If no schema appears in the list, your integration account doesn't contain any schema files to use for decoding. Upload the schema that you want to use to your integration account.

  7. Save your workflow. On the designer toolbar, select Save.

  8. To test your workflow, send a request to the HTTPS endpoint, which appears in the Request trigger's HTTP POST URL property, and include the XML content that you want to decode in the request body.

You're now done with setting up your flat file decoding action. In a real world app, you might want to store the decoded data in a line-of-business (LOB) app, such as Salesforce. Or, you can send the decoded data to a trading partner. To send the output from the decoding action to Salesforce or to your trading partner, use the other connectors available in Azure Logic Apps.

Next steps