Encode and decode flat files in Azure Logic Apps
Applies to: Azure Logic Apps (Consumption + Standard)
Before you send XML content to a business partner in a business-to-business (B2B) scenario, you might want to encode that content first. If you receive encoded XML content, you'll need to decode that content first. When you're building a logic app workflow in Azure Logic Apps, you can encode and decode flat files by using the Flat File built-in connector actions and a flat file schema for encoding and decoding. You can use Flat File actions in multitenant Consumption logic app workflows and single-tenant Standard logic app workflows.
While no Flat File triggers are available, you can use any trigger or action to feed the source XML content into your workflow. For example, you can use a built-in connector trigger, a managed or Azure-hosted connector trigger available for Azure Logic Apps, or even another app.
This article shows how to add the Flat File encoding and decoding actions to your workflow.
- Add a Flat File encoding or decoding action to your workflow.
- Select the schema that you want to use.
For more information, review the following documentation:
- Consumption versus Standard logic apps
- Integration account built-in connectors
- Built-in connectors overview for Azure Logic Apps
- Managed or Azure-hosted connectors in Azure Logic Apps
Prerequisites
An Azure account and subscription. If you don't have a subscription yet, sign up for a free Azure account.
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.
Your logic app resource and workflow. Flat file operations don't have any triggers available, so your workflow has to minimally include a trigger. For more information, see the following documentation:
A flat file schema for encoding and decoding the XML content. For more information, Add schemas to use with workflows in Azure Logic Apps.
Based on whether you're working on a Consumption or Standard logic app workflow, you'll need an integration account resource. Usually, you need this resource when you want to define and store artifacts for use in enterprise integration and B2B workflows.
Important
To work together, both your integration account and logic app resource must exist in the same Azure subscription and Azure region.
If you're working on a Consumption logic app workflow, your logic app resource requires a link to your integration account.
If you're working on a Standard logic app workflow, you can link your logic app resource to your integration account, upload schemas directly to your logic app resource, or both, based on the following scenarios:
If you already have an integration account with the artifacts that you need or want to use, you can link your integration account to multiple Standard logic app resources where you want to use the artifacts. That way, you don't have to upload schemas to each individual logic app. For more information, review Link your logic app resource to your integration account.
The Flat File built-in connector lets you select a schema that you previously uploaded to your logic app resource or to a linked integration account, but not both. You can then use this artifact across all child workflows within the same logic app resource.
So, if you don't have or need an integration account, you can use the upload option. Otherwise, you can use the linking option. Either way, you can use these artifacts across all child workflows within the same logic app resource.
Install or use a tool that can send HTTP requests to test your solution, for example:
- Visual Studio Code with an extension from Visual Studio Marketplace
- PowerShell Invoke-RestMethod
- Microsoft Edge - Network Console tool
- Bruno
- curl
Caution
For scenarios where you have sensitive data, such as credentials, secrets, access tokens, API keys, and other similar information, make sure to use a tool that protects your data with the necessary security features, works offline or locally, doesn't sync your data to the cloud, and doesn't require that you sign in to an online account. This way, you reduce the risk around exposing sensitive data to the public.
Limitations
XML content that you want to decode must be encoded in UTF-8 format.
In your flat file schema, make sure the contained XML groups don't have excessive numbers of the
max count
property set to a value greater than 1. Avoid nesting an XML group with amax count
property value greater than 1 inside another XML group with amax count
property greater than 1.When Azure Logic Apps parses the flat file schema, and whenever the schema allows the choice of the next fragment, Azure Logic Apps 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.
Upload schema
After you create your schema, you now have to upload the schema based on the following scenario:
If you're working on a Consumption logic app workflow, add your schema to your integration account.
If you're working on a Standard logic app workflow, you can add your schema to your integration account, or add your schema to your logic app resource.
Add a Flat File encoding action
In the Azure portal, open your logic app workflow in the designer, if not already open.
If your workflow doesn't have a trigger or any other actions that your workflow needs, add those operations first. Flat File operations don't have any triggers available.
This example continues with the Request trigger named When a HTTP request is received.
On the workflow designer, under the step where you want to add the Flat File action, select New step.
Under the Choose an operation search box, select Built-in. In the search box, enter flat file.
From the actions list, select the action named Flat File Encoding.
In the action's Content property, provide the output from the trigger or a previous action that you want to encode by following these steps:
Click inside the Content box so that the dynamic content list appears.
From the dynamic content list, select the flat file content that you want to encode.
For this example, from the dynamic content list, under When a HTTP request is received, select the Body token, which represents the body content output from the trigger.
Note
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 encode in the Content box.
From the Schema Name list, select your schema.
Note
If the schema list is empty, either your logic app resource isn't linked to your integration account or your integration account doesn't contain any schema files.
When you're done, your action looks similar to the following:
To add other optional parameters to the action, select those parameters from the Add new parameter list.
Parameter Value Description Mode of empty node generation ForcedDisabled or HonorSchemaNodeProperty or ForcedEnabled The mode to use for empty node generation with flat file encoding.
For BizTalk, the flat file schema has a property that controls empty node generation. You can either follow the empty node generation property behavior for your flat file schema, or you can use this setting to have Azure Logic Apps generate or omit empty nodes. For more information, see Tags for empty elements.XML Normalization Yes or No The setting to enable or disable XML normalization in flat file encoding. For more information, see XmlTextReader.Normalization. Save your workflow. On the designer toolbar, select Save.
Add a Flat File decoding action
In the Azure portal, open your logic app workflow in the designer, if not already open.
If your workflow doesn't have a trigger or any other actions that your workflow needs, add those operations first. Flat File operations don't have any triggers available.
This example continues with the Request trigger named When a HTTP request is received.
On the workflow designer, under the step where you want to add the Flat File action, select New step.
Under the Choose an operation search box, select Built-in. In the search box, enter flat file.
From the actions list, select the action named Flat File Decoding.
In the action's Content property, provide the output from the trigger or a previous action that you want to decode by following these steps:
Click inside the Content box so that the dynamic content list appears.
From the dynamic content list, select the flat file content that you want to encode.
For this example, from the dynamic content list, under When a HTTP request is received, select the Body token, which represents the body content output from the trigger.
Note
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 encode in the Content box.
From the Schema Name list, select your schema.
Note
If the schema list is empty, either your logic app resource isn't linked to your integration account or your integration account doesn't contain any schema files.
When you're done, your action looks similar to the following:
Save your workflow. On the designer toolbar, select Save.
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:
Test your workflow
To trigger your workflow, follow these steps:
In the Request trigger, find the HTTP POST URL property, and copy the URL.
Open your HTTP request tool and use its instructions to send an HTTP request to the copied URL, including the method that the Request trigger expects.
This example uses the
POST
method with the URL.Include the XML content that you want to encode or decode in the request body.
After your workflow finishes running, go to the workflow's run history, and examine the Flat File action's inputs and outputs.
Next steps
- Learn more about the Enterprise Integration Pack