Unpacking Software Livestream

Join our monthly Unpacking Software livestream to hear about the latest news, chat and opinion on packaging, software deployment and lifecycle management!

Learn More

Chocolatey Product Spotlight

Join the Chocolatey Team on our regular monthly stream where we put a spotlight on the most recent Chocolatey product releases. You'll have a chance to have your questions answered in a live Ask Me Anything format.

Learn More

Chocolatey Coding Livestream

Join us for the Chocolatey Coding Livestream, where members of our team dive into the heart of open source development by coding live on various Chocolatey projects. Tune in to witness real-time coding, ask questions, and gain insights into the world of package management. Don't miss this opportunity to engage with our team and contribute to the future of Chocolatey!

Learn More

Calling All Chocolatiers! Whipping Up Windows Automation with Chocolatey Central Management

Webinar from
Wednesday, 17 January 2024

We are delighted to announce the release of Chocolatey Central Management v0.12.0, featuring seamless Deployment Plan creation, time-saving duplications, insightful Group Details, an upgraded Dashboard, bug fixes, user interface polishing, and refined documentation. As an added bonus we'll have members of our Solutions Engineering team on-hand to dive into some interesting ways you can leverage the new features available!

Watch On-Demand
Chocolatey Community Coffee Break

Join the Chocolatey Team as we discuss all things Community, what we do, how you can get involved and answer your Chocolatey questions.

Watch The Replays
Chocolatey and Intune Overview

Webinar Replay from
Wednesday, 30 March 2022

At Chocolatey Software we strive for simple, and teaching others. Let us teach you just how simple it could be to keep your 3rd party applications updated across your devices, all with Intune!

Watch On-Demand
Chocolatey For Business. In Azure. In One Click.

Livestream from
Thursday, 9 June 2022

Join James and Josh to show you how you can get the Chocolatey For Business recommended infrastructure and workflow, created, in Azure, in around 20 minutes.

Watch On-Demand
The Future of Chocolatey CLI

Livestream from
Thursday, 04 August 2022

Join Paul and Gary to hear more about the plans for the Chocolatey CLI in the not so distant future. We'll talk about some cool new features, long term asks from Customers and Community and how you can get involved!

Watch On-Demand
Hacktoberfest Tuesdays 2022

Livestreams from
October 2022

For Hacktoberfest, Chocolatey ran a livestream every Tuesday! Re-watch Cory, James, Gary, and Rain as they share knowledge on how to contribute to open-source projects such as Chocolatey CLI.

Watch On-Demand

Downloads:

1,383

Downloads of v 0.5.1-beta-2020102860442:

99

Last Update:

28 Oct 2020

Package Maintainer(s):

Software Author(s):

  • Microsoft

Tags:

biztalkmigrator-azure biztalk azure integration aim ais cli

BizTalk Migrator Dependency - Azure Templates

This is a prerelease version of BizTalk Migrator Dependency - Azure Templates.

  • 1
  • 2
  • 3

0.5.1-beta-2020102860442 | Updated: 28 Oct 2020

Downloads:

1,383

Downloads of v 0.5.1-beta-2020102860442:

99

Software Author(s):

  • Microsoft

BizTalk Migrator Dependency - Azure Templates 0.5.1-beta-2020102860442

This is a prerelease version of BizTalk Migrator Dependency - Azure Templates.

Legal Disclaimer: Neither this package nor Chocolatey Software, Inc. are affiliated with or endorsed by Microsoft. The inclusion of Microsoft trademark(s), if any, upon this webpage is solely to identify Microsoft goods or services and not for commercial purposes.

  • 1
  • 2
  • 3

Some Checks Have Failed or Are Not Yet Complete

Not All Tests Have Passed


Validation Testing Failed


Verification Testing Passed

Details

Scan Testing Successful:

No detections found in any package files

Details
Learn More

Deployment Method: Individual Install, Upgrade, & Uninstall

To install BizTalk Migrator Dependency - Azure Templates, run the following command from the command line or from PowerShell:

>

To upgrade BizTalk Migrator Dependency - Azure Templates, run the following command from the command line or from PowerShell:

>

To uninstall BizTalk Migrator Dependency - Azure Templates, run the following command from the command line or from PowerShell:

>

Deployment Method:

NOTE

This applies to both open source and commercial editions of Chocolatey.

1. Enter Your Internal Repository Url

(this should look similar to https://community.chocolatey.org/api/v2/)


2. Setup Your Environment

1. Ensure you are set for organizational deployment

Please see the organizational deployment guide

2. Get the package into your environment

  • Open Source or Commercial:
    • Proxy Repository - Create a proxy nuget repository on Nexus, Artifactory Pro, or a proxy Chocolatey repository on ProGet. Point your upstream to https://community.chocolatey.org/api/v2/. Packages cache on first access automatically. Make sure your choco clients are using your proxy repository as a source and NOT the default community repository. See source command for more information.
    • You can also just download the package and push it to a repository Download

3. Copy Your Script

choco upgrade biztalkmigrator-azure -y --source="'INTERNAL REPO URL'" --version="'0.5.1-beta-2020102860442'" --prerelease [other options]

See options you can pass to upgrade.

See best practices for scripting.

Add this to a PowerShell script or use a Batch script with tools and in places where you are calling directly to Chocolatey. If you are integrating, keep in mind enhanced exit codes.

If you do use a PowerShell script, use the following to ensure bad exit codes are shown as failures:


choco upgrade biztalkmigrator-azure -y --source="'INTERNAL REPO URL'" --version="'0.5.1-beta-2020102860442'" --prerelease
$exitCode = $LASTEXITCODE

Write-Verbose "Exit code was $exitCode"
$validExitCodes = @(0, 1605, 1614, 1641, 3010)
if ($validExitCodes -contains $exitCode) {
  Exit 0
}

Exit $exitCode

- name: Install biztalkmigrator-azure
  win_chocolatey:
    name: biztalkmigrator-azure
    version: '0.5.1-beta-2020102860442'
    source: INTERNAL REPO URL
    state: present
    allow_prerelease: yes

See docs at https://docs.ansible.com/ansible/latest/modules/win_chocolatey_module.html.


chocolatey_package 'biztalkmigrator-azure' do
  action    :install
  source   'INTERNAL REPO URL'
  version  '0.5.1-beta-2020102860442'
  options  '--prerelease'
end

See docs at https://docs.chef.io/resource_chocolatey_package.html.


cChocoPackageInstaller biztalkmigrator-azure
{
    Name        = "biztalkmigrator-azure"
    Version     = "0.5.1-beta-2020102860442"
    Source      = "INTERNAL REPO URL"
    chocoParams = "--prerelease"
}

Requires cChoco DSC Resource. See docs at https://github.com/chocolatey/cChoco.


package { 'biztalkmigrator-azure':
  ensure          => '0.5.1-beta-2020102860442',
  install_options => ['--prerelease'],
  provider        => 'chocolatey',
  source          => 'INTERNAL REPO URL',
}

Requires Puppet Chocolatey Provider module. See docs at https://forge.puppet.com/puppetlabs/chocolatey.


4. If applicable - Chocolatey configuration/installation

See infrastructure management matrix for Chocolatey configuration elements and examples.

WARNING

This package is exempt from moderation. While it is likely safe for you, there is more risk involved.

Description

Azure templates to migrate BizTalk applications to Microsoft Azure Integration Services.


tools\templates\application\applicationgroup\applicationgroup.dev.parameters.json.liquid
 
tools\templates\application\applicationgroup\applicationgroup.json.liquid
 
tools\templates\application\applicationgroup\applicationgroup.prod.parameters.json.liquid
 
tools\templates\application\applicationgroup\Deploy-10-ApplicationGroup.ps1.liquid
 
tools\templates\application\applicationgroup\New-ApplicationGroup.ps1.liquid
 
tools\templates\application\applicationgroup\Remove-ApplicationGroup.ps1.liquid
 
tools\templates\application\applicationgroup\TearDown-10-ApplicationGroup.ps1.liquid
 
tools\templates\application\config\configurationentries\configurationentry.appcfg.dev.psparameters.json.liquid
 
tools\templates\application\config\configurationentries\configurationentry.appcfg.prod.psparameters.json.liquid
 
tools\templates\application\config\configurationentries\Deploy-105-ConfigurationEntry-AppConfig.ps1.liquid
 
tools\templates\application\config\configurationentries\New-ConfigurationEntry-AppConfig.ps1
<#
.SYNOPSIS
Creates a configuration entry in application configuration.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER configStoreName
The name of the application configuration store.

.PARAMETER key
The key for the configuration item.

.PARAMETER value
The value for the configuration item

.PARAMETER type
The type assigned to the configuration item.

.PARAMETER label
The label for the configuration item.

.PARAMETER tags
The tags to apply to the configuration item.

.EXAMPLE
.\New-ConfigurationEntry-AppConfig.ps1 -configStoreName "appcfg-aimroutestore-dev" -key "SampleConfigKey" -value "{ ""samplekey"": ""samplevalue"" }" -type configType -label "sample label"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $configStoreName,
    [parameter(Mandatory = $true)]
    [string] $key,
    [parameter(Mandatory = $true)]
    [string] $value,
    [parameter(Mandatory = $true)]
    [string] $type,
    [parameter(Mandatory = $true)]
    [string] $label,
    [parameter(Mandatory = $false)]
    [string[]] $tags = ""
)

Write-Host "Deploying the configuraton entry key $key"

az appconfig kv set --name $configStoreName --key $key --value $value --content-type $type --label $label --tags $tags --yes 

Write-Host "Deployment complete for the configuration entry key $key"
tools\templates\application\config\configurationentries\Remove-ConfigurationEntry-AppConfig.ps1
<#
.SYNOPSIS
Removes a configuration entry from the application configuration.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER configStoreName
The name of the application configuration store.

.PARAMETER key
The key of the item remove from the configuration store.

.PARAMETER label
The label of the item remove from the configuration store.

.EXAMPLE
.\TearDown-100-ConfigurationEntry-AppConfig.ps1 -configStoreName "appcfg-aimroutestore-dev" -key "SampleConfigKey" -label "SampleLabel"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $configStoreName,
    [parameter(Mandatory = $true)]
    [string] $key,
    [parameter(Mandatory = $true)]
    [string] $label
)

Write-Host "Removing the configuration entry for key $key"

az appconfig kv delete --name $configStoreName --key $key --label $label --yes

Write-Host "Removed the configuration entry for key $key"
tools\templates\application\config\configurationentries\TearDown-105-ConfigurationEntry-AppConfig.ps1.liquid
 
tools\templates\application\config\routingproperties\route\Deploy-105-RoutingProperties-AppConfig.ps1.liquid
 
tools\templates\application\config\routingproperties\route\New-RoutingProperties-AppConfig.ps1
<#
.SYNOPSIS
Creates routing properties in app config.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER configStoreName
The name of the application configuration store.

.PARAMETER key
The key for the configuration item.

.PARAMETER value
The value for the configuration item

.PARAMETER type
The type assigned to the configuration item.

.PARAMETER label
The label for the configuration item.

.PARAMETER tags
The tags to apply to the configuration item.

.EXAMPLE
.\New-RoutingProperties-AppConfig.ps1 -configStoreName "appcfg-aimroutestore-dev" -key "SampleConfigKey" -value "{ ""samplekey"": ""samplevalue"" }" -type configType -label "sample label"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $configStoreName,
    [parameter(Mandatory = $true)]
    [string] $key,
    [parameter(Mandatory = $true)]
    [string] $value,
    [parameter(Mandatory = $true)]
    [string] $type,
    [parameter(Mandatory = $true)]
    [string] $label,
    [parameter(Mandatory = $false)]
    [string[]] $tags = ""
)

Write-Host "Deploying routing properties with the key $key"

az appconfig kv set --name $configStoreName --key $key --value $value --content-type $type --label $label --tags $tags --yes 

Write-Host "Deployment complete routing properties with the key $key"
tools\templates\application\config\routingproperties\route\Remove-RoutingProperties-AppConfig.ps1
<#
.SYNOPSIS
Removes routing properties from app config.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER configStoreName
The name of the application configuration store.

.PARAMETER key
The key of the item remove from the configuration store.

.PARAMETER label
The label of the item remove from the configuration store.

.EXAMPLE
.\TearDown-100-RoutingProperties-AppConfig.ps1 -configStoreName "appcfg-aimroutestore-dev" -key "SampleConfigKey" -label "SampleLabel"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $configStoreName,
    [parameter(Mandatory = $true)]
    [string] $key,
    [parameter(Mandatory = $true)]
    [string] $label
)

Write-Host "Removing routing properties with the key $key"

az appconfig kv delete --name $configStoreName --key $key --label $label --yes

Write-Host "Removed routing properties with the key $key"
tools\templates\application\config\routingproperties\route\routingproperties.appcfg.dev.psparameters.json.liquid
 
tools\templates\application\config\routingproperties\route\routingproperties.appcfg.prod.psparameters.json.liquid
 
tools\templates\application\config\routingproperties\route\TearDown-105-RoutingProperties-AppConfig.ps1.liquid
 
tools\templates\application\config\routingproperties\schema\Deploy-105-RoutingProperties-AppConfig.ps1.liquid
 
tools\templates\application\config\routingproperties\schema\New-RoutingProperties-AppConfig.ps1
<#
.SYNOPSIS
Creates routing properties in app config.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER configStoreName
The name of the application configuration store.

.PARAMETER key
The key for the configuration item.

.PARAMETER value
The value for the configuration item

.PARAMETER type
The type assigned to the configuration item.

.PARAMETER label
The label for the configuration item.

.PARAMETER tags
The tags to apply to the configuration item.

.EXAMPLE
.\New-RoutingProperties-AppConfig.ps1 -configStoreName "appcfg-aimroutestore-dev" -key "SampleConfigKey" -value "{ ""samplekey"": ""samplevalue"" }" -type configType -label "sample label"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $configStoreName,
    [parameter(Mandatory = $true)]
    [string] $key,
    [parameter(Mandatory = $true)]
    [string] $value,
    [parameter(Mandatory = $true)]
    [string] $type,
    [parameter(Mandatory = $true)]
    [string] $label,
    [parameter(Mandatory = $false)]
    [string[]] $tags = ""
)

Write-Host "Deploying the routing properties for key $key"

az appconfig kv set --name $configStoreName --key $key --value $value --content-type $type --label $label --tags $tags --yes 

Write-Host "Deployment complete for the routing properties for key $key"
tools\templates\application\config\routingproperties\schema\Remove-RoutingProperties-AppConfig.ps1
<#
.SYNOPSIS
Removes routing properties from app config.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER configStoreName
The name of the application configuration store.

.PARAMETER key
The key of the item remove from the configuration store.

.PARAMETER label
The label of the item remove from the configuration store.

.EXAMPLE
.\TearDown-100-RoutingProperties-AppConfig.ps1 -configStoreName "appcfg-aimroutestore-dev" -key "SampleConfigKey" -label "SampleLabel"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $configStoreName,
    [parameter(Mandatory = $true)]
    [string] $key,
    [parameter(Mandatory = $true)]
    [string] $label
)

Write-Host "Removing the routing properties for key $key"

az appconfig kv delete --name $configStoreName --key $key --label $label --yes

Write-Host "Removed routing properties for the key $key"
tools\templates\application\config\routingproperties\schema\routingproperties.appcfg.dev.psparameters.json.liquid
 
tools\templates\application\config\routingproperties\schema\routingproperties.appcfg.prod.psparameters.json.liquid
 
tools\templates\application\config\routingproperties\schema\TearDown-105-RoutingProperties-AppConfig.ps1.liquid
 
tools\templates\application\config\routingslips\Deploy-105-RoutingSlip-AppConfig.ps1.liquid
 
tools\templates\application\config\routingslips\New-RoutingSlip-AppConfig.ps1
<#
.SYNOPSIS
Creates routing slip configuration in application configuration.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER configStoreName
The name of the application configuration store.

.PARAMETER key
The key for the configuration item.

.PARAMETER value
The value for the configuration item

.PARAMETER type
The type assigned to the configuration item.

.PARAMETER label
The label for the configuration item.

.PARAMETER tags
The tags to apply to the configuration item.

.EXAMPLE
.\New-RoutingSlip-AppConfig.ps1 -configStoreName "appcfg-aimroutestore-dev" -key "SampleConfigKey" -value "{ ""samplekey"": ""samplevalue"" }" -type configType -label "sample label"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $configStoreName,
    [parameter(Mandatory = $true)]
    [string] $key,
    [parameter(Mandatory = $true)]
    [string] $value,
    [parameter(Mandatory = $true)]
    [string] $type,
    [parameter(Mandatory = $true)]
    [string] $label,
    [parameter(Mandatory = $false)]
    [string[]] $tags = ""
)

Write-Host "Deploying the routing slip configuration key $key"

az appconfig kv set --name $configStoreName --key $key --value $value --content-type $type --label $label --tags $tags --yes 

Write-Host "Deployment complete for the routing slip configuration key $key"
tools\templates\application\config\routingslips\Remove-RoutingSlip-AppConfig.ps1
<#
.SYNOPSIS
Removes routing slip configuration from the application configuration.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER configStoreName
The name of the application configuration store.

.PARAMETER key
The key of the item remove from the configuration store.

.PARAMETER label
The label of the item remove from the configuration store.

.EXAMPLE
.\TearDown-100-RoutingSlip-AppConfig.ps1 -configStoreName "appcfg-aimroutestore-dev" -key "SampleConfigKey" -label "SampleLabel"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $configStoreName,
    [parameter(Mandatory = $true)]
    [string] $key,
    [parameter(Mandatory = $true)]
    [string] $label
)

Write-Host "Removing the routing slip configuration for key $key"

az appconfig kv delete --name $configStoreName --key $key --label $label --yes

Write-Host "Removed routing slip configuration for key $key"
tools\templates\application\config\routingslips\routingslip.appcfg.dev.psparameters.json.liquid
 
tools\templates\application\config\routingslips\routingslip.appcfg.prod.psparameters.json.liquid
 
tools\templates\application\config\routingslips\TearDown-105-RoutingSlip-AppConfig.ps1.liquid
 
tools\templates\application\workflows\messageresponsehandler\Deploy-80-MessageResponseHandlerServiceBus-ApiConnection.ps1.liquid
 
tools\templates\application\workflows\messageresponsehandler\Deploy-85-MessageResponseHandler-LogicApp.ps1.liquid
 
tools\templates\application\workflows\messageresponsehandler\messageresponsehandler.logicapp.dev.parameters.json.liquid
 
tools\templates\application\workflows\messageresponsehandler\messageresponsehandler.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "serviceBusTopicSubscribeApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for ServiceBus Response Subscribe operations."
            }
        },
        "scenarioStep": {
            "defaultValue": "messageResponseHandler",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. messageResponseHandler."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "serviceBusTopicSubscribeApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('serviceBusTopicSubscribeApiConnectionName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "$connections": {
                            "defaultValue": {},
                            "type": "Object"
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. messageResponseHandler."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {},
                            "type": "Request",
                            "operationOptions": "EnableSchemaValidation",
                            "kind": "Http",
                            "inputs": {
                                "schema": {
                                    "properties": {
                                        "correlationId": {
                                            "type": "string"
                                        },
                                        "responseSubscriptionName": {
                                            "type": "string"
                                        },
                                        "responseTimeoutInMinutes": {
                                            "type": "integer"
                                        },
                                        "responseTopicName": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "correlationId",
                                        "responseTopicName",
                                        "responseSubscriptionName",
                                        "responseTimeoutInMinutes"
                                    ],
                                    "type": "object"
                                }
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseBodyArray_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseBodyArray",
                                        "type": "array"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseCount_variable": {
                            "runAfter": {
                                "Initialize_ResponseBodyArray_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseCount",
                                        "type": "integer",
                                        "value": 0
                                    }
                                ]
                            }
                        },
                        "SendResponse:_Check_Outcome": {
                            "actions": {
                                "SendResponse:_Switch_on_Checkpoint": {
                                    "cases": {
                                        "Success": {
                                            "case": "WaitForResponseSuccess",
                                            "actions": {
                                                "SendResponse:Success:_Complete_each_Response_Message": {
                                                    "actions": {
                                                        "SendResponse:Success:_Complete_Current_Response_message": {
                                                            "inputs": {
                                                                "host": {
                                                                    "connection": {
                                                                        "name": "@parameters('$connections')['servicebussubscribe']['connectionId']"
                                                                    }
                                                                },
                                                                "method": "delete",
                                                                "path": "/@{encodeURIComponent(triggerBody()?['responseTopicName'])}/subscriptions/@{encodeURIComponent(triggerBody()?['responseSubscriptionName'])}/messages/complete",
                                                                "queries": {
                                                                    "lockToken": "@items('SendResponse:Success:_Complete_each_Response_Message')?['LockToken']",
                                                                    "sessionId": "@items('SendResponse:Success:_Complete_each_Response_Message')?['SessionId']",
                                                                    "subscriptionType": "Main"
                                                                },
                                                                "retryPolicy": {
                                                                    "type": "none"
                                                                }
                                                            },
                                                            "runAfter": {},
                                                            "type": "ApiConnection"
                                                        }
                                                    },
                                                    "foreach": "@variables('ResponseBodyArray')",
                                                    "runAfter": {},
                                                    "type": "Foreach"
                                                },
                                                "SendResponse:Success:_Build_Response": {
                                                    "inputs": {
                                                        "$content-type": "@variables('ResponseBodyArray')?[0]?['ContentType']",
                                                        "$content": "@variables('ResponseBodyArray')?[0]?['ContentData']",
                                                        "$content-encoding": "@variables('ResponseBodyArray')?[0]?['ContentTransferEncoding']"
                                                    },
                                                    "runAfter": {
                                                        "SendResponse:Success:_Complete_each_Response_Message": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose"
                                                },
                                                "SendResponse:Success:_Send_Response": {
                                                    "runAfter": {
                                                        "SendResponse:Success:_Build_Response": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@outputs('SendResponse:Success:_Build_Response')",
                                                        "headers": {
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                },
                                                "SendResponse:Success:_Send_Fault_Response": {
                                                    "runAfter": {
                                                        "SendResponse:Success:_Complete_each_Response_Message": [
                                                            "Failed",
                                                            "Skipped",
                                                            "TimedOut"
                                                        ]
                                                    },
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": {
                                                            "fault": {
                                                                "faultActor": "@{workflow()['name']} (@{workflow()?['run']?['name']})",
                                                                "faultCategory": "Error",
                                                                "faultCode": "500",
                                                                "faultMessage": "An error occurred trying to complete the response messages received for this session.",
                                                                "faultReason": ""
                                                            }
                                                        },
                                                        "headers": {
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 500
                                                    }
                                                }
                                            }
                                        },
                                        "Failure": {
                                            "case": "WaitForResponseFailure",
                                            "actions": {
                                                "SendResponse:Failure:_Send_Fault_Response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@variables('FaultMessage')",
                                                        "headers": {
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 500
                                                    }
                                                }
                                            }
                                        },
                                        "Timeout": {
                                            "case": "WaitForResponseTimeout",
                                            "actions": {
                                                "SendResponse:Timeout:_Send_Fault_Response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": {
                                                            "fault": {
                                                                "faultActor": "@{workflow()['name']} (@{workflow()?['run']?['name']})",
                                                                "faultCategory": "Error",
                                                                "faultCode": "504",
                                                                "faultMessage": "Timed out waiting for a response message.",
                                                                "faultReason": ""
                                                            }
                                                        },
                                                        "headers": {
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 504
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "SendResponse:UnknownCheckpoint:_Send_Fault_Response": {
                                                "runAfter": {},
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": {
                                                        "fault": {
                                                            "faultActor": "@{workflow()['name']} (@{workflow()?['run']?['name']})",
                                                            "faultCategory": "Error",
                                                            "faultCode": "500",
                                                            "faultMessage": "Unexpected Checkpoint value of '@{variables('Checkpoint')}' in LogicApp @{workflow()['name']}. Unable to continue.",
                                                            "faultReason": ""
                                                        }
                                                    },
                                                    "headers": {
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 500
                                                }
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "expression": "@variables('Checkpoint')",
                                    "type": "Switch"
                                }
                            },
                            "runAfter": {
                                "Step:_Wait_for_Response": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Do_we_have_a_Fault": {
                                        "actions": {
                                            "Failure:NoFault:_Send_Fault_Response": {
                                                "runAfter": {},
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": {
                                                        "fault": {
                                                            "faultActor": "@{workflow()['name']} (@{workflow()?['run']?['name']})",
                                                            "faultCategory": "Error",
                                                            "faultCode": "500",
                                                            "faultMessage": "An error occurred in LogicApp @{workflow()['name']}. Unable to continue. Expected a Checkpoint of WaitForResponseSuccess/WaitForResponseFailure/WaitForResponseTimeout but received a Checkpoint of '@{variables('Checkpoint')}'.",
                                                            "faultReason": ""
                                                        }
                                                    },
                                                    "headers": {
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 500
                                                }
                                            }
                                        },
                                        "else": {
                                            "actions": {
                                                "Failure:HaveFault:_Send_Fault_Response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@variables('FaultMessage')",
                                                        "headers": {
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 500
                                                    }
                                                }
                                            }
                                        },
                                        "runAfter": {},
                                        "expression": {
                                            "and": [
                                                {
                                                    "equals": [
                                                        "@coalesce(variables('FaultMessage'), '')",
                                                        ""
                                                    ]
                                                }
                                            ]
                                        },
                                        "type": "if"
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "WaitForResponseSuccess"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "WaitForResponseFailure"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "WaitForResponseTimeout"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Wait_for_Response": {
                            "actions": {
                                "WaitForResponse:_Loop_until_we_get_Response_or_TimeOut": {
                                    "actions": {
                                        "WaitForResponse:_Get_Response_Message_from_Topic": {
                                            "inputs": {
                                                "host": {
                                                    "connection": {
                                                        "name": "@parameters('$connections')['servicebussubscribe']['connectionId']"
                                                    }
                                                },
                                                "method": "get",
                                                "path": "/@{encodeURIComponent(encodeURIComponent(triggerBody()?['responseTopicName']))}/subscriptions/@{encodeURIComponent(triggerBody()?['responseSubscriptionName'])}/messages/batch/peek",
                                                "queries": {
                                                    "maxMessageCount": 1,
                                                    "sessionId": "@{triggerBody()?['correlationId']}",
                                                    "subscriptionType": "Main"
                                                },
                                                "retryPolicy": {
                                                    "type": "none"
                                                }
                                            },
                                            "runAfter": {},
                                            "type": "ApiConnection"
                                        },
                                        "WaitForResponse:_Set_StatusCode_variable": {
                                            "runAfter": {
                                                "WaitForResponse:_Get_Response_Message_from_Topic": [
                                                    "Succeeded",
                                                    "Failed",
                                                    "Skipped",
                                                    "TimedOut"
                                                ]
                                            },
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "StatusCode",
                                                "value": "@coalesce(outputs('WaitForResponse:_Get_Response_Message_from_Topic')?['statusCode'], 500)"
                                            }
                                        },
                                        "WaitForResponse:_Check_Status_Code": {
                                            "runAfter": {
                                                "WaitForResponse:_Set_StatusCode_variable": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "cases": {
                                                "Success": {
                                                    "case": 200,
                                                    "actions": {
                                                        "WaitForResponse:Success:_Set_ResponseBodyArray_variable": {
                                                            "inputs": {
                                                                "name": "ResponseBodyArray",
                                                                "value": "@array(body('WaitForResponse:_Get_Response_Message_from_Topic'))"
                                                            },
                                                            "runAfter": {},
                                                            "type": "SetVariable"
                                                        },
                                                        "WaitForResponse:Success:_Set_ResponseCount_variable": {
                                                            "inputs": {
                                                                "name": "ResponseCount",
                                                                "value": "@length(variables('ResponseBodyArray'))"
                                                            },
                                                            "runAfter": {
                                                                "WaitForResponse:Success:_Set_ResponseBodyArray_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable"
                                                        }
                                                    }
                                                }
                                            },
                                            "default": {
                                                "actions": {
                                                    "WaitForResponse:Failure:_Create_Fault_Message": {
                                                        "runAfter": {},
                                                        "type": "Compose",
                                                        "inputs": {
                                                            "fault": {
                                                                "faultActor": "@{workflow()?['name']}.@{actions('WaitForResponse:_Get_Response_Message_from_Topic')?['name']} (@{workflow()?['run']?['name']})",
                                                                "faultCategory": "Error",
                                                                "faultCode": "@{coalesce(outputs('WaitForResponse:_Get_Response_Message_from_Topic')?['statusCode'], outputs('WaitForResponse:_Get_Response_Message_from_Topic')?['body']?['statusCode'], actions('WaitForResponse:_Get_Response_Message_from_Topic')?['error']?['code'])}",
                                                                "faultMessage": "@{coalesce(outputs('WaitForResponse:_Get_Response_Message_from_Topic')?['error']?['message'], body('WaitForResponse:_Get_Response_Message_from_Topic')?['message'], body('WaitForResponse:_Get_Response_Message_from_Topic')?['error']?['message'], actions('WaitForResponse:_Get_Response_Message_from_Topic')?['error']?['message'])}",
                                                                "faultReason": "@{actions('WaitForResponse:_Get_Response_Message_from_Topic')?['status']}"
                                                            }
                                                        }
                                                    },
                                                    "WaitForResponse:Failure:_Set_FaultMessage_variable": {
                                                        "runAfter": {
                                                            "WaitForResponse:Failure:_Create_Fault_Message": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@outputs('WaitForResponse:Failure:_Create_Fault_Message')"
                                                        }
                                                    },
                                                    "WaitForResponse:Failure:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "WaitForResponse:Failure:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred executing the @{actions('WaitForResponse:_Get_Response_Message_from_Topic')?['name']} action to get the response message."
                                                        }
                                                    },
                                                    "WaitForResponse:Failure:_Set_Checkpoint_variable": {
                                                        "inputs": {
                                                            "name": "Checkpoint",
                                                            "value": "WaitForResponseFailure"
                                                        },
                                                        "runAfter": {
                                                            "WaitForResponse:Failure:_Set_ErrorMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable"
                                                    }
                                                }
                                            },
                                            "expression": "@variables('StatusCode')",
                                            "type": "Switch"
                                        }
                                    },
                                    "expression": "@or(greater(variables('ResponseCount'), 0), equals(variables('Checkpoint'), 'WaitForResponseFailure'))",
                                    "limit": {
                                        "count": "@mul(coalesce(triggerBody()?['responseTimeoutInMinutes'], 3), 2)",
                                        "timeout": "PT@{coalesce(triggerBody()?['responseTimeoutInMinutes'], 3)}M"
                                    },
                                    "runAfter": {},
                                    "type": "Until"
                                },
                                "WaitForResponse:_Check_Outcome": {
                                    "actions": {
                                        "WaitForResponse:Success:_Set_Checkpoint_variable": {
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "WaitForResponseSuccess"
                                            },
                                            "runAfter": {},
                                            "type": "SetVariable"
                                        }
                                    },
                                    "else": {
                                        "actions": {
                                            "WaitForResponse:TimeOut:_Set_Checkpoint_variable": {
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "WaitForResponseTimeout"
                                                },
                                                "runAfter": {},
                                                "type": "SetVariable"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "WaitForResponse:_Loop_until_we_get_Response_or_TimeOut": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@variables('Checkpoint')",
                                                    ""
                                                ]
                                            },
                                            {
                                                "greater": [
                                                    "@variables('ResponseCount')",
                                                    0
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "if"
                                }
                            },
                            "runAfter": {
                                "Initialize_ResponseCount_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "$connections": {
                        "value": {
                            "servicebussubscribe": {
                                "connectionId": "[variables('serviceBusTopicSubscribeApiConnectionResourceId')]",
                                "connectionName": "[parameters('serviceBusTopicSubscribeApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/servicebus')]"
                            }
                        }
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\application\workflows\messageresponsehandler\messageresponsehandler.logicapp.prod.parameters.json.liquid
 
tools\templates\application\workflows\messageresponsehandler\messageresponsehandlerservicebus.apiconnection.dev.parameters.json.liquid
 
tools\templates\application\workflows\messageresponsehandler\messageresponsehandlerservicebus.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "serviceBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that contains the Azure Service Bus resource."
            }
        },
        "serviceBusNamespaceName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Namespace this API Connection connects to)."
            }
        },
        "serviceBusPolicyName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Policy this API Connection connects to)."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'servicebus')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "connectionString": "[listKeys(resourceId(parameters('serviceBusResourceGroupName'), 'Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('serviceBusNamespaceName'), parameters('serviceBusPolicyName')), '2017-04-01').primaryConnectionString]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\application\workflows\messageresponsehandler\messageresponsehandlerservicebus.apiconnection.prod.parameters.json.liquid
 
tools\templates\application\workflows\messageresponsehandler\New-MessageResponseHandler-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-MessageResponseHandler-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\messageresponsehandler.logicapp.json" -templateParameterFile ".\messagereponsehandler.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "messagereponsehandler.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName    
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the message response handler Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\application\workflows\messageresponsehandler\New-MessageResponseHandlerServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Creates a service bus api connection for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-MessageResponseHandlerServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\messageresponsehandlersb.apiconnection.json" -templateParameterFile ".\messageresponsehandlersb.apiconnection.dev.parameters.json" -deploymentName "messageresponsehandlersb.apiconnection.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying a service bus api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\application\workflows\messageresponsehandler\Remove-MessageResponseHandler-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-MessageResponseHandler-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-messageresponsehandler-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\application\workflows\messageresponsehandler\Remove-MessageResponseHandlerServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the message response handlers service bus api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-MessageResponseHandlerServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -resourceName "apic-aimsmessageresponsehandlerconnector-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the message response handler service bus api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the message response handler service bus api connection resource: $resourceName"
}
else {
    Write-Host "The message response handlers service bus api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\application\workflows\messageresponsehandler\TearDown-80-MessageResponseHandlerServiceBus-ApiConnection.ps1.liquid
 
tools\templates\application\workflows\messageresponsehandler\TearDown-85-MessageResponseHandler-LogicApp.ps1.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\Deploy-80-MessageSuspendProcessorServiceBus-ApiConnection.ps1.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\Deploy-85-MessageSuspendProcessor-LogicApp.ps1.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\messagesuspendprocessor.logicapp.dev.parameters.json.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\messagesuspendprocessor.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "serviceBusTopicPublishApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for ServiceBus SuspendQueue Publish operations."
            }
        },
        "scenarioStep": {
            "defaultValue": "messageSuspendProcessor",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. messageSuspendProcessor."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "serviceBusTopicPublishApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('serviceBusTopicPublishApiConnectionName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "$connections": {
                            "defaultValue": {},
                            "type": "Object"
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. messageSuspendProcessor."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "operationOptions": "EnableSchemaValidation",
                            "kind": "Http",
                            "inputs": {
                                "schema": {
                                    "properties": {
                                        "nackMessage": {
                                            "properties": {},
                                            "type": "object"
                                        },
                                        "originalMessage": {
                                            "properties": {},
                                            "type": "object"
                                        },
                                        "suspendQueueTopicName": {
                                            "type": "string"
                                        },
                                        "failedMessageRouting": {
                                            "type": "boolean"
                                        },
                                        "scenario": {
                                            "type": "string"
                                        }
                                    },
                                    "required": [
                                        "nackMessage",
                                        "suspendQueueTopicName",
                                        "failedMessageRouting",
                                        "scenario"
                                    ],
                                    "type": "object"
                                }
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_NackMessage_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "NackMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_OriginalMessage_variable": {
                            "runAfter": {
                                "Initialize_NackMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "OriginalMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Success:_Build_ACK_message": {
                                    "runAfter": {},
                                    "type": "Compose",
                                    "inputs": {
                                        "body": [
                                            {
                                                "$content": { "result": "Successfully published a NACK@{if(equals(variables('Checkpoint'), 'SuspendOriginalMessage'), ' and Original message', '')} to the SuspendQueue in ServiceBus" },
                                                "$contentType": "application/json",
                                                "$part": 1,
                                                "$partType": "http://schemas.microsoft.com/aim#ack"
                                            }
                                        ],
                                        "header": {
                                            "properties": {
                                                "createDate": "@utcNow()",
                                                "envelopeType": "ack",
                                                "messageId": "@guid()",
                                                "rootPart": 1,
                                                "trackingId": "@variables('NackMessage')?['header']?['properties']?['trackingId']"
                                            },
                                            "routing": {
                                                "messageType": "http://schemas.microsoft.com/aim#ack"
                                            },
                                            "routingSlip": {},
                                            "state": {}
                                        }
                                    }
                                },
                                "Routing:Success:_Send_ACK-Content_response": {
                                    "runAfter": {
                                        "Success:_Build_ACK_message": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "Response",
                                    "kind": "Http",
                                    "inputs": {
                                        "body": "@outputs('Success:_Build_ACK_message')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{variables('NackMessage')?['header']?['properties']?['trackingId']}",
                                            "Aim-Clear-Cache": "@coalesce(trigger()?['headers']?['Aim-Clear-Cache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(trigger()?['headers']?['Aim-Enable-Trace'], 'false')",
                                            "Content-Type": "application/json"
                                        },
                                        "statusCode": 200
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Suspend_Original_Message": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@variables('NackMessage')?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "messageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Tracking-Id": "@{variables('NackMessage')?['header']?['properties']?['trackingId']}",
                                                "Aim-Clear-Cache": "@coalesce(trigger()?['headers']?['Aim-Clear-Cache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(trigger()?['headers']?['Aim-Enable-Trace'], 'false')",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SuspendOriginalMessage"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SkippedSuspendOriginalMessage"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Messages": {
                            "actions": {
                                "GetMessages:_Set_NackMessage_variable": {
                                    "runAfter": {},
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "NackMessage",
                                        "value": "@triggerBody()?['nackMessage']"
                                    }
                                },
                                "GetMessages:_Set_OriginalMessage_variable": {
                                    "runAfter": {
                                        "GetMessages:_Set_NackMessage_variable": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "OriginalMessage",
                                        "value": "@triggerBody()?['originalMessage']"
                                    }
                                },
                                "GetMessages:_Have_Valid_Messages": {
                                    "actions": {
                                        "GetMessages:Success:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "GetMessages"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "GetMessages:_Set_OriginalMessage_variable": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "GetMessages:Failure:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): no messages supplied in triggerBody - need either or both of NACK message or Original message"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('NackMessage'), '')",
                                                        ""
                                                    ]
                                                }
                                            },
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('OriginalMessage'), '')",
                                                        ""
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Initialize_OriginalMessage_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Suspend_NACK": {
                            "actions": {
                                "SuspendNack:_Check_Status_Code": {
                                    "runAfter": {
                                        "SuspendNack:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "SuspendNack:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "SuspendNack"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "SuspendNack:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "SuspendNack:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "SuspendNack:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to publish a NACK to the SuspendQueue in ServiceBus"
                                                        }
                                                    },
                                                    "SuspendNack:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('SuspendNack:_Send_to_ServiceBus')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "SuspendNack:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()['name'], '.', actions('SuspendNack:_Send_to_ServiceBus')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('SuspendNack:_Send_to_ServiceBus')?['statusCode'], outputs('SuspendNack:_Send_to_ServiceBus')?['body']?['statusCode'], actions('SuspendNack:_Send_to_ServiceBus')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('SuspendNack:_Send_to_ServiceBus')?['error']?['message'], outputs('SuspendNack:_Send_to_ServiceBus')?['body']?['message'], actions('SuspendNack:_Send_to_ServiceBus')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('SuspendNack:_Send_to_ServiceBus')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "SuspendNack:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "SuspendNack:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to publish a NACK to the SuspendQueue in ServiceBus"
                                                            }
                                                        },
                                                        "SuspendNack:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "SuspendNack:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('SuspendNack:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('SuspendNack:_Send_to_ServiceBus')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "SuspendNack:_Send_to_ServiceBus": {
                                    "runAfter": {},
                                    "type": "ApiConnection",
                                    "inputs": {
                                        "body": {
                                            "ContentData": "@{base64(variables('NackMessage'))}",
                                            "ContentType": "application/json",
                                            "MessageId": "@coalesce(variables('NackMessage')?['header']?['properties']?['messageId'], guid())",
                                            "Properties": "@variables('NackMessage')?['header']?['routing']",
                                            "SessionId": "none"
                                        },
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['servicebuspublish']['connectionId']"
                                            }
                                        },
                                        "method": "post",
                                        "path": "/@{encodeURIComponent(coalesce(triggerBody()?['suspendQueueTopicName'], '(suspendqueue topic name not set)'))}/messages",
                                        "queries": {
                                            "systemProperties": "None"
                                        }
                                    }
                                },
                                "SuspendNack:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "SuspendNack:_Send_to_ServiceBus": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('SuspendNack:_Send_to_ServiceBus')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Messages": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetMessages"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Suspend_Original_Message": {
                            "actions": {
                                "SuspendOriginalMessage:_Check_FailedMessageRouting_value": {
                                    "actions": {
                                        "SuspendOriginalMessage:_Check_Status_Code": {
                                            "runAfter": {
                                                "SuspendOriginalMessage:_Set_StatusCode_variable": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "cases": {
                                                "Success": {
                                                    "case": 200,
                                                    "actions": {
                                                        "SuspendOriginalMessage:Success:_Set_Checkpoint_variable": {
                                                            "runAfter": {},
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "Checkpoint",
                                                                "value": "SuspendOriginalMessage"
                                                            }
                                                        }
                                                    }
                                                }
                                            },
                                            "default": {
                                                "actions": {
                                                    "SuspendOriginalMessage:Failure:_Do_we_have_a_Fault_Message": {
                                                        "actions": {
                                                            "SuspendOriginalMessage:Fault:_Set_ErrorMessage_variable": {
                                                                "runAfter": {
                                                                    "SuspendOriginalMessage:Fault:_Set_FaultMessage_variable": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "ErrorMessage",
                                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to publish an original message to the SuspendQueue in ServiceBus"
                                                                }
                                                            },
                                                            "SuspendOriginalMessage:Fault:_Set_FaultMessage_variable": {
                                                                "runAfter": {},
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "FaultMessage",
                                                                    "value": "@body('SuspendOriginalMessage:_Send_to_ServiceBus')"
                                                                }
                                                            }
                                                        },
                                                        "runAfter": {},
                                                        "else": {
                                                            "actions": {
                                                                "SuspendOriginalMessage:NoFault:_Create_Fault_Message": {
                                                                    "runAfter": {},
                                                                    "type": "Compose",
                                                                    "inputs": {
                                                                        "fault": {
                                                                            "faultActor": "@concat(workflow()['name'], '.', actions('SuspendOriginalMessage:_Send_to_ServiceBus')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                            "faultCategory": "Error",
                                                                            "faultCode": "@{coalesce(outputs('SuspendOriginalMessage:_Send_to_ServiceBus')?['statusCode'], outputs('SuspendOriginalMessage:_Send_to_ServiceBus')?['body']?['statusCode'], actions('SuspendOriginalMessage:_Send_to_ServiceBus')?['error']?['code'])}",
                                                                            "faultMessage": "@{coalesce(outputs('SuspendOriginalMessage:_Send_to_ServiceBus')?['error']?['message'], outputs('SuspendOriginalMessage:_Send_to_ServiceBus')?['body']?['message'], actions('SuspendOriginalMessage:_Send_to_ServiceBus')?['error']?['message'])}",
                                                                            "faultReason": "@{actions('SuspendOriginalMessage:_Send_to_ServiceBus')?['status']}"
                                                                        }
                                                                    }
                                                                },
                                                                "SuspendOriginalMessage:NoFault:_Set_ErrorMessage_variable": {
                                                                    "runAfter": {
                                                                        "SuspendOriginalMessage:NoFault:_Set_FaultMessage_variable": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "ErrorMessage",
                                                                        "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to publish an original message to the SuspendQueue in ServiceBus"
                                                                    }
                                                                },
                                                                "SuspendOriginalMessage:NoFault:_Set_FaultMessage_variable": {
                                                                    "runAfter": {
                                                                        "SuspendOriginalMessage:NoFault:_Create_Fault_Message": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "FaultMessage",
                                                                        "value": "@outputs('SuspendOriginalMessage:NoFault:_Create_Fault_Message')"
                                                                    }
                                                                }
                                                            }
                                                        },
                                                        "expression": {
                                                            "and": [
                                                                {
                                                                    "not": {
                                                                        "equals": [
                                                                            "@body('SuspendOriginalMessage:_Send_to_ServiceBus')?['fault']",
                                                                            null
                                                                        ]
                                                                    }
                                                                }
                                                            ]
                                                        },
                                                        "type": "If"
                                                    }
                                                }
                                            },
                                            "expression": "@variables('StatusCode')",
                                            "type": "Switch"
                                        },
                                        "SuspendOriginalMessage:_Send_to_ServiceBus": {
                                            "runAfter": {},
                                            "type": "ApiConnection",
                                            "inputs": {
                                                "body": {
                                                    "ContentData": "@{base64(variables('OriginalMessage'))}",
                                                    "ContentType": "application/json",
                                                    "MessageId": "@coalesce(variables('OriginalMessage')?['header']?['properties']?['messageId'], guid())",
                                                    "Properties": {
                                                        "messageType": "@variables('OriginalMessage')?['header']?['properties']?['messageType']",
                                                        "errorType": "FailedMessage"
                                                    },
                                                    "SessionId": "none"
                                                },
                                                "host": {
                                                    "connection": {
                                                        "name": "@parameters('$connections')['servicebuspublish']['connectionId']"
                                                    }
                                                },
                                                "method": "post",
                                                "path": "/@{encodeURIComponent(coalesce(triggerBody()?['suspendQueueTopicName'], '(suspendqueue topic name not set)'))}/messages",
                                                "queries": {
                                                    "systemProperties": "None"
                                                }
                                            }
                                        },
                                        "SuspendOriginalMessage:_Set_StatusCode_variable": {
                                            "runAfter": {
                                                "SuspendOriginalMessage:_Send_to_ServiceBus": [
                                                    "Succeeded",
                                                    "Failed",
                                                    "Skipped",
                                                    "TimedOut"
                                                ]
                                            },
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "StatusCode",
                                                "value": "@coalesce(outputs('SuspendOriginalMessage:_Send_to_ServiceBus')?['statusCode'], 500)"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "SuspendOriginalMessage:Skipped:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "SkippedSuspendOriginalMessage"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(triggerBody()?['failedMessageRouting'], false)",
                                                    true
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "if"
                                }
                            },
                            "runAfter": {
                                "Step:_Suspend_NACK": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SuspendNack"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "$connections": {
                        "value": {
                            "servicebuspublish": {
                                "connectionId": "[variables('serviceBusTopicPublishApiConnectionResourceId')]",
                                "connectionName": "[parameters('serviceBusTopicPublishApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/servicebus')]"
                            }
                        }
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\application\workflows\messagesuspendprocessor\messagesuspendprocessor.logicapp.prod.parameters.json.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\messagesuspendprocessorservicebus.apiconnection.dev.parameters.json.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\messagesuspendprocessorservicebus.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "serviceBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that contains the Azure Service Bus resource."
            }
        },
        "serviceBusNamespaceName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Namespace this API Connection connects to)."
            }
        },
        "serviceBusPolicyName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Policy this API Connection connects to)."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'servicebus')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "connectionString": "[listKeys(resourceId(parameters('serviceBusResourceGroupName'), 'Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('serviceBusNamespaceName'), parameters('serviceBusPolicyName')), '2017-04-01').primaryConnectionString]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\application\workflows\messagesuspendprocessor\messagesuspendprocessorservicebus.apiconnection.prod.parameters.json.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\New-MessageSuspendProcessor-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-MessageSuspendProcessor-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\xmlmessagesuspendprocessor.logicapp.json" -templateParameterFile ".\xmlmessageprocessor.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "xmlmessagesuspendprocessor.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName    
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the xml message suspend processor Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\application\workflows\messagesuspendprocessor\Remove-MessageSuspendProcessorServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the message response handlers service bus api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-MessageSuspendProcessorServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -resourceName "apic-aimsuspendprocessorconnector-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the message suspend processor service bus api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the message suspend processor service bus api connection resource: $resourceName"
}
else {
    Write-Host "The message suspend processor service bus api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\application\workflows\messagesuspendprocessor\TearDown-80-MessageSuspendProcessorServiceBus-ApiConnection.ps1.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\TearDown-85-MessageSuspendProcessor-LogicApp.ps1.liquid
 
tools\templates\channels\topicchannel\Deploy-20-TopicChannel-ServiceBus.ps1.liquid
 
tools\templates\channels\topicchannel\namespace\Deploy-15-Namespace-ServiceBus.ps1.liquid
 
tools\templates\channels\topicchannel\namespace\namespace.sb.dev.psparameters.json.liquid
 
tools\templates\channels\topicchannel\namespace\namespace.sb.prod.psparameters.json.liquid
 
tools\templates\channels\topicchannel\namespace\New-Namespace-ServiceBus.ps1
<#
.SYNOPSIS
Creates a Service Bus Namespace resource for use by various AIM components.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER location
The location to create the service bus in.

.PARAMETER namespace
Namespace to create the service bus with.

.PARAMETER sku
The SKU level for the namespace.

.PARAMETER tags
The tags to apply to the namespace.

.EXAMPLE
.\New-Namespace-ServiceBus.ps1 -resourceGroupName "rg-aimapp-systemapplication-dev-uksouth" -location "uksouth" -namespace "sb-aimmsgbox-dev-uksouth" -sku "Standard" 
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $location,
    [parameter(Mandatory = $true)]
    [string] $namespace,
    [parameter(Mandatory = $false)]
    [string] $sku = "Basic",
    [parameter(Mandatory = $false)]
    [string[]] $tags = ""
)

Write-Host "Deploying the namespace: $namespace"

az servicebus namespace create --resource-group $resourceGroupName --name $namespace --location $location --sku $sku --tags $tags

Write-Host "Deployment Complete"
tools\templates\channels\topicchannel\namespace\Remove-Namespace-ServiceBus.ps1
<#
.SYNOPSIS
Removes the namespace resource.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
The resource group the namespace is in.

.PARAMETER namespace.
The name of the namespace.

.EXAMPLE
.\Remove-Namespace-ServiceBus.ps1 -namespace "sb-aimmsgbox-dev-uksouth" -resourceGroupName "rg-aimapp-systemapplication-dev-uksouth"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $namespace
)

$resourceExists = az servicebus namespace list --resource-group $resourceGroupName --query "[?name=='$namespace'].{name:name}" -o tsv

if ($resourceExists) {
    Write-Host "Removing the namespace resource: $namespace"

    az servicebus namespace delete --name $namespace --resource-group $resourceGroupName
    
    Write-Host "Removed the namespace resource: $namespace"
}
else {
    Write-Host "The namespace resource $namespace does not exist in resource group $resourceGroupName"
}
tools\templates\channels\topicchannel\namespace\TearDown-15-Namespace-ServiceBus.ps1.liquid
 
tools\templates\channels\topicchannel\New-TopicChannel-ServiceBus.ps1
<#
.SYNOPSIS
Creates a Topic Channel resource for use by various AIM components.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER namespace
Namespace to create the topic on.

.PARAMETER topic
Topic name to create in the namespace.

.PARAMETER enablePartitioning
Defines if partitioning should be enabled (true) or not on the topic.

.PARAMETER tags
The tags to apply to the namespace.

.EXAMPLE
.\New-TopicChannel-ServiceBus.ps1 -resourceGroupName "rg-aimapp-systemapplication-dev-uksouth" -namespace "sb-aimmsgbox-dev-uksouth" -topic "messagebox"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $namespace,
    [parameter(Mandatory = $true)]
    [string] $topic,
    [parameter(Mandatory = $true)]
    [bool] $enablePartitioning,
    [parameter(Mandatory = $false)]
    [string[]] $tags = ""
)

Write-Host "Deploying the topic: $topic"

az servicebus topic create --resource-group $resourceGroupName --namespace-name $namespace --name $topic --enable-partitioning $enablePartitioning

Write-Host "Deployment Complete"
tools\templates\channels\topicchannel\Remove-TopicChannel-ServiceBus.ps1
<#
.SYNOPSIS
Removes the topic channel resource.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
The resource group name.

.PARAMETER namespace
The name of the namespace the topic is on.

.PARAMETER topic.
The topic to remove.

.EXAMPLE
.\Remove-TopicChannel-ServiceBus.ps1 -$resourceName "sb-aimmsgbox-dev-uksouth" -resourceGroupName "rg-aimapp-systemapplication-dev-uksouth" -topic "messagebox"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $namespace,
    [parameter(Mandatory = $true)]
    [string] $topic
)

$namespaceResourceExists = az servicebus namespace list --resource-group $resourceGroupName --query "[?name=='$namespace'].{name:name}" -o tsv

if ($namespaceResourceExists) {

    $topicResourceExists = az servicebus topic list --resource-group $resourceGroupName --namespace-name $namespace --query "[?name=='$topic'].{name:name}" -o tsv
 
    if ($topicResourceExists) {

        Write-Host "Removing the topic resource: $topic"

        az servicebus topic delete --resource-group $resourceGroupName --namespace-name $namespace --name $topic

        Write-Host "Removed the topic resource: $topic"
    }
    else {
        Write-Host "The topic resource $topic does not exist in resource group $resourceGroupName with the namespace $namespace"
    }
}
else {
    Write-Host "The namespace $namespace does not exist in resource group $resourceGroupName when attempting to remove the topic $topic"
}
tools\templates\channels\topicchannel\subscriptions\Deploy-30-TopicChannelSubscription-ServiceBus.ps1.liquid
 
tools\templates\channels\topicchannel\subscriptions\New-TopicChannelSubscription-ServiceBus.ps1
<#
.SYNOPSIS
Creates a topic subscription and rules resources.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER name
Name of the subscription that will be created.

.PARAMETER serviceBusNamespace
Name of the Azure Service Bus namespace.

.PARAMETER serviceBusTopic
Name of the Azure Service Bus topic.

.PARAMETER serviceBusSessionsEnabled
Identifies if sessions are enabled (true) or not (false).

.PARAMETER rules
The rules to set on the subscription.

.EXAMPLE
./New-TopicChannelSubscription-ServiceBus.ps1 -resourceGroupName "rg-aimapp-app1-dev-uksouth" -name "sbs-aimmsgbox-ftp-passthru" -serviceBusNamespace "sb-aimmsgbox-dev-uksouth" -serviceBusTopic "messagebox" -serviceBusSessionsEnabled "true" -rules @{<rulesarray>}
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $name,
    [parameter(Mandatory = $true)]
    [string] $serviceBusNamespace,
    [parameter(Mandatory = $true)]
    [string] $serviceBusTopic,
    [parameter(Mandatory = $true)]
    [bool] $serviceBusSessionsEnabled,
    [parameter(Mandatory = $true)]
    [object[]] $rules
)

# --------------------------------------------------------------------------

Write-Host "Deploying the topic subscription $name"

az servicebus topic subscription create --name $name --resource-group $resourceGroupName --namespace-name $serviceBusNamespace --topic-name $serviceBusTopic --enable-session $serviceBusSessionsEnabled
if (!$?) {
    throw "Deployment failed, aborting"
}

Write-Host "Deployment complete"

# --------------------------------------------------------------------------

Write-Host "Creating rules for subscription $name"

ForEach ($rule in $rules) {
    $ruleName = $rule.name

    Write-Host "Creating rule $ruleName in subscription $name"

    az servicebus topic subscription rule create --name $ruleName --resource-group $resourceGroupName --namespace-name $serviceBusNamespace --topic-name $serviceBusTopic --subscription-name $name --filter-sql-expression $rule.expression
    if (!$?) {
        throw "Deployment failed, aborting"
    }
}

Write-Host "Created rules for subscription $name"
tools\templates\channels\topicchannel\subscriptions\Remove-TopicChannelSubscription-ServiceBus.ps1
<#
.SYNOPSIS
Removes a topic subscription.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be deleted.

.PARAMETER name
Name of the subscription that will be deleted.

.PARAMETER serviceBusNamespace
Name of the Azure Service Bus namespace.

.PARAMETER serviceBusTopic
Name of the Azure Service Bus topic.

.EXAMPLE
./Remove-TopicChannelSubscription-ServiceBus.ps1 -resourceGroupName "rg-aimapp-app1-dev-uksouth" -resourceName "sbs-aimmsgbox-ftp-passthru" -serviceBusNamespace "sb-aimmsgbox-dev-uksouth" -serviceBusTopic "messagebox"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName,
    [parameter(Mandatory = $true)]
    [string] $serviceBusNamespace,
    [parameter(Mandatory = $true)]
    [string] $serviceBusTopic
)

$resourceExists = az servicebus topic subscription show --name $resourceName --resource-group $resourceGroupName --namespace-name $serviceBusNamespace --topic-name $serviceBusTopic

if ($resourceExists) {
    Write-Host "Removing the topic subscription resource: $resourceName"

    az servicebus topic subscription delete --name $resourceName --resource-group $resourceGroupName --namespace-name $serviceBusNamespace --topic-name $serviceBusTopic

    Write-Host "Removed the topic subscription resource: $resourceName"
}
else {
    Write-Host "The topic subscription resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\channels\topicchannel\subscriptions\TearDown-30-TopicChannelSubscription-ServiceBus.ps1.liquid
 
tools\templates\channels\topicchannel\subscriptions\topicchannelsubscription.sbs.dev.psparameters.json.liquid
 
tools\templates\channels\topicchannel\subscriptions\topicchannelsubscription.sbs.prod.psparameters.json.liquid
 
tools\templates\channels\topicchannel\TearDown-20-TopicChannel-ServiceBus.ps1.liquid
 
tools\templates\channels\topicchannel\topicchannel.sb.dev.psparameters.json.liquid
 
tools\templates\channels\topicchannel\topicchannel.sb.prod.psparameters.json.liquid
 
tools\templates\Deploy-All.ps1.liquid
 
tools\templates\endpoints\file\datagateway\datagateway.onpremisedatagateway.dev.parameters.json.liquid
 
tools\templates\endpoints\file\datagateway\datagateway.onpremisedatagateway.dev.psparameters.json.liquid
 
tools\templates\endpoints\file\datagateway\datagateway.onpremisedatagateway.json
{
    "$schema": "https://schema.management.azure.com/schemas/2014-04-01-preview/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "dataGatewayName": {
            "type": "String"
        },
        "dataGatewayLocation": {
            "type": "String"
        },
        "connectionGatewayInstallationId": {
            "type": "String"
        },
        "connectionGatewayInstallationLocation": {
            "type": "String"
        },
        "tags": {
            "type": "object"
        }
    },
    "resources": [
        {
            "type": "Microsoft.Web/connectionGateways",
            "name": "[parameters('dataGatewayName')]",
            "apiVersion": "2016-06-01",
            "location": "[parameters('dataGatewayLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "connectionGatewayInstallation": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('connectionGatewayInstallationLocation'), '/connectionGatewayInstallations/', parameters('connectionGatewayInstallationId'))]"
                }
            }
        }
    ],
    "outputs": {
    }
}
tools\templates\endpoints\file\datagateway\datagateway.onpremisedatagateway.prod.parameters.json.liquid
 
tools\templates\endpoints\file\datagateway\datagateway.onpremisedatagateway.prod.psparameters.json.liquid
 
tools\templates\endpoints\file\datagateway\Deploy-30-DataGateway.ps1.liquid
 
tools\templates\endpoints\file\datagateway\New-DataGateway.ps1
<#
.SYNOPSIS
Creates an on-premise data gateway.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
The name of the Azure resource group to deploy the data gateway to.

.PARAMETER subscriptionId
"<azure-subs-id>"

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER connectionGatewayInstallationDisplayName
The name of the connection gateway installation to link the new data gateway to.

.PARAMETER connectionGatewayInstallationLocation
The location of the connection gateway installation to link the new data gateway to.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.
    
.EXAMPLE
.\New-DataGateway.ps1 -resourceGroupName $params.resourceGroupName -subscriptionId "<azure-subs-id>" -connectionGatewayInstallationDisplayName "cgw-aimmsgbus-dev-uksouth-xxxx" -connectionGatewayInstallationLocation "uksouth" -templateFile "datagateway.onpremisedatagateway.json" -templateParameterFile "datagateway.onpremisedatagateway.dev.parameters.json" -deploymentName "datagateway.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,        
    [parameter(Mandatory = $true)]    
    [string] $connectionGatewayInstallationDisplayName,
    [parameter(Mandatory = $true)]    
    [string] $connectionGatewayInstallationLocation,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id
    
    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

$connectionGatewayInstallationName = az rest --method get --uri /subscriptions/$subscriptionId/providers/Microsoft.Web/locations/$connectionGatewayInstallationLocation/connectionGatewayInstallations?api-version=2016-06-01 --query "value[?properties.displayName=='$connectionGatewayInstallationDisplayName'].{Name:name} | [0]" -o tsv

if ($connectionGatewayInstallationName -eq "") {
    throw "No connection gateway installation found in location: $connectionGatewayInstallationLocation with the display name: $connectionGatewayInstallationDisplayName "
}

Write-Host "Deploying the data gateway `r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName" 

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "connectionGatewayInstallationId=$connectionGatewayInstallationName" --parameters "connectionGatewayInstallationLocation=$connectionGatewayInstallationLocation" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\file\datagateway\Remove-DataGateway.ps1
<#
.SYNOPSIS
Removes an on-premise data gateway,.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
The name of the resource group name the connection gateway exists in.

.PARAMETER dataGatewayName
The name of the data gateway to remove.

.EXAMPLE
.\Remove-DataGateway.ps1 -resourceGroupName "rg-aimmsgbus-dev" -dataGatewayName "cgw-aimmsgbus-dev-uksouth-xxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $dataGatewayName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $dataGatewayName --namespace "Microsoft.Web" --resource-type "connectionGateways"

if ($resourceExists) {
    Write-Host "Removing the On-premises Data Gateway $dataGatewayName"

    az resource delete --resource-group $resourceGroupName --name $dataGatewayName --namespace "Microsoft.Web" --resource-type "connectionGateways"

    Write-Host "Removed the On-premises Data Gateway $dataGatewayName"
}
else {
    Write-Host "The On-premises Data Gateway $dataGatewayName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\file\datagateway\TearDown-30-DataGateway.ps1.liquid
 
tools\templates\endpoints\file\receive\Deploy-100-FileReceiveAdapterFileSystem-ApiConnection.ps1.liquid
 
tools\templates\application\workflows\messagesuspendprocessor\Remove-MessageSuspendProcessor-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-MessageSuspendProcessor-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-messagesuspendprocessor-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\application\workflows\messagesuspendprocessor\New-MessageSuspendProcessorServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Creates a service bus api connection for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-MessageSuspendProcessorServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\messagesuspendprocessorrsb.apiconnection.json" -templateParameterFile ".\messagesuspendprocessorsb.apiconnection.dev.parameters.json" -deploymentName "messagesuspendprocessorsb.apiconnection.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying a service bus api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\file\receive\Deploy-100-FileReceiveAdapterServiceBus-ApiConnection.ps1.liquid
 
tools\templates\endpoints\file\receive\Deploy-105-FileReceiveAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\file\receive\filereceiveadapter.logicapp.dev.parameters.json.liquid
 
tools\templates\endpoints\file\receive\filereceiveadapter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicApStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "systemApplicationResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that SystemApplication artifacts are deployed to (e.g. ServiceBus or MessageConstructor LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "string",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "messageConstructorLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle File Message Construction and Sending."
            }
        },
        "messageSuspendProcessorLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle suspending of messages."
            }
        },
        "suspendQueueTopicName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic that suspended messages are sent to."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "fileSystemReceiveApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for Filesystem Receive operations."
            }
        },
        "fileReceiveFolder": {
            "type": "string",
            "metadata": {
                "description": "The path where the File connector looks for new/updated files."
            }
        },
        "fileMaxFileCount": {
            "defaultValue": 10,
            "type": "int",
            "metadata": {
                "description": "The max number of files the File Connector will retrieve per polling interval."
            }
        },
        "fileRecurrenceFrequency": {
            "type": "string",
            "allowedValues": [ "Second", "Minute", "Hour", "Day", "Month", "Year" ],
            "metadata": {
                "description": "The frequency with which to check for new files on the File server."
            }
        },
        "fileRecurrenceInterval": {
            "type": "int",
            "metadata": {
                "description": "The interval with which to check for new files on the File server."
            }
        },
        "serviceBusTopicPublishApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for ServiceBus SuspendQueue Publish operations."
            }
        },
        "scenario": {
            "type": "string",
            "metadata": {
                "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
            }
        },
        "scenarioStep": {
            "defaultValue": "fileReceiveAdapter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. fileReceiveAdapter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "messageConstructorLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageConstructorLogicAppName'))]",
        "messageSuspendProcessorLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageSuspendProcessorLogicAppName'))]",
        "fileSystemApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('fileSystemReceiveApiConnectionName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]",
        "serviceBusTopicPublishApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('serviceBusTopicPublishApiConnectionName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicApStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "$connections": {
                            "defaultValue": {},
                            "type": "Object"
                        },
                        "fileReceiveFolder": {
                            "type": "String",
                            "description": "The path where the File connector looks for new/updated files."
                        },
                        "fileMaxFileCount": {
                            "type": "Int",
                            "description": "The max number of files the File Connector will retrieve per polling interval."
                        },
                        "fileRecurrenceFrequency": {
                            "type": "string",
                            "allowedValues": [ "Second", "Minute", "Hour", "Day", "Month", "Year" ],
                            "description": "The frequency with which to check for new files on the File server."
                        },
                        "fileRecurrenceInterval": {
                            "type": "int",
                            "description": "The interval with which to check for new files on the File server."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        },
                        "scenario": {
                            "type": "String",
                            "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. FileReceiveAdapter."
                        },
                        "clearCache": {
                            "defaultValue": true,
                            "type": "Bool",
                            "description": "Indicates if we should clear APIM cache before retrieved config items e.g. configurationEntries or routingSlips."
                        },
                        "suspendQueueTopicName": {
                            "type": "String",
                            "description": "Name of the ServiceBus Topic that suspended messages are sent to."
                        }
                    },
                    "triggers": {
                        "When_a_file_is_added_or_modified_(properties_only)": {
                            "inputs": {
                                "host": {
                                    "connection": {
                                        "name": "@parameters('$connections')['filesystemreceive']['connectionId']"
                                    }
                                },
                                "method": "get",
                                "path": "/datasets/default/triggers/batch/onupdatedfile",
                                "queries": {
                                    "folderId": "@{parameters('fileReceiveFolder')}",
                                    "maxFileCount": "@parameters('fileMaxFileCount')"
                                }
                            },
                            "recurrence": {
                                "frequency": "@parameters('fileRecurrenceFrequency')",
                                "interval": "@parameters('fileRecurrenceInterval')"
                            },
                            "splitOn": "@triggerBody()",
                            "type": "ApiConnection"
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Compose_FileNameMask": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "Compose",
                            "inputs": "@{coalesce(variables('Configuration')?['scenarioStep']?['fileNameMask'], '*.*')}"
                        },
                        "Respond:_Were_we_successful": {
                            "actions": {
                                "Terminate_with_ACK": {
                                    "runAfter": {},
                                    "type": "Terminate",
                                    "inputs": {
                                        "runStatus": "Succeeded"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Construct_Message": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Do_we_have_a_NACK": {
                                        "actions": {},
                                        "runAfter": {},
                                        "else": {
                                            "actions": {
                                                "Failure:_Build_NACK_message": {
                                                    "runAfter": {},
                                                    "type": "Compose",
                                                    "inputs": {
                                                        "body": [
                                                            {
                                                                "$content": {
                                                                    "code": "500",
                                                                    "message": "@variables('ErrorMessage')",
                                                                    "lastCheckpoint": "@variables('Checkpoint')",
                                                                    "fault": "@variables('FaultMessage')"
                                                                },
                                                                "$contentType": "application/json",
                                                                "$part": 1,
                                                                "$partType": "http://schemas.microsoft.com/aim#nack"
                                                            }
                                                        ],
                                                        "header": {
                                                            "properties": {
                                                                "createDate": "@utcNow()",
                                                                "envelopeType": "nack",
                                                                "messageId": "@guid()",
                                                                "rootPart": 1,
                                                                "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                            },
                                                            "routing": {
                                                                "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                            },
                                                            "routingSlip": {},
                                                            "state": {}
                                                        }
                                                    }
                                                },
                                                "Failure:_Set_ResponseMessage_variable": {
                                                    "runAfter": {
                                                        "Failure:_Build_NACK_message": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "ResponseMessage",
                                                        "value": "@outputs('Failure:_Build_NACK_message')"
                                                    }
                                                }
                                            }
                                        },
                                        "expression": {
                                            "and": [
                                                {
                                                    "equals": [
                                                        "@{coalesce(variables('ResponseMessage')?['header']?['properties']?['envelopeType'], '(unknown)')}",
                                                        "nack"
                                                    ]
                                                }
                                            ]
                                        },
                                        "type": "If"
                                    },
                                    "Failure:_Send_NACK_to_SuspendQueue": {
                                        "runAfter": {
                                            "Failure:_Do_we_have_a_NACK": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Workflow",
                                        "inputs": {
                                            "body": {
                                                "nackMessage": "variables('ResponseMessage')",
                                                "originalMessage": "@triggerBody()",
                                                "suspendQueueTopicName": "@{parameters('suspendQueueTopicName')}",
                                                "failedMessageRouting": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['failedMessageRouting'], false)",
                                                "scenario": "@{parameters('scenario')}"
                                            },
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                            },
                                            "host": {
                                                "triggerName": "manual",
                                                "workflow": {
                                                    "id": "[variables('messageSuspendProcessorLogicAppResourceId')]"
                                                }
                                            }
                                        }
                                    },
                                    "Terminate_with_NACK": {
                                        "runAfter": {
                                            "Failure:_Send_NACK_to_SuspendQueue": [
                                                "Succeeded",
                                                "Failed",
                                                "TimedOut"
                                            ]
                                        },
                                        "type": "Terminate",
                                        "inputs": {
                                            "runError": {
                                                "code": "@{coalesce(variables('ResponseMessage')?['body']?[0]?['$content']?['code'], '500')}",
                                                "message": "@{coalesce(variables('ResponseMessage')?['body']?[0]?['$content']?['message'], '(unknown error)')}"
                                            },
                                            "runStatus": "Failed"
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "IgnoreFile"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ConstructMessageACK"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(parameters('scenario'))}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@parameters('clearCache')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Compose_FileNameMask": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Validate_Configuration": {
                            "actions": {
                                "ValidateConfiguration:_Have_Valid_Properties": {
                                    "actions": {
                                        "ValidateConfiguration:Success:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "ValidateConfiguration"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "ValidateConfiguration:Failure:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): property btsReceivePortName is not set in configuration"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortName'], '')",
                                                        ""
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Should_we_process_file": {
                            "actions": {
                                "ShouldWeProcessFile:_Check_FileMask": {
                                    "inputs": {
                                        "code": "var escapedFileMask = workflowContext.actions.Compose_FileNameMask.outputs;\r\nvar fileMaskRegex = \"^\" + escapedFileMask.replace(\".\", \"[.]\").replace(\"*\", \".*\").replace(\"?\", \".\") + \"$\";\r\nreturn workflowContext.trigger.outputs.body.Name.match(fileMaskRegex) !== null;"
                                    },
                                    "runAfter": {},
                                    "type": "JavaScriptCode"
                                },
                                "ShouldWeProcessFile:Failure:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ShouldWeProcessFile:_Check_FileMask": [
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 500
                                    }
                                },
                                "ShouldWeProcessFile:Success:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ShouldWeProcessFile:_Check_FileMask": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 200
                                    }
                                },
                                "ShouldWeProcessFile:_Check_StatusCode": {
                                    "runAfter": {
                                        "ShouldWeProcessFile:Failure:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ],
                                        "ShouldWeProcessFile:Success:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "ShouldWeProcessFile:Success:_Does_FileMask_match": {
                                                    "actions": {
                                                        "ShouldWeProcessFile:Process:_Set_Checkpoint_variable": {
                                                            "runAfter": {},
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "Checkpoint",
                                                                "value": "ProcessFile"
                                                            }
                                                        }
                                                    },
                                                    "runAfter": {},
                                                    "else": {
                                                        "actions": {
                                                            "ShouldWeProcessFile:Ignore:_Set_Checkpoint_variable": {
                                                                "runAfter": {},
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "Checkpoint",
                                                                    "value": "IgnoreFile"
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "expression": {
                                                        "and": [
                                                            {
                                                                "equals": [
                                                                    "@outputs('ShouldWeProcessFile:_Check_FileMask')?['body']",
                                                                    true
                                                                ]
                                                            }
                                                        ]
                                                    },
                                                    "type": "If"
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "ShouldWeProcessFile:Failure:_Create_Fault_message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "fault": {
                                                        "faultActor": "@concat(workflow()?['name'], '.', actions('ShouldWeProcessFile:_Check_FileMask')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                        "faultCategory": "Error",
                                                        "faultCode": "@{coalesce(outputs('ShouldWeProcessFile:_Check_FileMask')?['statusCode'], outputs('ShouldWeProcessFile:_Check_FileMask')?['body']?['statusCode'], actions('ShouldWeProcessFile:_Check_FileMask')?['error']?['code'])}",
                                                        "faultMessage": "@{coalesce(outputs('ShouldWeProcessFile:_Check_FileMask')?['error']?['message'], outputs('ShouldWeProcessFile:_Check_FileMask')?['body']?['message'], actions('ShouldWeProcessFile:_Check_FileMask')?['error']?['message'])}",
                                                        "faultReason": "@{actions('ShouldWeProcessFile:_Check_FileMask')?['status']}"
                                                    }
                                                }
                                            },
                                            "ShouldWeProcessFile:Failure:_Set_ErrorMessage_variable": {
                                                "runAfter": {
                                                    "ShouldWeProcessFile:Failure:_Set_FaultMessage_variable": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to execute the FileMask Javascript"
                                                }
                                            },
                                            "ShouldWeProcessFile:Failure:_Set_FaultMessage_variable": {
                                                "runAfter": {
                                                    "ShouldWeProcessFile:Failure:_Create_Fault_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "FaultMessage",
                                                    "value": "@outputs('ShouldWeProcessFile:Failure:_Create_Fault_message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                }
                            },
                            "runAfter": {
                                "Step:_Validate_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ValidateConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Construct_Message": {
                            "actions": {
                                "ConstructMessage:_Call_MessageConstructor": {
                                    "runAfter": {
                                        "ConstructMessage:_Get_file_content": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": {
                                            "$content": "@{body('ConstructMessage:_Get_file_content')}",
                                            "$contentTransferEncoding": "none",
                                            "$contentType": "@triggerBody()?['MediaType']",
                                            "properties": {
                                                "receivedFileName": "@{triggerBody()?['Name']}",
                                                "scenario": "@{parameters('scenario')}",
                                                "btsReceivePortName": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortName'], '(unknownReceivePortName)')}",
                                                "btsReceivePortId": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortId'], '(unknownReceivePortId)')}"
                                            }
                                        },
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('messageConstructorLogicAppResourceId')]"
                                            }
                                        }
                                    }
                                },
                                "ConstructMessage:_Check_StatusCode": {
                                    "runAfter": {
                                        "ConstructMessage:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "ConstructMessage:Success:_Check_EnvelopeType": {
                                                    "runAfter": {},
                                                    "cases": {
                                                        "ACK": {
                                                            "case": "ack",
                                                            "actions": {
                                                                "ACK:_Set_ResponseMessage_variable": {
                                                                    "runAfter": {},
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "ResponseMessage",
                                                                        "value": "@body('ConstructMessage:_Call_MessageConstructor')"
                                                                    }
                                                                },
                                                                "ACK:_Set_Checkpoint_variable": {
                                                                    "runAfter": {
                                                                        "ACK:_Set_ResponseMessage_variable": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "Checkpoint",
                                                                        "value": "ConstructMessageACK"
                                                                    }
                                                                }
                                                            }
                                                        },
                                                        "NACK": {
                                                            "case": "nack",
                                                            "actions": {
                                                                "NACK:_Set_ResponseMessage_variable": {
                                                                    "runAfter": {},
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "ResponseMessage",
                                                                        "value": "@body('ConstructMessage:_Call_MessageConstructor')"
                                                                    }
                                                                },
                                                                "NACK:_Set_Checkpoint_variable": {
                                                                    "runAfter": {
                                                                        "NACK:_Set_ResponseMessage_variable": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "Checkpoint",
                                                                        "value": "ConstructMessageNACK"
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "default": {
                                                        "actions": {
                                                            "ConstructMessage:UnknownEnvelope:_Compose_NACK_Message": {
                                                                "runAfter": {},
                                                                "type": "Compose",
                                                                "inputs": {
                                                                    "body": [
                                                                        {
                                                                            "$content": {
                                                                                "code": "500",
                                                                                "message": "@concat('Body returned by action ', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' is not an ACK or NACK. Envelope type is: ', coalesce(body('ConstructMessage:_Call_MessageConstructor')?['header']?['properties']?['envelopeType'], '(unknown)'))"
                                                                            },
                                                                            "$contentType": "application/json",
                                                                            "$part": 1,
                                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                                        }
                                                                    ],
                                                                    "header": {
                                                                        "properties": {
                                                                            "createDate": "@utcNow()",
                                                                            "envelopeType": "nack",
                                                                            "messageId": "@guid()",
                                                                            "rootPart": 1,
                                                                            "trackingId": ""
                                                                        },
                                                                        "routing": {
                                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                                        },
                                                                        "routingSlip": {},
                                                                        "state": {}
                                                                    }
                                                                }
                                                            },
                                                            "ConstructMessage:UnknownEnvelope:_Set_ResponseMessage_variable": {
                                                                "runAfter": {
                                                                    "ConstructMessage:UnknownEnvelope:_Compose_NACK_Message": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "ResponseMessage",
                                                                    "value": "@outputs('ConstructMessage:UnknownEnvelope:_Compose_NACK_Message')"
                                                                }
                                                            },
                                                            "ConstructMessage:UnknownEnvelope:_Set_Checkpoint_variable": {
                                                                "runAfter": {
                                                                    "ConstructMessage:UnknownEnvelope:_Set_ResponseMessage_variable": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "Checkpoint",
                                                                    "value": "ConstructMessageNACK"
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "expression": "@body('ConstructMessage:_Call_MessageConstructor')?['header']?['properties']?['envelopeType']",
                                                    "type": "Switch"
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "ConstructMessage:Failure:_Create_NACK_Message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['statusCode'], outputs('ConstructMessage:_Call_MessageConstructor')?['body']?['statusCode'])}",
                                                                    "faultMessage": "@{coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['error']?['message'], outputs('ConstructMessage:_Call_MessageConstructor')?['body']?['message'])}",
                                                                    "faultReason": ""
                                                                },
                                                                "message": "@concat('Action ', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' resulted in an error response.')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": ""
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "ConstructMessage:Failure:_Set_ResponseMessage_variable": {
                                                "runAfter": {
                                                    "ConstructMessage:Failure:_Create_NACK_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ResponseMessage",
                                                    "value": "@outputs('ConstructMessage:Failure:_Create_NACK_Message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "ConstructMessage:_Get_file_content": {
                                    "runAfter": {},
                                    "type": "ApiConnection",
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['filesystemreceive']['connectionId']"
                                            }
                                        },
                                        "method": "get",
                                        "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}/content",
                                        "queries": {
                                            "inferContentType": true
                                        }
                                    }
                                },
                                "ConstructMessage:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ConstructMessage:_Call_MessageConstructor": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Should_we_process_file": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ProcessFile"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "$connections": {
                        "value": {
                            "filesystemreceive": {
                                "connectionId": "[variables('fileSystemApiConnectionResourceId')]",
                                "connectionName": "[parameters('fileSystemReceiveApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/filesystem')]"
                            },
                            "servicebuspublish": {
                                "connectionId": "[variables('serviceBusTopicPublishApiConnectionResourceId')]",
                                "connectionName": "[parameters('serviceBusTopicPublishApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/servicebus')]"
                            }
                        }
                    },
                    "fileReceiveFolder": {
                        "value": "[parameters('fileReceiveFolder')]"
                    },
                    "fileMaxFileCount": {
                        "value": "[parameters('fileMaxFileCount')]"
                    },
                    "fileRecurrenceFrequency": {
                        "value": "[parameters('fileRecurrenceFrequency')]"
                    },
                    "fileRecurrenceInterval": {
                        "value": "[parameters('fileRecurrenceInterval')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    },
                    "scenario": {
                        "value": "[parameters('scenario')]"
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "suspendQueueTopicName": {
                        "value": "[parameters('suspendQueueTopicName')]"
                    }
                }
            }
        }
    ]
}
tools\templates\endpoints\file\receive\filereceiveadapter.logicapp.prod.parameters.json.liquid
 
tools\templates\endpoints\file\receive\filereceiveadapterfilesystem.apiconnection.dev.parameters.json.liquid
 
tools\templates\endpoints\file\receive\filereceiveadapterfilesystem.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "rootFolder": {
            "type": "string",
            "metadata": {
                "description": "Root folder to use with the Filesystem connector"
            }
        },
        "authType": {
            "defaultValue": "windows",
            "type": "string",
            "metadata": {
                "description": "Authentication type to use with the Filesystem connector"
            }
        },
        "userName": {
            "type": "string",
            "metadata": {
                "description": "User Name for the Filesystem connector"
            }
        },
        "password": {
            "type": "securestring",
            "metadata": {
                "description": "Password for the Filesystem connector"
            }
        },
        "gatewayResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup the On-Premises Data Gateway is located in"
            }
        },
        "gatewayName": {
            "type": "string",
            "metadata": {
                "description": "Name of the On-Premises Data Gateway to use"
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "gatewayResourceId": "[resourceId(parameters('gatewayResourceGroupName'), 'Microsoft.Web/connectionGateways', parameters('gatewayName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'filesystem')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "rootfolder": "[parameters('rootfolder')]",
                    "authType": "[parameters('authType')]",
                    "userName": "[parameters('userName')]",
                    "password": "[parameters('password')]",
                    "gateway": {
                        "id": "[variables('gatewayResourceId')]"
                    }
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\endpoints\file\receive\filereceiveadapterfilesystem.apiconnection.prod.parameters.json.liquid
 
tools\templates\endpoints\file\receive\filereceiveadapterservicebus.apiconnection.dev.parameters.json.liquid
 
tools\templates\endpoints\file\receive\filereceiveadapterservicebus.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "serviceBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that contains the Azure Service Bus resource."
            }
        },
        "serviceBusNamespaceName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Namespace this API Connection connects to)."
            }
        },
        "serviceBusPolicyName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Policy this API Connection connects to)."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'servicebus')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "connectionString": "[listKeys(resourceId(parameters('serviceBusResourceGroupName'), 'Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('serviceBusNamespaceName'), parameters('serviceBusPolicyName')), '2017-04-01').primaryConnectionString]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\endpoints\file\receive\filereceiveadapterservicebus.apiconnection.prod.parameters.json.liquid
 
tools\templates\endpoints\file\receive\New-FileReceiveAdapter-LogicApp.ps1
<#
.SYNOPSIS
Creates a file receive adapter for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FileReceiveAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth" -templateFile ".\filereceiveadapter.logicapp.json" -templateParameterFile ".\filereceiveadapter.logicapp.dev.parameters.json" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "filereceiveadapter.logicapp.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying a file receive adapter`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\file\receive\New-FileReceiveAdapterFileSystem-ApiConnection.ps1
<#
.SYNOPSIS
Creates a file api connection for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FileReceiveAdapterFileSystem-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth" -templateFile ".\filereceiveadapterfile.apiconnection.json" -templateParameterFile ".\filereceiveadapterfile.apiconnection.dev.parameters.json" -deployment -deploymentName "filereceiveadapterfile
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying a file system api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\file\receive\New-FileReceiveAdapterServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Creates a service bus api connection for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FileReceiveAdapterServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth" -templateFile ".\filereceiveadaptersb.apiconnection.json" -templateParameterFile ".\filereceiveadaptersb.apiconnection.dev.parameters.json" -deploymentName "filereceiveadaptersb.apiconnection.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying a service bus api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\file\receive\Remove-FileReceiveAdapter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the file receive adapter.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-FileReceiveAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth-xxxxx" -resourceName "logic-Aim-FilePassthru-ReceiveLocation-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

if ($resourceExists) {
    Write-Host "Removing the file receive adapter resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

    Write-Host "Removed the file receive adapter resource: $resourceName"
}
else {
    Write-Host "The file receive adapter resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\file\receive\Remove-FileReceiveAdapterFileSystem-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the file receive adapters file system api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-FileReceiveAdapterFileSystem-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth" -resourceName "filereceiveconnector-Aim-filePassthru-ReceiveLocation-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the file receive adapters file system api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the file receive adapters file system api connection resource: $resourceName"
}
else {
    Write-Host "The file receive adapters file system api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\file\receive\Remove-FileReceiveAdapterServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the file receive adapters service bus api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-FileReceiveAdapterServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth" -resourceName "topicpublisherconnector-filereceiveadapater-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the file receive adapters service bus api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the file receive adapters service bus api connection resource: $resourceName"
}
else {
    Write-Host "The file receive adapters service bus api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\file\receive\TearDown-100-FileReceiveAdapterFileSystem-ApiConnection.ps1.liquid
 
tools\templates\endpoints\file\receive\TearDown-100-FileReceiveAdapterServiceBus-ApiConnection.ps1.liquid
 
tools\templates\endpoints\file\receive\TearDown-105-FileReceiveAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\file\send\Deploy-100-FileSendAdapter-ApiConnection.ps1.liquid
 
tools\templates\endpoints\file\send\Deploy-105-FileSendAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\file\send\filesendadapter.logicapp.dev.parameters.json.liquid
 
tools\templates\endpoints\file\send\filesendadapter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "fileSystemSendApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for File Send operations."
            }
        },
        "scenarioStep": {
            "defaultValue": "fileSendAdapter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. fileSendAdapter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "fileSendApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('fileSystemSendApiConnectionName'))]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "$connections": {
                            "defaultValue": {},
                            "type": "Object"
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. fileSendAdapter."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_SendFileName_variable": {
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "SendFileName",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_CopyMode_variable": {
                            "runAfter": {
                                "Initialize_SendFileName_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "CopyMode",
                                        "type": "string",
                                        "value": "Create"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                            "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                            "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_SendToFile": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SendToFile"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_CopyMode_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Missing:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "NoBodyContent"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_GetSendFileName": {
                            "actions": {
                                "GetSendFileName:_Set_SendFileName_variable": {
                                    "description": "A full list of supported FileName macros can be found here: https://social.technet.microsoft.com/wiki/contents/articles/8823.biztalk-server-list-of-macros.aspx. At this time we are not supporting the Party macros.",
                                    "type": "SetVariable",
                                    "runAfter": {},
                                    "inputs": {
                                        "name": "SendFileName",
                                        "value": "@{replace(replace(replace(replace(replace(replace(replace(coalesce(variables('Configuration')?[parameters('scenarioStep')]?['fileName'], '%MessageID%.xml'), '%MessageID%', coalesce(triggerBody()?['header']?['properties']?['messageId'], guid())), '%SourceFileName%', coalesce(triggerBody()?['header']?['properties']?['receivedFileName'], 'myfile.txt')), '%datetime%', utcNow('yyyy-MM-ddThhmmss')), '%datetime_bts2000%', utcNow('yyyyMMddhhmmsss')), '%datetime.tz%', utcNow('yyyy-MM-ddThhmmssK')), '%time%', utcNow('hhmmss')), '%time.tz%', utcNow('hhmmssK'))}"
                                    }
                                },
                                "SendToFile:_Set_Checkpoint_variable": {
                                    "runAfter": {
                                        "GetSendFileName:_Set_SendFileName_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "Checkpoint",
                                        "value": "GetSendFileName"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "NoBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_SendToFile": {
                            "actions": {
                                "SendToFile:_Check_Status_Code": {
                                    "runAfter": {
                                        "SendToFile:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "SendToFile:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "SendToFile"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "SendToFile:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "SendToFile:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "SendToFile:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to send a file using the FileSystem connector"
                                                        }
                                                    },
                                                    "SendToFile:Fault:_Create_Fault_Message": {
                                                        "runAfter": {},
                                                        "type": "Compose",
                                                        "inputs": {
                                                            "fault": {
                                                                "faultActor": "@concat(workflow()?['name'], '.', actions('SendToFile:_Create_File')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                "faultCategory": "Error",
                                                                "faultCode": "@{coalesce(outputs('SendToFile:_Create_File')?['statusCode'], outputs('SendToFile:_Create_File')?['body']?['statusCode'], actions('SendToFile:_Create_File')?['error']?['code'])}",
                                                                "faultMessage": "@{coalesce(outputs('SendToFile:_Create_File')?['error']?['message'], outputs('SendToFile:_Create_File')?['body']?['message'], actions('SendToFile:_Create_File')?['error']?['message'])}",
                                                                "faultReason": "@{actions('SendToFile:_Create_File')?['status']}"
                                                            }
                                                        }
                                                    },
                                                    "SendToFile:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {
                                                            "SendToFile:Fault:_Create_Fault_Message": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('SendToFile:Fault:_Create_Fault_Message')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "SendToFile:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('SendToFile:_Create_File')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('SendToFile:_Create_File')?['statusCode'], outputs('SendToFile:_Create_File')?['body']?['statusCode'])}",
                                                                    "faultMessage": "@{coalesce(outputs('SendToFile:_Create_File')?['error']?['message'], outputs('SendToFile:_Create_File')?['body']?['message'])}",
                                                                    "faultReason": "@actions('SendToFile:_Create_File')?['inputs']?['path']"
                                                                }
                                                            }
                                                        },
                                                        "SendToFile:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "SendToFile:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to send a file using the FileSystem connector"
                                                            }
                                                        },
                                                        "SendToFile:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "SendToFile:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('SendToFile:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('SendToFile:_Create_File')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "SendToFile:_Set_CopyMode_variable": {
                                    "runAfter": {},
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "CopyMode",
                                        "value": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['copyMode'], 'Create')}"
                                    }
                                },
                                "SendToFile:_Create_File": {
                                    "inputs": {
                                        "body": "@variables('BodyContent')",
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['filesystemsend']['connectionId']"
                                            }
                                        },
                                        "method": "@{if(equals(variables('CopyMode'), 'Create'), 'post', if(equals(variables('CopyMode'), 'Append'), 'patch', if(equals(variables('CopyMode'), 'Update'), 'put', 'undefined')))}",
                                        "path": "/datasets/default/files@{if(contains(createArray('Append', 'Update'), variables('CopyMode')), concat(coalesce(variables('Configuration')?[parameters('scenarioStep')]?['destinationFolder'], '(undefined)'), '\\', variables('SendFileName')), '')}",
                                        "queries": {
                                            "folderPath": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['destinationFolder'], '(undefined)')",
                                            "name": "@variables('SendFileName')",
                                            "queryParametersSingleEncoded": true
                                        }
                                    },
                                    "runAfter": {
                                        "SendToFile:_Set_CopyMode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "runtimeConfiguration": {
                                        "contentTransfer": {
                                            "transferMode": "Chunked"
                                        }
                                    },
                                    "type": "ApiConnection"
                                },
                                "SendToFile:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "SendToFile:_Create_File": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('SendToFile:_Create_File')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_GetSendFileName": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetSendFileName"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "$connections": {
                        "value": {
                            "filesystemsend": {
                                "connectionId": "[variables('fileSendApiConnectionResourceId')]",
                                "connectionName": "[parameters('fileSystemSendApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/filesystem')]"
                            }
                        }
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\endpoints\file\send\filesendadapter.logicapp.prod.parameters.json.liquid
 
tools\templates\endpoints\file\send\filesystemsendadapter.apiconnection.dev.parameters.json.liquid
 
tools\templates\endpoints\file\send\filesystemsendadapter.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "rootFolder": {
            "type": "string",
            "metadata": {
                "description": "Root folder to use with the Filesystem connector"
            }
        },
        "authType": {
            "defaultValue": "windows",
            "type": "string",
            "metadata": {
                "description": "Authentication type to use with the Filesystem connector"
            }
        },
        "userName": {
            "type": "string",
            "metadata": {
                "description": "User Name for the Filesystem connector"
            }
        },
        "password": {
            "type": "securestring",
            "metadata": {
                "description": "Password for the Filesystem connector"
            }
        },
        "gatewayResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup the On-Premises Data Gateway is located in"
            }
        },
        "gatewayName": {
            "type": "string",
            "metadata": {
                "description": "Name of the On-Premises Data Gateway to use"
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "gatewayResourceId": "[resourceId(parameters('gatewayResourceGroupName'), 'Microsoft.Web/connectionGateways', parameters('gatewayName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'filesystem')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "rootfolder": "[parameters('rootfolder')]",
                    "authType": "[parameters('authType')]",
                    "userName": "[parameters('userName')]",
                    "password": "[parameters('password')]",
                    "gateway": {
                        "id": "[variables('gatewayResourceId')]"
                    }
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\endpoints\file\send\filesystemsendadapter.apiconnection.prod.parameters.json.liquid
 
tools\templates\endpoints\file\send\New-FileSendAdapter-ApiConnection.ps1
<#
.SYNOPSIS
Creates a file send adapters api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FileSendAdapter-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth-xxxxx" -templateFile ".\fileconnection.json" -templateParameterFile ".\fileconnection.dev.parameters.json" -deploymentName "filesendconnection"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying a file send adapters api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\file\send\New-FileSendAdapter-LogicApp.ps1
<#
.SYNOPSIS
Creates a file send adapter.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FileSendAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth-xxxxx" -templateFile ".\fileadapter.json" -templateParameterFile ".\fileadapter.dev.parameters.json" -deploymentName "fileadapter"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription from Key Vault for the routing slip router Logic App"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying a file send adapter`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\file\send\Remove-FileSendAdapter-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the file send adapters api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-FileSendAdapter-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth-xxxxx" -resourceName "filereceiveconnector-Aim-FilePassthru-ReceiveLocation-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the file send adapters api connection: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the file send adapters api connection: $resourceName"
}
else {
    Write-Host "The file send adapaters api connectionresource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\file\send\Remove-FileSendAdapter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the file send adapter.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-FileSendAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-filepassthru-dev-uksouth-xxxxx" -resourceName "logic-Aim-FilePassthru-ReceiveLocation-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

if ($resourceExists) {
    Write-Host "Removing the file send adapter resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

    Write-Host "Removed the file send adapter resource: $resourceName"
}
else {
    Write-Host "The file send adapter resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\file\send\TearDown-100-FileSendAdapter-ApiConnection.ps1.liquid
 
tools\templates\endpoints\file\send\TearDown-105-FileSendAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\ftp\receive\Deploy-100-FtpReceiveAdapterFtp-ApiConnection.ps1.liquid
 
tools\templates\endpoints\ftp\receive\Deploy-100-FtpReceiveAdapterServiceBus-ApiConnection.ps1.liquid
 
tools\templates\endpoints\ftp\receive\Deploy-105-FtpReceiveAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\ftp\receive\ftpreceiveadapter.logicapp.dev.parameters.json.liquid
 
tools\templates\endpoints\ftp\receive\ftpreceiveadapter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicApStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "systemApplicationResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that SystemApplication artifacts are deployed to (e.g. ServiceBus or MessageConstructor LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "string",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "messageConstructorLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle FTP Message Construction and Sending."
            }
        },
        "messageSuspendProcessorLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle suspending of messages."
            }
        },
        "suspendQueueTopicName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic that suspended messages are sent to."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "ftpReceiveApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for FTP Receive operations."
            }
        },
        "ftpReceiveFolder": {
            "type": "string",
            "metadata": {
                "description": "The path where the FTP connector looks for new/updated files."
            }
        },
        "ftpMaxFileCount": {
            "defaultValue": 10,
            "type": "int",
            "metadata": {
                "description": "The max number of files the FTP Connector will retrieve per polling interval."
            }
        },
        "ftpFileMask": {
            "type": "string",
            "metadata": {
                "description": "The mask to use to decide if we're processing a given file e.g. *.* or *.csv"
            }
        },
        "ftpRecurrenceFrequency": {
            "type": "string",
            "allowedValues": [ "Second", "Minute", "Hour", "Day", "Month", "Year" ],
            "metadata": {
                "description": "The frequency with which to check for new files on the FTP server."
            }
        },
        "ftpRecurrenceInterval": {
            "type": "int",
            "metadata": {
                "description": "The interval with which to check for new files on the FTP server."
            }
        },
        "serviceBusTopicPublishApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for ServiceBus SuspendQueue Publish operations."
            }
        },
        "scenario": {
            "type": "string",
            "metadata": {
                "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
            }
        },
        "scenarioStep": {
            "defaultValue": "ftpReceiveAdapter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. ftpReceiveAdapter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "messageConstructorLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageConstructorLogicAppName'))]",
        "messageSuspendProcessorLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageSuspendProcessorLogicAppName'))]",
        "ftpApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('ftpReceiveApiConnectionName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]",
        "serviceBusTopicPublishApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('serviceBusTopicPublishApiConnectionName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicApStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "$connections": {
                            "defaultValue": {},
                            "type": "Object"
                        },
                        "ftpReceiveFolder": {
                            "type": "String",
                            "description": "The path where the FTP connector looks for new/updated files."
                        },
                        "ftpMaxFileCount": {
                            "type": "Int",
                            "description": "The max number of files the FTP Connector will retrieve per polling interval."
                        },
                        "ftpRecurrenceFrequency": {
                            "type": "string",
                            "allowedValues": [ "Second", "Minute", "Hour", "Day", "Month", "Year" ],
                            "description": "The frequency with which to check for new files on the FTP server."
                        },
                        "ftpRecurrenceInterval": {
                            "type": "int",
                            "description": "The interval with which to check for new files on the FTP server."
                        },
                        "fileNameMask": {
                            "defaultValue": "*.*",
                            "type": "String",
                            "description": "The mask to use to decide if we're processing a given file e.g. *.* or *.csv"
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        },
                        "scenario": {
                            "type": "String",
                            "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. FTPReceiveAdapter."
                        },
                        "clearCache": {
                            "defaultValue": true,
                            "type": "Bool",
                            "description": "Indicates if we should clear APIM cache before retrieved config items e.g. configurationEntries or routingSlips."
                        },
                        "suspendQueueTopicName": {
                            "type": "String",
                            "description": "Name of the ServiceBus Topic that suspended messages are sent to."
                        }
                    },
                    "triggers": {
                        "When_a_file_is_added_or_modified_(properties_only)": {
                            "recurrence": {
                                "frequency": "@{parameters('ftpRecurrenceFrequency')}",
                                "interval": "@parameters('ftpRecurrenceInterval')"
                            },
                            "splitOn": "@triggerBody()",
                            "type": "ApiConnection",
                            "inputs": {
                                "host": {
                                    "connection": {
                                        "name": "@parameters('$connections')['ftpreceive']['connectionId']"
                                    }
                                },
                                "method": "get",
                                "path": "/datasets/default/triggers/batch/onupdatedfile",
                                "queries": {
                                    "folderId": "@{parameters('ftpReceiveFolder')}",
                                    "maxFileCount": "@parameters('ftpMaxFileCount')"
                                }
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Compose_FileNameMask": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "Compose",
                            "inputs": "@parameters('fileNameMask')"
                        },
                        "Respond:_Were_we_successful": {
                            "actions": {
                                "Terminate_with_ACK": {
                                    "runAfter": {},
                                    "type": "Terminate",
                                    "inputs": {
                                        "runStatus": "Succeeded"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Construct Message": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Do_we_have_a_NACK": {
                                        "actions": {},
                                        "runAfter": {},
                                        "else": {
                                            "actions": {
                                                "Failure:_Build_NACK_message": {
                                                    "runAfter": {},
                                                    "type": "Compose",
                                                    "inputs": {
                                                        "body": [
                                                            {
                                                                "$content": {
                                                                    "code": "500",
                                                                    "message": "@variables('ErrorMessage')",
                                                                    "lastCheckpoint": "@variables('Checkpoint')",
                                                                    "fault": "@variables('FaultMessage')"
                                                                },
                                                                "$contentType": "application/json",
                                                                "$part": 1,
                                                                "$partType": "http://schemas.microsoft.com/aim#nack"
                                                            }
                                                        ],
                                                        "header": {
                                                            "properties": {
                                                                "createDate": "@utcNow()",
                                                                "envelopeType": "nack",
                                                                "messageId": "@guid()",
                                                                "rootPart": 1,
                                                                "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                            },
                                                            "routing": {
                                                                "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                            },
                                                            "routingSlip": {},
                                                            "state": {}
                                                        }
                                                    }
                                                },
                                                "Failure:_Set_ResponseMessage_variable": {
                                                    "runAfter": {
                                                        "Failure:_Build_NACK_message": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "ResponseMessage",
                                                        "value": "@outputs('Failure:_Build_NACK_message')"
                                                    }
                                                }
                                            }
                                        },
                                        "expression": {
                                            "and": [
                                                {
                                                    "equals": [
                                                        "@{coalesce(variables('ResponseMessage')?['header']?['properties']?['envelopeType'], '(unknown)')}",
                                                        "nack"
                                                    ]
                                                }
                                            ]
                                        },
                                        "type": "If"
                                    },
                                    "Failure:_Send_NACK_to_SuspendQueue": {
                                        "runAfter": {
                                            "Failure:_Do_we_have_a_NACK": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Workflow",
                                        "inputs": {
                                            "body": {
                                                "nackMessage": "variables('ResponseMessage')",
                                                "originalMessage": "@triggerBody()",
                                                "suspendQueueTopicName": "@{parameters('suspendQueueTopicName')}",
                                                "failedMessageRouting": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['failedMessageRouting'], false)",
                                                "scenario": "@{parameters('scenario')}"
                                            },
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                            },
                                            "host": {
                                                "triggerName": "manual",
                                                "workflow": {
                                                    "id": "[variables('messageSuspendProcessorLogicAppResourceId')]"
                                                }
                                            }
                                        }
                                    },
                                    "Terminate_with_NACK": {
                                        "runAfter": {
                                            "Failure:_Send_NACK_to_SuspendQueue": [
                                                "Succeeded",
                                                "Failed",
                                                "Skipped",
                                                "TimedOut"
                                            ]
                                        },
                                        "type": "Terminate",
                                        "inputs": {
                                            "runError": {
                                                "code": "@{coalesce(variables('ResponseMessage')?['body']?[0]?['$content']?['code'], '500')}",
                                                "message": "@{coalesce(variables('ResponseMessage')?['body']?[0]?['$content']?['message'], '(unknown error)')}"
                                            },
                                            "runStatus": "Failed"
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "IgnoreFile"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ConstructMessageACK"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(parameters('scenario'))}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@parameters('clearCache')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Compose_FileNameMask": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Validate_Configuration": {
                            "actions": {
                                "ValidateConfiguration:_Have_Valid_Properties": {
                                    "actions": {
                                        "ValidateConfiguration:Success:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "ValidateConfiguration"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "ValidateConfiguration:Failure:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): property btsReceivePortName is not set in configuration"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortName'], '')",
                                                        ""
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Should_we_process_file": {
                            "actions": {
                                "ShouldWeProcessFile:_Check_FileMask": {
                                    "runAfter": {},
                                    "type": "JavaScriptCode",
                                    "inputs": {
                                        "code": "var escapedFileMask = workflowContext.actions.Compose_FileNameMask.outputs;\r\nvar fileMaskRegex = \"^\" + escapedFileMask.replace(\".\", \"[.]\").replace(\"*\", \".*\").replace(\"?\", \".\") + \"$\";\r\nreturn workflowContext.trigger.outputs.body.Name.match(fileMaskRegex) !== null;"
                                    }
                                },
                                "ShouldWeProcessFile:Failure:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ShouldWeProcessFile:_Check_FileMask": [
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 500
                                    }
                                },
                                "ShouldWeProcessFile:Success:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ShouldWeProcessFile:_Check_FileMask": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 200
                                    }
                                },
                                "ShouldWeProcessFile:_Check_StatusCode": {
                                    "runAfter": {
                                        "ShouldWeProcessFile:Failure:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ],
                                        "ShouldWeProcessFile:Success:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "ShouldWeProcessFile:Success:_Does_FileMask_match": {
                                                    "actions": {
                                                        "ShouldWeProcessFile:Process:_Set_Checkpoint_variable": {
                                                            "runAfter": {},
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "Checkpoint",
                                                                "value": "ProcessFile"
                                                            }
                                                        }
                                                    },
                                                    "runAfter": {},
                                                    "else": {
                                                        "actions": {
                                                            "ShouldWeProcessFile:Ignore:_Set_Checkpoint_variable": {
                                                                "runAfter": {},
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "Checkpoint",
                                                                    "value": "IgnoreFile"
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "expression": {
                                                        "and": [
                                                            {
                                                                "equals": [
                                                                    "@outputs('ShouldWeProcessFile:_Check_FileMask')?['body']",
                                                                    true
                                                                ]
                                                            }
                                                        ]
                                                    },
                                                    "type": "If"
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "ShouldWeProcessFile:Failure:_Create_Fault_message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "fault": {
                                                        "faultActor": "@concat(workflow()?['name'], '.', actions('ShouldWeProcessFile:_Check_FileMask')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                        "faultCategory": "Error",
                                                        "faultCode": "@{coalesce(outputs('ShouldWeProcessFile:_Check_FileMask')?['statusCode'], outputs('ShouldWeProcessFile:_Check_FileMask')?['body']?['statusCode'], actions('ShouldWeProcessFile:_Check_FileMask')?['error']?['code'])}",
                                                        "faultMessage": "@{coalesce(outputs('ShouldWeProcessFile:_Check_FileMask')?['error']?['message'], outputs('ShouldWeProcessFile:_Check_FileMask')?['body']?['message'], actions('ShouldWeProcessFile:_Check_FileMask')?['error']?['message'])}",
                                                        "faultReason": "@{actions('ShouldWeProcessFile:_Check_FileMask')?['status']}"
                                                    }
                                                }
                                            },
                                            "ShouldWeProcessFile:Failure:_Set_ErrorMessage_variable": {
                                                "runAfter": {
                                                    "ShouldWeProcessFile:Failure:_Set_FaultMessage_variable": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to execute the FileMask Javascript"
                                                }
                                            },
                                            "ShouldWeProcessFile:Failure:_Set_FaultMessage_variable": {
                                                "runAfter": {
                                                    "ShouldWeProcessFile:Failure:_Create_Fault_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "FaultMessage",
                                                    "value": "@outputs('ShouldWeProcessFile:Failure:_Create_Fault_message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                }
                            },
                            "runAfter": {
                                "Step:_Validate_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ValidateConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Construct Message": {
                            "actions": {
                                "ConstructMessage:_Call_MessageConstructor": {
                                    "runAfter": {
                                        "ConstructMessage:_Get_file_content": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": {
                                            "$content": "@{body('ConstructMessage:_Get_file_content')}",
                                            "$contentTransferEncoding": "none",
                                            "$contentType": "@triggerBody()?['MediaType']",
                                            "properties": {
                                                "receivedFileName": "@{triggerBody()?['Name']}",
                                                "scenario": "@{parameters('scenario')}",
                                                "btsReceivePortName": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortName'], '(unknownReceivePortName)')}",
                                                "btsReceivePortId": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortId'], '(unknownReceivePortId)')}"
                                            }
                                        },
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('messageConstructorLogicAppResourceId')]"
                                            }
                                        }
                                    }
                                },
                                "ConstructMessage:_Check_StatusCode": {
                                    "runAfter": {
                                        "ConstructMessage:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "ConstructMessage:Success:_Check_EnvelopeType": {
                                                    "runAfter": {},
                                                    "cases": {
                                                        "ACK": {
                                                            "case": "ack",
                                                            "actions": {
                                                                "ACK:_Set_ResponseMessage_variable": {
                                                                    "runAfter": {},
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "ResponseMessage",
                                                                        "value": "@body('ConstructMessage:_Call_MessageConstructor')"
                                                                    }
                                                                },
                                                                "ACK:_Set_Checkpoint_variable": {
                                                                    "runAfter": {
                                                                        "ACK:_Set_ResponseMessage_variable": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "Checkpoint",
                                                                        "value": "ConstructMessageACK"
                                                                    }
                                                                }
                                                            }
                                                        },
                                                        "NACK": {
                                                            "case": "nack",
                                                            "actions": {
                                                                "NACK:_Set_ResponseMessage_variable": {
                                                                    "runAfter": {},
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "ResponseMessage",
                                                                        "value": "@body('ConstructMessage:_Call_MessageConstructor')"
                                                                    }
                                                                },
                                                                "NACK:_Set_Checkpoint_variable": {
                                                                    "runAfter": {
                                                                        "NACK:_Set_ResponseMessage_variable": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "Checkpoint",
                                                                        "value": "ConstructMessageNACK"
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "default": {
                                                        "actions": {
                                                            "ConstructMessage:UnknownEnvelope:_Compose_NACK_Message": {
                                                                "runAfter": {},
                                                                "type": "Compose",
                                                                "inputs": {
                                                                    "body": [
                                                                        {
                                                                            "$content": {
                                                                                "code": "500",
                                                                                "message": "@concat('Body returned by action ', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' is not an ACK or NACK. Envelope type is: ', coalesce(body('ConstructMessage:_Call_MessageConstructor')?['header']?['properties']?['envelopeType'], '(unknown)'))"
                                                                            },
                                                                            "$contentType": "application/json",
                                                                            "$part": 1,
                                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                                        }
                                                                    ],
                                                                    "header": {
                                                                        "properties": {
                                                                            "createDate": "@utcNow()",
                                                                            "envelopeType": "nack",
                                                                            "messageId": "@guid()",
                                                                            "rootPart": 1,
                                                                            "trackingId": ""
                                                                        },
                                                                        "routing": {
                                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                                        },
                                                                        "routingSlip": {},
                                                                        "state": {}
                                                                    }
                                                                }
                                                            },
                                                            "ConstructMessage:UnknownEnvelope:_Set_ResponseMessage_variable": {
                                                                "runAfter": {
                                                                    "ConstructMessage:UnknownEnvelope:_Compose_NACK_Message": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "ResponseMessage",
                                                                    "value": "@outputs('ConstructMessage:UnknownEnvelope:_Compose_NACK_Message')"
                                                                }
                                                            },
                                                            "ConstructMessage:UnknownEnvelope:_Set_Checkpoint_variable": {
                                                                "runAfter": {
                                                                    "ConstructMessage:UnknownEnvelope:_Set_ResponseMessage_variable": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "Checkpoint",
                                                                    "value": "ConstructMessageNACK"
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "expression": "@body('ConstructMessage:_Call_MessageConstructor')?['header']?['properties']?['envelopeType']",
                                                    "type": "Switch"
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "ConstructMessage:Failure:_Create_NACK_Message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['statusCode'], outputs('ConstructMessage:_Call_MessageConstructor')?['body']?['statusCode'])}",
                                                                    "faultMessage": "@{coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['error']?['message'], outputs('ConstructMessage:_Call_MessageConstructor')?['body']?['message'])}",
                                                                    "faultReason": ""
                                                                },
                                                                "message": "@concat('Action ', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' resulted in an error response.')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": ""
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "ConstructMessage:Failure:_Set_ResponseMessage_variable": {
                                                "runAfter": {
                                                    "ConstructMessage:Failure:_Create_NACK_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ResponseMessage",
                                                    "value": "@outputs('ConstructMessage:Failure:_Create_NACK_Message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "ConstructMessage:_Get_file_content": {
                                    "runAfter": {},
                                    "type": "ApiConnection",
                                    "inputs": {
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['ftpreceive']['connectionId']"
                                            }
                                        },
                                        "method": "get",
                                        "path": "/datasets/default/files/@{encodeURIComponent(encodeURIComponent(triggerBody()?['Id']))}/content",
                                        "queries": {
                                            "inferContentType": true
                                        }
                                    }
                                },
                                "ConstructMessage:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ConstructMessage:_Call_MessageConstructor": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Should_we_process_file": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ProcessFile"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "$connections": {
                        "value": {
                            "ftpreceive": {
                                "connectionId": "[variables('ftpApiConnectionResourceId')]",
                                "connectionName": "[parameters('ftpReceiveApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/ftp')]"
                            },
                            "servicebuspublish": {
                                "connectionId": "[variables('serviceBusTopicPublishApiConnectionResourceId')]",
                                "connectionName": "[parameters('serviceBusTopicPublishApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/servicebus')]"
                            }
                        }
                    },
                    "ftpReceiveFolder": {
                        "value": "[parameters('ftpReceiveFolder')]"
                    },
                    "ftpMaxFileCount": {
                        "value": "[parameters('ftpMaxFileCount')]"
                    },
                    "ftpRecurrenceFrequency": {
                        "value": "[parameters('ftpRecurrenceFrequency')]"
                    },
                    "ftpRecurrenceInterval": {
                        "value": "[parameters('ftpRecurrenceInterval')]"
                    },
                    "fileNameMask": {
                        "value": "[parameters('ftpFileMask')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    },
                    "scenario": {
                        "value": "[parameters('scenario')]"
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "suspendQueueTopicName": {
                        "value": "[parameters('suspendQueueTopicName')]"
                    }
                }
            }
        }
    ]
}
tools\templates\endpoints\ftp\receive\ftpreceiveadapter.logicapp.prod.parameters.json.liquid
 
tools\templates\endpoints\ftp\receive\ftpreceiveadapterftp.apiconnection.dev.parameters.json.liquid
 
tools\templates\endpoints\ftp\receive\ftpreceiveadapterftp.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectorName": {
            "type": "string",
            "metadata": {
                "description": "FTP Server Name"
            }
        },
        "apiConnectorLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this connection is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "serverAddress": {
            "type": "string",
            "metadata": {
                "description": "FTP Server Address"
            }
        },
        "userName": {
            "type": "string",
            "metadata": {
                "description": "User Name for the FTP Server"
            }
        },
        "password": {
            "type": "securestring",
            "metadata": {
                "description": "Password for the FTP Server"
            }
        },
        "isBinaryTransport": {
            "type": "bool",
            "metadata": {
                "description": "Indicates if Binary or ASCII mode should be used"
            }
        },
        "serverPort": {
            "type": "int",
            "defaultValue": 21,
            "metadata": {
                "description": "FTP Port Number (example: 21)"
            }
        },
        "isSSL": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Indicates if SSL needs to be enabled (i.e. FTPS)"
            }
        },
        "disableCertificateValidation": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Indicates if Certificate Validation needs to be disabled"
            }
        },
        "closeConnectionAfterRequestCompletion": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Indicates if the session should be closed every time after request completes. Enable if you hit Max Connections limit."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectorName')]",
            "location": "[parameters('apiConnectorLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/', 'ftp')]"
                },
                "displayName": "Ftp-Receive-Connector",
                "parameterValues": {
                    "serverAddress": "[parameters('serverAddress')]",
                    "userName": "[parameters('userName')]",
                    "password": "[parameters('password')]",
                    "serverPort": "[parameters('serverPort')]",
                    "isSSL": "[parameters('isSSL')]",
                    "isBinaryTransport": "[parameters('isBinaryTransport')]",
                    "disableCertificateValidation": "[parameters('disableCertificateValidation')]",
                    "closeConnectionAfterRequestCompletion": "[parameters('closeConnectionAfterRequestCompletion')]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\endpoints\ftp\receive\ftpreceiveadapterftp.apiconnection.prod.parameters.json.liquid
 
tools\templates\endpoints\ftp\receive\ftpreceiveadapterservicebus.apiconnection.dev.parameters.json.liquid
 
tools\templates\endpoints\ftp\receive\ftpreceiveadapterservicebus.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "serviceBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that contains the Azure Service Bus resource."
            }
        },
        "serviceBusNamespaceName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Namespace this API Connection connects to)."
            }
        },
        "serviceBusPolicyName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Policy this API Connection connects to)."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'servicebus')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "connectionString": "[listKeys(resourceId(parameters('serviceBusResourceGroupName'), 'Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('serviceBusNamespaceName'), parameters('serviceBusPolicyName')), '2017-04-01').primaryConnectionString]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\endpoints\ftp\receive\ftpreceiveadapterservicebus.apiconnection.prod.parameters.json.liquid
 
tools\templates\endpoints\ftp\receive\New-FtpReceiveAdapter-LogicApp.ps1
<#
.SYNOPSIS
Creates an ftp receive adapter for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FtpReceiveAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth" -templateFile ".\ftpreceiveadapter.logicapp.json" -templateParameterFile ".\ftpreceiveadapter.logicapp.dev.parameters.json" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "ftpreceiveadapter.logicapp.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying an ftp receive adapter`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\ftp\send\ftpsendadapter.logicapp.dev.parameters.json.liquid
 
tools\templates\endpoints\ftp\send\ftpsendadapter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "ftpSendApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for FTP Send operations."
            }
        },
        "ftpSendFolder": {
            "defaultValue": "/",
            "type": "string",
            "metadata": {
                "description": "The path where the FTP connector send files."
            }
        },
        "ftpSendFileName": {
            "defaultValue": "%MessageID%-%SourceFileName%",
            "type": "string",
            "metadata": {
                "description": "The name of the file to send (can include macro values e.g. %MessageID% or %SourceFileName%)."
            }
        },
        "scenarioStep": {
            "defaultValue": "ftpSendAdapter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. ftpSendAdapter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "ftpSendApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('ftpSendApiConnectionName'))]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "$connections": {
                            "defaultValue": {},
                            "type": "Object"
                        },
                        "ftpSendFolder": {
                            "type": "String",
                            "description": "The path where the FTP connector send files."
                        },
                        "ftpSendFileName": {
                            "type": "String",
                            "description": "The name of the file to send (can include macro values e.g. %MessageID% or %SourceFileName%))."
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. ftpSendAdapter."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_SendFileName_variable": {
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "SendFileName",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                            "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                            "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_SendToFTP": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SendToFTP"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_SendFileName_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Missing:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "NoBodyContent"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_GetSendFileName": {
                            "actions": {
                                "GetSendFileName:_Set_SendFileName_variable": {
                                    "description": "A full list of supported FileName macros can be found here: https://social.technet.microsoft.com/wiki/contents/articles/8823.biztalk-server-list-of-macros.aspx. At this time we are not supporting the Party macros.",
                                    "type": "SetVariable",
                                    "runAfter": {},
                                    "inputs": {
                                        "name": "SendFileName",
                                        "value": "@{replace(replace(replace(replace(replace(replace(replace(parameters('ftpSendFileName'), '%MessageID%', coalesce(triggerBody()?['header']?['properties']?['messageId'], guid())), '%SourceFileName%', coalesce(triggerBody()?['header']?['properties']?['receivedFileName'], 'myfile.txt')), '%datetime%', utcNow('yyyy-MM-ddThhmmss')), '%datetime_bts2000%', utcNow('yyyyMMddhhmmsss')), '%datetime.tz%', utcNow('yyyy-MM-ddThhmmssK')), '%time%', utcNow('hhmmss')), '%time.tz%', utcNow('hhmmssK'))}"
                                    }
                                },
                                "SendToFTP:_Set_Checkpoint_variable": {
                                    "runAfter": {
                                        "GetSendFileName:_Set_SendFileName_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "Checkpoint",
                                        "value": "GetSendFileName"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "NoBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_SendToFTP": {
                            "actions": {
                                "SendToFTP:_Check_Status_Code": {
                                    "runAfter": {
                                        "SendToFTP:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "SendToFTP:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "SendToFTP"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "SendToFTP:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "SendToFTP:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "SendToFTP:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to send a file using the FTP connector"
                                                        }
                                                    },
                                                    "SendToFTP:Fault:_Create_Fault_Message": {
                                                        "runAfter": {},
                                                        "type": "Compose",
                                                        "inputs": {
                                                            "fault": {
                                                                "faultActor": "@concat(workflow()?['name'], '.', actions('SendToFTP:_Create_File')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                "faultCategory": "Error",
                                                                "faultCode": "@{coalesce(outputs('SendToFTP:_Create_File')?['statusCode'], outputs('SendToFTP:_Create_File')?['body']?['statusCode'], actions('SendToFTP:_Create_File')?['error']?['code'])}",
                                                                "faultMessage": "@{coalesce(outputs('SendToFTP:_Create_File')?['error']?['message'], outputs('SendToFTP:_Create_File')?['body']?['message'], actions('SendToFTP:_Create_File')?['error']?['message'])}",
                                                                "faultReason": "@{actions('SendToFTP:_Create_File')?['status']}"
                                                            }
                                                        }
                                                    },
                                                    "SendToFTP:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {
                                                            "SendToFTP:Fault:_Create_Fault_Message": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('SendToFTP:Fault:_Create_Fault_Message')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "SendToFTP:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('SendToFTP:_Create_File')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('SendToFTP:_Create_File')?['statusCode'], outputs('SendToFTP:_Create_File')?['body']?['statusCode'])}",
                                                                    "faultMessage": "@{coalesce(outputs('SendToFTP:_Create_File')?['error']?['message'], outputs('SendToFTP:_Create_File')?['body']?['message'])}",
                                                                    "faultReason": "@actions('SendToFTP:_Create_File')?['inputs']?['path']"
                                                                }
                                                            }
                                                        },
                                                        "SendToFTP:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "SendToFTP:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to send a file using the FTP connector"
                                                            }
                                                        },
                                                        "SendToFTP:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "SendToFTP:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('SendToFTP:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('SendToFTP:_Create_File')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "SendToFTP:_Create_File": {
                                    "inputs": {
                                        "body": "@variables('BodyContent')",
                                        "headers": {
                                            "ReadFileMetadataFromServer": true
                                        },
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['ftpsend']['connectionId']"
                                            }
                                        },
                                        "method": "post",
                                        "path": "/datasets/default/files",
                                        "queries": {
                                            "folderPath": "@parameters('ftpSendFolder')",
                                            "name": "@variables('SendFileName')",
                                            "queryParametersSingleEncoded": true
                                        }
                                    },
                                    "runAfter": {},
                                    "runtimeConfiguration": {
                                        "contentTransfer": {
                                            "transferMode": "Chunked"
                                        }
                                    },
                                    "type": "ApiConnection"
                                },
                                "SendToFTP:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "SendToFTP:_Create_File": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('SendToFTP:_Create_File')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_GetSendFileName": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetSendFileName"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "$connections": {
                        "value": {
                            "ftpsend": {
                                "connectionId": "[variables('ftpSendApiConnectionResourceId')]",
                                "connectionName": "[parameters('ftpSendApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/ftp')]"
                            }
                        }
                    },
                    "ftpSendFolder": {
                        "value": "[parameters('ftpSendFolder')]"
                    },
                    "ftpSendFileName": {
                        "value": "[parameters('ftpSendFileName')]"
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\endpoints\ftp\send\ftpsendadapter.logicapp.prod.parameters.json.liquid
 
tools\templates\endpoints\ftp\send\New-FtpSendAdapter-ApiConnection.ps1
<#
.SYNOPSIS
Creates an ftp connector for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-FtpSendAdapter-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -templateFile ".\ftpconnection.json" -templateParameterFile ".\ftpconnection.dev.parameters.json" -deploymentName "ftpsendconnection"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying an ftp connector`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\ftp\send\New-FtpSendAdapter-LogicApp.ps1
<#
.SYNOPSIS
Creates an ftp adapter for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-FtpSendAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -templateFile ".\ftpadapter.json" -templateParameterFile ".\ftpadapter.dev.parameters.json" -deploymentName "ftpadapter"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription from Key Vault for the routing slip router Logic App"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying an ftp adapter`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\http\receive\TearDown-105-HttpReceiveAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\http\send\Deploy-105-HttpSendAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\http\send\httpsendadapter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "httpSendAdapter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. httpSendAdapter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. httpSendAdapter."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                            "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                            "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_SendToHttp": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SendToHttp"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Missing:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "NoBodyContent"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_SendToHttp": {
                            "actions": {
                                "SendToHttp:_Check_Status_Code": {
                                    "runAfter": {
                                        "SendToHttp:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "SendToHttp:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "SendToHttp"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "SendToHttp:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "SendToHttp:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "SendToHttp:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to send an HTTP request"
                                                        }
                                                    },
                                                    "SendToHttp:Fault:_Create_Fault_Message": {
                                                        "runAfter": {},
                                                        "type": "Compose",
                                                        "inputs": {
                                                            "fault": {
                                                                "faultActor": "@concat(workflow()?['name'], '.', actions('SendToHttp:_SendHttp')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                "faultCategory": "Error",
                                                                "faultCode": "@{coalesce(outputs('SendToHttp:_SendHttp')?['statusCode'], outputs('SendToHttp:_SendHttp')?['body']?['statusCode'], actions('SendToHttp:_SendHttp')?['error']?['code'])}",
                                                                "faultMessage": "@{coalesce(outputs('SendToHttp:_SendHttp')?['error']?['message'], outputs('SendToHttp:_SendHttp')?['body']?['message'], actions('SendToHttp:_SendHttp')?['error']?['message'])}",
                                                                "faultReason": "@{actions('SendToHttp:_SendHttp')?['status']}"
                                                            }
                                                        }
                                                    },
                                                    "SendToHttp:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {
                                                            "SendToHttp:Fault:_Create_Fault_Message": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('SendToHttp:Fault:_Create_Fault_Message')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "SendToHttp:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('SendToHttp:_SendHttp')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('SendToHttp:_SendHttp')?['statusCode'], outputs('SendToHttp:_SendHttp')?['body']?['statusCode'])}",
                                                                    "faultMessage": "@{coalesce(outputs('SendToHttp:_SendHttp')?['error']?['message'], outputs('SendToHttp:_SendHttp')?['body']?['message'])}",
                                                                    "faultReason": "@actions('SendToHttp:_SendHttp')?['inputs']?['path']"
                                                                }
                                                            }
                                                        },
                                                        "SendToHttp:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "SendToHttp:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to send an HTTP request"
                                                            }
                                                        },
                                                        "SendToHttp:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "SendToHttp:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('SendToHttp:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('SendToHttp:_SendHttp')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "SendToHttp:_SendHttp": {
                                    "inputs": {
                                        "body": "@variables('BodyContent')",
                                        "headers": {
                                            "Content-Type": "@{body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$contentType']}"
                                        },
                                        "method": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['httpMethod'], 'POST')}",
                                        "uri": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['httpUri'], '')}"
                                    },
                                    "runAfter": {},
                                    "type": "Http"
                                },
                                "SendToHttp:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "SendToHttp:_SendHttp": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('SendToHttp:_SendHttp')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\endpoints\http\send\httpsendadapter.logicapp.prod.parameters.json.liquid
 
tools\templates\endpoints\http\send\httpsnedadapter.logicapp.dev.parameters.json.liquid
 
tools\templates\endpoints\http\send\New-HttpSendAdapter-LogicApp.ps1
<#
.SYNOPSIS
Creates a http send adapter for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-HttpSendAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-httpjsonorch-dev-uksouth" -templateFile ".\httpsendadapter.logicapp.json" -templateParameterFile ".\httpsendadapter.logicapp.dev.parameters.json" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "httpsendadapter.logicapp.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying a http send adapter`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\http\send\Remove-HttpSendAdapter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the http send adapter.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-HttpSendAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-httpjsonorch-dev-uksouth-xxxxx" -resourceName "logic-aimhttpsadapter-purchaseorderhttpjsonsend-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

if ($resourceExists) {
    Write-Host "Removing the http send adapter resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

    Write-Host "Removed the http send adapter resource: $resourceName"
}
else {
    Write-Host "The http send adapter resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\http\send\TearDown-105-HttpSendAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\messageconstructor\Deploy-85-MessageConstructor-LogicApp.ps1.liquid
 
tools\templates\endpoints\messageconstructor\messageconstructor.logicapp.dev.parameters.json.liquid
 
tools\templates\endpoints\messageconstructor\messageconstructor.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "string",
            "defaultValue": "[resourceGroup().name]",
            "metadata": {
                "description": "Name of the ResourceGroup that APIM is deployed to (if different from the ResourceGroup that this LogicApp is deployed to)."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "messageConstructor",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. messageConstructor."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. messageConstructor."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {
                                    "properties": {
                                        "$content": {
                                            "type": "string"
                                        },
                                        "$contentTransferEncoding": {
                                            "type": "string"
                                        },
                                        "$contentType": {
                                            "type": "string"
                                        },
                                        "properties": {
                                            "properties": {},
                                            "type": "object"
                                        }
                                    },
                                    "type": "object"
                                }
                            },
                            "description": "We should be receiving a Body message that contains details about the received content, plus properties from the FTP adapter e.g. ReceivedFileName"
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value":  "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{variables('Envelope')?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{body('Routing:_Call_RoutingSlipRouter')?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Merge_Properties": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{variables('Envelope')?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "MergeProperties"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Build_Envelope": {
                            "actions": {
                                "BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@triggerBody()?['$content']",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['properties']?['trackingId']}",
                                            "Content-Encoding": "@{coalesce(triggerBody()?['$contentTransferEncoding'], 'none')}",
                                            "Content-Type": "@{triggerBody()?['$contentType']}"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {
                                                "envelopeType": "@{encodeURIComponent('document')}",
                                                "scenario": "@{encodeURIComponent(triggerBody()?['properties']?['scenario'])}"
                                            },
                                            "template": "/aimmessagingmanager/buildenvelope/{envelopeType}/{scenario}"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "encodeBody": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['encodeBody'], 'true')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "BuildEnvelope:_Check_Status_Code": {
                                    "runAfter": {
                                        "BuildEnvelope:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "BuildEnvelope:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "BuildEnvelope:Success:_Set_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "BuildEnvelope"
                                                    }
                                                },
                                                "BuildEnvelope:Success:_Set_Envelope_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@body('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "BuildEnvelope:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "BuildEnvelope:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "BuildEnvelope:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager BuildEnvelope operation"
                                                        }
                                                    },
                                                    "BuildEnvelope:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "BuildEnvelope:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['statusCode'], outputs('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['body']?['statusCode'], actions('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['error']?['message'], outputs('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['body']?['message'], actions('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "BuildEnvelope:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "BuildEnvelope:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager BuildEnvelope operation"
                                                            }
                                                        },
                                                        "BuildEnvelope:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "BuildEnvelope:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('BuildEnvelope:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@outputs('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['body']?.fault",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "BuildEnvelope:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('BuildEnvelope:_Call_APIM_MessagingManager.BuildEnvelope')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Merge_Properties": {
                            "actions": {
                                "MergeProperties:_Call_APIM_MessagingManager.MergeProperties": {
                                    "runAfter": {
                                        "MergeProperties:_Create_Request_Message": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@outputs('MergeProperties:_Create_Request_Message')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@variables('Envelope')?['header']?['properties']?['trackingId']",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/mergeproperties"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "MergeProperties:_Check_StatusCode": {
                                    "runAfter": {
                                        "MergeProperties:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "MergeProperties:Success:_Copy_Properties_to_Envelope": {
                                                    "runAfter": {},
                                                    "type": "Compose",
                                                    "inputs": "@setProperty(variables('Envelope'), 'header', setProperty(variables('Envelope')?['header'], 'properties', body('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')))"
                                                },
                                                "MergeProperties:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "MergeProperties:Success_Set_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "MergeProperties"
                                                    }
                                                },
                                                "MergeProperties:Success_Set_Envelope_variable": {
                                                    "runAfter": {
                                                        "MergeProperties:Success:_Copy_Properties_to_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@outputs('MergeProperties:Success:_Copy_Properties_to_Envelope')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "MergeProperties:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "MergeProperties:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "MergeProperties:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager MergeProperties operation"
                                                        }
                                                    },
                                                    "MergeProperties:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "MergeProperties:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['statusCode'], outputs('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['body']?['statusCode'], actions('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['error']?['message'], outputs('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['body']?['message'], actions('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "MergeProperties:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "MergeProperties:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager MergeProperties operation"
                                                            }
                                                        },
                                                        "MergeProperties:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "MergeProperties:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('MergeProperties:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@outputs('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['body']?.fault",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "MergeProperties:_Create_Request_Message": {
                                    "runAfter": {},
                                    "type": "Compose",
                                    "inputs": "@createArray(variables('Envelope')?['header']?['properties'], triggerBody()?['properties'])"
                                },
                                "MergeProperties:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "MergeProperties:_Call_APIM_MessagingManager.MergeProperties": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('MergeProperties:_Call_APIM_MessagingManager.MergeProperties')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Build_Envelope": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "BuildEnvelope"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\endpoints\messageconstructor\messageconstructor.logicapp.prod.parameters.json.liquid
 
tools\templates\endpoints\messageconstructor\New-MessageConstructor-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-MessageConstructor-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\messageconstructor.logicapp.json" -templateParameterFile ".\messageconstructor.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "messageconstructor.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName 
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value

Write-Host "Deploying the message constructor Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\messageconstructor\Remove-MessageConstructor-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
./Remove-MessageConstructor-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimmessageconstructor-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\messageconstructor\TearDown-85-MessageConstructor-LogicApp.ps1.liquid
 
tools\templates\intermediaries\contentdemoter\contentdemoter.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\contentdemoter\contentdemoter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "contentPromoter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. contentPromoter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "routingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimroutingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. contentPromoter."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_DemoteMessageProperties": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "DemoteMessageProperties"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_DemoteMessageProperties": {
                            "actions": {
                                "DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('routingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimroutingmanager/demotemessageproperties"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "DemoteMessageProperties:_Check_Status_Code": {
                                    "runAfter": {
                                        "DemoteMessageProperties:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "DemoteMessageProperties:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "DemoteMessageProperties:Success:_Set_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "DemoteMessageProperties"
                                                    }
                                                },
                                                "DemoteMessageProperties:Success:_Set_Envelope_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@body('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "DemoteMessageProperties:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "DemoteMessageProperties:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "DemoteMessageProperties:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager DemoteMessageProperties operation"
                                                        }
                                                    },
                                                    "DemoteMessageProperties:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "DemoteMessageProperties:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['statusCode'], outputs('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['body']?['statusCode'], actions('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['error']?['message'], outputs('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['body']?['message'], actions('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "DemoteMessageProperties:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "DemoteMessageProperties:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager DemoteMessageProperties operation"
                                                            }
                                                        },
                                                        "DemoteMessageProperties:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "DemoteMessageProperties:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('DemoteMessageProperties:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "DemoteMessageProperties:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('DemoteMessageProperties:_Call_APIM_RoutingManager.DemoteMessageProperties')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\contentdemoter\contentdemoter.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\contentdemoter\Deploy-90-ContentDemoter-LogicApp.ps1.liquid
 
tools\templates\intermediaries\contentdemoter\New-ContentDemoter-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-ContentDemoter-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\contentdemoter.logicapp.json" -templateParameterFile ".\contentdemoter.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "contentdemoter.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName    
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the content demoter Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\contentdemoter\Remove-ContentDemoter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-ContentDemoter-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimcontentdemoter-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\contentdemoter\TearDown-90-ContentDemoter-LogicApp.ps1.liquid
 
tools\templates\intermediaries\contentpromoter\contentpromoter.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\contentpromoter\contentpromoter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "contentPromoter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. contentPromoter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "routingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimroutingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. contentPromoter."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_ResolveRoutingProperties": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ResolveRoutingProperties"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_ResolveRoutingProperties": {
                            "actions": {
                                "ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('routingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimroutingmanager/resolveroutingproperties"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "ResolveRoutingProperties:_Check_Status_Code": {
                                    "runAfter": {
                                        "ResolveRoutingProperties:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "ResolveRoutingProperties:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "ResolveRoutingProperties:Success:_Set_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "ResolveRoutingProperties"
                                                    }
                                                },
                                                "ResolveRoutingProperties:Success:_Set_Envelope_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@body('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "ResolveRoutingProperties:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "ResolveRoutingProperties:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "ResolveRoutingProperties:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager ResolveRoutingProperties operation"
                                                        }
                                                    },
                                                    "ResolveRoutingProperties:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "ResolveRoutingProperties:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['statusCode'], outputs('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['body']?['statusCode'], actions('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['error']?['message'], outputs('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['body']?['message'], actions('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "ResolveRoutingProperties:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "ResolveRoutingProperties:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager ResolveRoutingProperties operation"
                                                            }
                                                        },
                                                        "ResolveRoutingProperties:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "ResolveRoutingProperties:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('ResolveRoutingProperties:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "ResolveRoutingProperties:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('ResolveRoutingProperties:_Call_APIM_RoutingManager.ResolveRoutingProperties')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\contentpromoter\contentpromoter.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\contentpromoter\Deploy-90-ContentPromoter-LogicApp.ps1.liquid
 
tools\templates\intermediaries\contentpromoter\New-ContentPromoter-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-ContentPromoter-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\contentpromoter.logicapp.json" -templateParameterFile ".\contentpromoter.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "contentpromoter.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName    
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the content promoter Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\contentpromoter\Remove-ContentPromoter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-ContentPromoter-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimcontentpromoter-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\contentpromoter\TearDown-90-ContentPromoter-LogicApp.ps1.liquid
 
tools\templates\intermediaries\flatfilemessageprocessor\Deploy-90-FlatFileMessageProcessor-LogicApp.ps1.liquid
 
tools\templates\intermediaries\flatfilemessageprocessor\flatfilemessageprocessor.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\flatfilemessageprocessor\flatfilemessageprocessor.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "String",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "flatFileDecoder",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. flatFileDecoder."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. flatFileDecoder."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow().Name} (@{workflow().run.name}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_StatusCode_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow().name, '.', actions('Routing:_Call_RoutingSlipRouter').name, ' (', workflow().run.name, ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?.statusCode, outputs('Routing:_Call_RoutingSlipRouter')?.body?.statusCode, actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?.error?.message, outputs('Routing:_Call_RoutingSlipRouter')?.body?.message, actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Decode_FlatFile": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "DecodeFlatFile"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow().name, '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep').name, ' (', workflow().run.name, ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?.statusCode, outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?.body?.statusCode, actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?.error?.message, outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?.body?.message, actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodySchemaName": {
                            "actions": {
                                "CheckBodySchemaName:_Is_BodySchemaName_blank": {
                                    "actions": {
                                        "CheckBodySchemaName:Failure:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}): No BodySchemaName is set in the configuration entry for this step."
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "CheckBodySchemaName:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodySchemaName"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['bodySchemaName'], '')}",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Failure:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}): No Root Body content can be found in the supplied Envelope"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodySchemaName": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodySchemaName"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Decode_BodyContent": {
                            "actions": {
                                "DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/decodebodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "DecodeBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "DecodeBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "DecodeBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "DecodeBodyContent"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "DecodeBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "DecodeBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "DecodeBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}) trying to call the MessageManager DecodeBodyContent operation"
                                                        }
                                                    },
                                                    "DecodeBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "DecodeBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow().name, '.', actions('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent').name, ' (', workflow().run.name, ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')?.statusCode, outputs('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')?.body?.statusCode, actions('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')?.error?.message, outputs('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')?.body?.message, actions('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "DecodeBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "DecodeBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}) trying to call the MessageManager DecodeBodyContent operation"
                                                            }
                                                        },
                                                        "DecodeBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "DecodeBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('DecodeBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "DecodeBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Decode_FlatFile": {
                            "actions": {
                                "DecodeFlatFile:Failure:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Decode_FlatFile": [
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 500
                                    }
                                },
                                "DecodeFlatFile:Success:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Decode_FlatFile": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 200
                                    }
                                },
                                "DecodeFlatFile:_Check_StatusCode": {
                                    "runAfter": {
                                        "DecodeFlatFile:Failure:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ],
                                        "DecodeFlatFile:Success:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "DecodeFlatFile:Success:_Add_new_Root_Body_Part_to_Envelope": {
                                                    "runAfter": {
                                                        "DecodeFlatFile:Success:_Remove_existing_Root_Body_Part_from_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": "@setProperty(variables('Envelope'), 'body', union(outputs('DecodeFlatFile:Success:_Remove_existing_Root_Body_Part_from_Envelope')?['body'], array(outputs('DecodeFlatFile:Success:_Create_new_Body_Part'))))"
                                                },
                                                "DecodeFlatFile:Success:_Create_new_Body_Part": {
                                                    "runAfter": {},
                                                    "type": "Compose",
                                                    "inputs": {
                                                        "$content": "@base64(body('Decode_FlatFile'))",
                                                        "$contentTransferEncoding": "base64",
                                                        "$contentType": "text/xml",
                                                        "$part": "@variables('Envelope')?['header']?['properties']?['rootPart']",
                                                        "$partType": "http://schemas.myorg.com/part'@{variables('Envelope')?['header']?['properties']?['rootPart']}#root"
                                                    }
                                                },
                                                "DecodeFlatFile:Success:_Remove_existing_Root_Body_Part_from_Envelope": {
                                                    "runAfter": {
                                                        "DecodeFlatFile:Success:_Create_new_Body_Part": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Query",
                                                    "inputs": {
                                                        "from": "@variables('Envelope')?['body']",
                                                        "where": "@not(equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart']))"
                                                    }
                                                },
                                                "DecodeFlatFile:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "DecodeFlatFile:Success:_Update_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "DecodeFlatFile"
                                                    }
                                                },
                                                "DecodeFlatFile:Success:_Update_Envelope_variable": {
                                                    "runAfter": {
                                                        "DecodeFlatFile:Success:_Add_new_Root_Body_Part_to_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@outputs('DecodeFlatFile:Success:_Add_new_Root_Body_Part_to_Envelope')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "DecodeFlatFile:Failure:_Create_Fault_message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "fault": {
                                                        "faultActor": "@concat(workflow().name, '.', actions('Decode_FlatFile').name, ' (', workflow().run.name, ')')",
                                                        "faultCategory": "Error",
                                                        "faultCode": "@{coalesce(outputs('Decode_FlatFile')?.statusCode, outputs('Decode_FlatFile')?.body?.statusCode, actions('Decode_FlatFile')?['error']?['code'])}",
                                                        "faultMessage": "@{coalesce(outputs('Decode_FlatFile')?.error?.message, outputs('Decode_FlatFile')?.body?.message, actions('Decode_FlatFile')?['error']?['message'])}",
                                                        "faultReason": "@{actions('Decode_FlatFile')?['status']}"
                                                    }
                                                }
                                            },
                                            "DecodeFlatFile:Failure:_Set_ErrorMessage_variable": {
                                                "runAfter": {
                                                    "DecodeFlatFile:Failure:_Set_FaultMessage_variable": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow().Name} (@{workflow().run.name}) trying to decode FlatFile content"
                                                }
                                            },
                                            "DecodeFlatFile:Failure:_Set_FaultMessage_variable": {
                                                "runAfter": {
                                                    "DecodeFlatFile:Failure:_Create_Fault_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "FaultMessage",
                                                    "value": "@outputs('DecodeFlatFile:Failure:_Create_Fault_message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Decode_FlatFile": {
                                    "runAfter": {},
                                    "type": "FlatFileDecoding",
                                    "inputs": {
                                        "content": "@{body('DecodeBodyContent:_Call_APIM_MessageManager.DecodeBodyContent')}",
                                        "integrationAccount": {
                                            "schema": {
                                                "name": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['bodySchemaName'], '')}"
                                            }
                                        }
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Decode_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "DecodeBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\endpoints\http\receive\Remove-HttpReceiveAdapter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the http receive adapter.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-HttpReceiveAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-httpjsonorch-dev-uksouth-xxxxx" -resourceName "logic-aimhttpradapter-purchaseorderhttpjsonreceive-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

if ($resourceExists) {
    Write-Host "Removing the http receive adapter resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

    Write-Host "Removed the http receive adapter resource: $resourceName"
}
else {
    Write-Host "The http receive adapter resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\http\receive\New-HttpReceiveAdapter-LogicApp.ps1
<#
.SYNOPSIS
Creates a http receive adapter for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-HttpReceiveAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-httpjsonorch-dev-uksouth" -templateFile ".\httpreceiveadapter.logicapp.json" -templateParameterFile ".\httpreceiveadapter.logicapp.dev.parameters.json" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "httpreceiveadapter.logicapp.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying a http receive adapter`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\http\receive\httpreceiveadapter.logicapp.prod.parameters.json.liquid
 
tools\templates\endpoints\http\receive\httpreceiveadapter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicApStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "systemApplicationResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that SystemApplication artifacts are deployed to (e.g. ServiceBus or MessageConstructor LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "string",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "messageConstructorLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle File Message Construction and Sending."
            }
        },
        "messageResponseHandlerLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle retrieving the response in a two-way messaging scenario."
            }
        },
        "messageSuspendProcessorLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle suspending of messages."
            }
        },
        "suspendQueueTopicName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic that suspended messages are sent to."
            }
        },
        "responseTopicName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic where response messages are found for two-way operations."
            }
        },
        "responseSubscriptionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Subscription used to get response messages for two-way operations."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },

        "scenario": {
            "type": "string",
            "metadata": {
                "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
            }
        },
        "scenarioStep": {
            "defaultValue": "httpReceiveAdapter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. httpReceiveAdapter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "messageConstructorLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageConstructorLogicAppName'))]",
        "messageResponseHandlerLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageResponseHandlerLogicAppName'))]",
        "messageSuspendProcessorLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageSuspendProcessorLogicAppName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicApStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        },
                        "scenario": {
                            "type": "String",
                            "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. httpReceiveAdapter."
                        },
                        "clearCache": {
                            "defaultValue": true,
                            "type": "Bool",
                            "description": "Indicates if we should clear APIM cache before retrieved config items e.g. configurationEntries or routingSlips."
                        },
                        "suspendQueueTopicName": {
                            "type": "String",
                            "description": "Name of the ServiceBus Topic that suspended messages are sent to."
                        },
                        "responseTopicName": {
                            "type": "String",
                            "description": "Name of the ServiceBus Topic where response messages are found for two-way operations."
                        },
                        "responseSubscriptionName": {
                            "type": "String",
                            "description": "Name of the ServiceBus Subscription used to get response messages for two-way operations."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_TwoWayResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "TwoWayResponseMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_TwoWayResponseContent_variable": {
                            "runAfter": {
                                "Initialize_TwoWayResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "TwoWayResponseContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Respond:_Were_we_successful": {
                            "actions": {
                                "Respond:_Is_this_a_TwoWay_adapter": {
                                    "actions": {
                                        "Respond:TwoWay:_Call_Response_Handler": {
                                            "runAfter": {},
                                            "type": "Workflow",
                                            "inputs": {
                                                "body": {
                                                    "responseTopicName": "@{parameters('responseTopicName')}",
                                                    "responseSubscriptionName": "@{parameters('responseSubscriptionName')}",
                                                    "correlationId": "@variables('ResponseMessage')?['header']?['properties']?['correlationId']",
                                                    "responseTimeoutInMinutes": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['responseTimeoutInMinutes'], 3)"
                                                },
                                                "headers": {
                                                    "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                    "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                                },
                                                "host": {
                                                    "triggerName": "manual",
                                                    "workflow": {
                                                        "id": "[variables('messageResponseHandlerLogicAppResourceId')]"
                                                    }
                                                }
                                            }
                                        },
                                        "Respond:TwoWay:_Check_StatusCode": {
                                            "runAfter": {
                                                "Respond:TwoWay:_Set_StatusCode_variable": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "cases": {
                                                "Success": {
                                                    "case": 200,
                                                    "actions": {
                                                        "Respond:TwoWay:Success:_Set_TwoWayResponseMessage_variable": {
                                                            "runAfter": {},
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "TwoWayResponseMessage",
                                                                "value": "@body('Respond:TwoWay:_Call_Response_Handler')"
                                                            }
                                                        },
                                                        "Respond:TwoWay:Success:_Check_TwoWayResponse_ContentType": {
                                                            "runAfter": {
                                                                "Respond:TwoWay:Success:_Set_TwoWayResponseMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "If",
                                                            "actions": {
                                                                "Respond:TwoWay:Success:_Get_Response_BodyContent": {
                                                                    "runAfter": {},
                                                                    "type": "ApiManagement",
                                                                    "inputs": {
                                                                        "api": {
                                                                            "id": "[variables('messagingManagerApiResourceId')]"
                                                                        },
                                                                        "body": "@if(equals(variables('TwoWayResponseMessage')?['$content-encoding'], 'Base64'), json(decodeBase64(variables('TwoWayResponseMessage')?['$content'])), variables('TwoWayResponseMessage')?['$content'])",
                                                                        "headers": {
                                                                            "Aim-Tracking-Id": "@{variables('ResponseMessage')?['header']?['properties']?['trackingId']}",
                                                                            "Content-Type": "application/json"
                                                                        },
                                                                        "method": "post",
                                                                        "pathTemplate": {
                                                                            "parameters": {},
                                                                            "template": "/aimmessagingmanager/getbodycontent"
                                                                        },
                                                                        "queries": {
                                                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                                                        },
                                                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                                                    }
                                                                },
                                                                "Respond:TwoWay:Success:GetBodyContent:_Check_Status_Code": {
                                                                    "runAfter": {
                                                                        "Respond:TwoWay:Success:GetBodyContent:_Set_StatusCode_variable": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "cases": {
                                                                        "Success": {
                                                                            "case": 200,
                                                                            "actions": {
                                                                                "Respond:TwoWay:Success:GetBodyContent:_Set_TwoWayResponseContent_variable": {
                                                                                    "runAfter": {},
                                                                                    "type": "SetVariable",
                                                                                    "inputs": {
                                                                                        "name": "TwoWayResponseContent",
                                                                                        "value": "@decodeBase64(body('Respond:TwoWay:Success:_Get_Response_BodyContent')?['$content'])"
                                                                                    }
                                                                                },
                                                                                "Respond:TwoWay:Success:GetBodyContent:Success:_Send_Response": {
                                                                                    "inputs": {
                                                                                        "body": "@variables('TwoWayResponseContent')",
                                                                                        "statusCode": 200,
                                                                                        "headers": {
                                                                                            "Content-Type": "@body('Respond:TwoWay:Success:_Get_Response_BodyContent')?['$contentType']"
                                                                                        }
                                                                                    },
                                                                                    "kind": "Http",
                                                                                    "runAfter": {
                                                                                        "Respond:TwoWay:Success:GetBodyContent:_Set_TwoWayResponseContent_variable": [
                                                                                            "Succeeded"
                                                                                        ]
                                                                                    },
                                                                                    "type": "Response"
                                                                                }
                                                                            }
                                                                        }
                                                                    },
                                                                    "default": {
                                                                        "actions": {
                                                                            "Respond:TwoWay:Success:GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                                                "actions": {
                                                                                    "Respond:TwoWay:Success:GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                                                        "runAfter": {
                                                                                            "Respond:TwoWay:Success:GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                                                "Succeeded"
                                                                                            ]
                                                                                        },
                                                                                        "type": "SetVariable",
                                                                                        "inputs": {
                                                                                            "name": "ErrorMessage",
                                                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                                                        }
                                                                                    },
                                                                                    "Respond:TwoWay:Success:GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                                                        "runAfter": {},
                                                                                        "type": "SetVariable",
                                                                                        "inputs": {
                                                                                            "name": "FaultMessage",
                                                                                            "value": "@body('Respond:TwoWay:Success:_Get_Response_BodyContent')"
                                                                                        }
                                                                                    }
                                                                                },
                                                                                "runAfter": {},
                                                                                "else": {
                                                                                    "actions": {
                                                                                        "Respond:TwoWay:Success:GetBodyContent:NoFault:_Create_Fault_Message": {
                                                                                            "runAfter": {},
                                                                                            "type": "Compose",
                                                                                            "inputs": {
                                                                                                "fault": {
                                                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Respond:TwoWay:Success:_Get_Response_BodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                                                    "faultCategory": "Error",
                                                                                                    "faultCode": "@{coalesce(outputs('Respond:TwoWay:Success:_Get_Response_BodyContent')?['statusCode'], outputs('Respond:TwoWay:Success:_Get_Response_BodyContent')?['body']?['statusCode'], actions('Respond:TwoWay:Success:_Get_Response_BodyContent')?['error']?['code'])}",
                                                                                                    "faultMessage": "@{coalesce(outputs('Respond:TwoWay:Success:_Get_Response_BodyContent')?['error']?['message'], outputs('Respond:TwoWay:Success:_Get_Response_BodyContent')?['body']?['message'], actions('Respond:TwoWay:Success:_Get_Response_BodyContent')?['error']?['message'])}",
                                                                                                    "faultReason": "@{actions('Respond:TwoWay:Success:_Get_Response_BodyContent')?['status']}"
                                                                                                }
                                                                                            }
                                                                                        },
                                                                                        "Respond:TwoWay:Success:GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                                                            "runAfter": {
                                                                                                "Respond:TwoWay:Success:GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                                                    "Succeeded"
                                                                                                ]
                                                                                            },
                                                                                            "type": "SetVariable",
                                                                                            "inputs": {
                                                                                                "name": "ErrorMessage",
                                                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                                                            }
                                                                                        },
                                                                                        "Respond:TwoWay:Success:GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                                                            "runAfter": {
                                                                                                "Respond:TwoWay:Success:GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                                                    "Succeeded"
                                                                                                ]
                                                                                            },
                                                                                            "type": "SetVariable",
                                                                                            "inputs": {
                                                                                                "name": "FaultMessage",
                                                                                                "value": "@outputs('Respond:TwoWay:Success:GetBodyContent:NoFault:_Create_Fault_Message')"
                                                                                            }
                                                                                        }
                                                                                    }
                                                                                },
                                                                                "expression": {
                                                                                    "and": [
                                                                                        {
                                                                                            "not": {
                                                                                                "equals": [
                                                                                                    "@body('Respond:TwoWay:Success:_Get_Response_BodyContent')?['fault']",
                                                                                                    null
                                                                                                ]
                                                                                            }
                                                                                        }
                                                                                    ]
                                                                                },
                                                                                "type": "If"
                                                                            },
                                                                            "Respond:TwoWay:Success:GetBodyContent:Failure:_Build_NACK_message": {
                                                                                "runAfter": {
                                                                                    "Respond:TwoWay:Success:GetBodyContent:Failure:_Do_we_have_a_Fault_Message": [
                                                                                        "Succeeded"
                                                                                    ]
                                                                                },
                                                                                "type": "Compose",
                                                                                "inputs": {
                                                                                    "body": [
                                                                                        {
                                                                                            "$content": {
                                                                                                "code": "500",
                                                                                                "message": "@variables('ErrorMessage')",
                                                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                                                "fault": "@variables('FaultMessage')"
                                                                                            },
                                                                                            "$contentType": "application/json",
                                                                                            "$part": 1,
                                                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                                                        }
                                                                                    ],
                                                                                    "header": {
                                                                                        "properties": {
                                                                                            "createDate": "@utcNow()",
                                                                                            "envelopeType": "nack",
                                                                                            "messageId": "@guid()",
                                                                                            "rootPart": 1,
                                                                                            "trackingId": "@body('Respond:TwoWay:_Call_Response_Handler')?['header']?['properties']?['trackingId']"
                                                                                        },
                                                                                        "routing": {
                                                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                                                        },
                                                                                        "routingSlip": {},
                                                                                        "state": {}
                                                                                    }
                                                                                }
                                                                            },
                                                                            "Respond:TwoWay:Success:GetBodyContent:Failure:_Send_to_SuspendQueue": {
                                                                                "runAfter": {
                                                                                    "Respond:TwoWay:Success:GetBodyContent:Failure:_Build_NACK_message": [
                                                                                        "Succeeded",
                                                                                        "Failed",
                                                                                        "TimedOut"
                                                                                    ]
                                                                                },
                                                                                "type": "Workflow",
                                                                                "inputs": {
                                                                                    "body": {
                                                                                        "nackMessage": "@outputs('Respond:TwoWay:Success:GetBodyContent:Failure:_Build_NACK_message')",
                                                                                        "originalMessage": "@body('Respond:TwoWay:_Call_Response_Handler')",
                                                                                        "suspendQueueTopicName": "@{parameters('suspendQueueTopicName')}",
                                                                                        "failedMessageRouting": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['failedMessageRouting'], false)",
                                                                                        "scenario": "@{parameters('scenario')}"
                                                                                    },
                                                                                    "headers": {
                                                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                                                                    },
                                                                                    "host": {
                                                                                        "triggerName": "manual",
                                                                                        "workflow": {
                                                                                            "id": "[variables('messageSuspendProcessorLogicAppResourceId')]"
                                                                                        }
                                                                                    }
                                                                                }
                                                                            },
                                                                            "Respond:TwoWay:Success:GetBodyContent:Failure:_Send_Response": {
                                                                                "inputs": {
                                                                                    "body": "@variables('FaultMessage')",
                                                                                    "statusCode": 500,
                                                                                    "headers": {
                                                                                        "Content-Type": "application/json"
                                                                                    }
                                                                                },
                                                                                "kind": "Http",
                                                                                "runAfter": {
                                                                                    "Respond:TwoWay:Success:GetBodyContent:Failure:_Send_to_SuspendQueue": [
                                                                                        "Succeeded",
                                                                                        "Failed",
                                                                                        "TimedOut"
                                                                                    ]
                                                                                },
                                                                                "type": "Response"
                                                                            }
                                                                        }
                                                                    },
                                                                    "expression": "@variables('StatusCode')",
                                                                    "type": "Switch"
                                                                },
                                                                "Respond:TwoWay:Success:GetBodyContent:_Set_StatusCode_variable": {
                                                                    "runAfter": {
                                                                        "Respond:TwoWay:Success:_Get_Response_BodyContent": [
                                                                            "Succeeded",
                                                                            "Failed",
                                                                            "Skipped",
                                                                            "TimedOut"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "StatusCode",
                                                                        "value": "@coalesce(outputs('Respond:TwoWay:Success:_Get_Response_BodyContent')['statusCode'], 500)"
                                                                    }
                                                                }
                                                            },
                                                            "else": {
                                                                "actions": {
                                                                    "Respond:TwoWay:Success:UnknownContentType:_Send_Response": {
                                                                        "inputs": {
                                                                            "body": "@if(equals(variables('TwoWayResponseMessage')?['$content-encoding'], 'Base64'), json(decodeBase64(variables('TwoWayResponseMessage')?['$content'])), variables('TwoWayResponseMessage')?['$content'])",
                                                                            "statusCode": 200,
                                                                            "headers": {
                                                                                "Content-Type": "@variables('TwoWayResponseMessage')?['$content-type']"
                                                                            }
                                                                        },
                                                                        "kind": "Http",
                                                                        "runAfter": {},
                                                                        "type": "Response"
                                                                    }
                                                                }
                                                            },
                                                            "expression": {
                                                                "or": [
                                                                    {
                                                                        "equals": [
                                                                            "@variables('TwoWayResponseMessage')?['$content-type']",
                                                                            "text/json"
                                                                        ]
                                                                    },
                                                                    {
                                                                        "equals": [
                                                                            "@variables('TwoWayResponseMessage')?['$content-type']",
                                                                            "application/json"
                                                                        ]
                                                                    }
                                                                ]
                                                            }
                                                        }
                                                    }   
                                                }
                                            },
                                            "default": {
                                                "actions": {
                                                    "Respond:TwoWay:Failure:_Create_Fault": {
                                                        "runAfter": {},
                                                        "type": "Compose",
                                                        "inputs": {
                                                            "fault": {
                                                                "faultActor": "@concat(workflow()?['name'], '.', actions('Respond:TwoWay:_Call_Response_Handler')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                "faultCategory": "Error",
                                                                "faultCode": "@{outputs('Respond:TwoWay:_Call_Response_Handler')?['statusCode']}",
                                                                "faultMessage": "An error occurred whilst trying to get the response message for a two-way scenario.",
                                                                "faultReason": "@{coalesce(body('Respond:TwoWay:_Call_Response_Handler')?['fault']?['faultMessage'], body('Respond:TwoWay:_Call_Response_Handler')?['error']?['message'])}"
                                                            }
                                                        }
                                                    },
                                                    "Respond:TwoWay:Failure:_Set_FaultMessage_variable": {
                                                        "runAfter": {
                                                            "Respond:TwoWay:Failure:_Create_Fault": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@outputs('Respond:TwoWay:Failure:_Create_Fault')"
                                                        }
                                                    },
                                                    "Respond:TwoWay:Failure:_Create_NACK_Message": {
                                                        "runAfter": {
                                                            "Respond:TwoWay:Failure:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "Compose",
                                                        "inputs": {
                                                            "body": [
                                                                {
                                                                    "$content": {
                                                                        "code": "500",
                                                                        "fault": "@variables('FaultMessage')",
                                                                        "message": "Action @{actions('Respond:TwoWay:_Call_Response_Handler')?['name']} resulted in an error response."
                                                                    },
                                                                    "$contentType": "application/json",
                                                                    "$part": 1,
                                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                                }
                                                            ],
                                                            "header": {
                                                                "properties": {
                                                                    "createDate": "@utcNow()",
                                                                    "envelopeType": "nack",
                                                                    "messageId": "@guid()",
                                                                    "rootPart": 1,
                                                                    "trackingId": "@body('Respond:TwoWay:_Call_Response_Handler')?['header']?['properties']?['trackingId']"
                                                                },
                                                                "routing": {
                                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                                },
                                                                "routingSlip": {},
                                                                "state": {}
                                                            }
                                                        }
                                                    },
                                                    "Respond:TwoWay:Failure:_Send_to_SuspendQueue": {
                                                        "runAfter": {
                                                            "Respond:TwoWay:Failure:_Create_NACK_Message": [
                                                                "Succeeded",
                                                                "Failed",
                                                                "TimedOut"
                                                            ]
                                                        },
                                                        "type": "Workflow",
                                                        "inputs": {
                                                            "body": {
                                                                "nackMessage": "@outputs('Respond:TwoWay:Failure:_Create_NACK_Message')",
                                                                "originalMessage": "@variables('ResponseMessage')",
                                                                "suspendQueueTopicName": "@{parameters('suspendQueueTopicName')}",
                                                                "failedMessageRouting": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['failedMessageRouting'], false)",
                                                                "scenario": "@{parameters('scenario')}"
                                                            },
                                                            "headers": {
                                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                                            },
                                                            "host": {
                                                                "triggerName": "manual",
                                                                "workflow": {
                                                                    "id": "[variables('messageSuspendProcessorLogicAppResourceId')]"
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "Respond:TwoWay:Failure:_Send_Fault_Response": {
                                                        "inputs": {
                                                            "body": "@variables('FaultMessage')",
                                                            "statusCode": "@coalesce(outputs('Respond:TwoWay:_Call_Response_Handler')?['statusCode'], 500)",
                                                            "headers": {
                                                                "Content-Type": "application/json"
                                                            }
                                                        },
                                                        "kind": "Http",
                                                        "runAfter": {
                                                            "Respond:TwoWay:Failure:_Send_to_SuspendQueue": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "Response"
                                                    }
                                                }
                                            },
                                            "expression": "@variables('StatusCode')",
                                            "type": "Switch"
                                        },
                                        "Respond:TwoWay:_Set_StatusCode_variable": {
                                            "runAfter": {
                                                "Respond:TwoWay:_Call_Response_Handler": [
                                                    "Succeeded",
                                                    "Failed",
                                                    "Skipped",
                                                    "TimedOut"
                                                ]
                                            },
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "StatusCode",
                                                "value": "@coalesce(outputs('Respond:TwoWay:_Call_Response_Handler')?['statusCode'], 500)"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "Respond:OneWay:_Send_Accepted_Response": {
                                                "inputs": {
                                                    "statusCode": 202,
                                                    "headers": {
                                                        "Content-Type": "application/json"
                                                    }
                                                },
                                                "kind": "Http",
                                                "runAfter": {},
                                                "type": "Response"
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['isTwoWay'], false)",
                                                    true
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "if"
                                }
                            },
                            "runAfter": {
                                "Step:_Construct Message": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Do_we_have_a_NACK": {
                                        "actions": {},
                                        "runAfter": {},
                                        "else": {
                                            "actions": {
                                                "Failure:_Build_NACK_message": {
                                                    "runAfter": {},
                                                    "type": "Compose",
                                                    "inputs": {
                                                        "body": [
                                                            {
                                                                "$content": {
                                                                    "code": "500",
                                                                    "message": "@variables('ErrorMessage')",
                                                                    "lastCheckpoint": "@variables('Checkpoint')",
                                                                    "fault": "@variables('FaultMessage')"
                                                                },
                                                                "$contentType": "application/json",
                                                                "$part": 1,
                                                                "$partType": "http://schemas.microsoft.com/aim#nack"
                                                            }
                                                        ],
                                                        "header": {
                                                            "properties": {
                                                                "createDate": "@utcNow()",
                                                                "envelopeType": "nack",
                                                                "messageId": "@guid()",
                                                                "rootPart": 1,
                                                                "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                            },
                                                            "routing": {
                                                                "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                            },
                                                            "routingSlip": {},
                                                            "state": {}
                                                        }
                                                    }
                                                },
                                                "Failure:_Set_ResponseMessage_variable": {
                                                    "runAfter": {
                                                        "Failure:_Build_NACK_message": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "ResponseMessage",
                                                        "value": "@outputs('Failure:_Build_NACK_message')"
                                                    }
                                                }
                                            }
                                        },
                                        "expression": {
                                            "and": [
                                                {
                                                    "equals": [
                                                        "@{coalesce(variables('ResponseMessage')?['header']?['properties']?['envelopeType'], '(unknown)')}",
                                                        "nack"
                                                    ]
                                                }
                                            ]
                                        },
                                        "type": "If"
                                    },
                                    "Failure:_Send_NACK_to_SuspendQueue": {
                                        "runAfter": {
                                            "Failure:_Do_we_have_a_NACK": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Workflow",
                                        "inputs": {
                                            "body": {
                                                "nackMessage": "@variables('ResponseMessage')",
                                                "originalMessage": "@triggerBody()",
                                                "suspendQueueTopicName": "@{parameters('suspendQueueTopicName')}",
                                                "failedMessageRouting": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['failedMessageRouting'], false)",
                                                "scenario": "@{parameters('scenario')}"
                                            },
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                            },
                                            "host": {
                                                "triggerName": "manual",
                                                "workflow": {
                                                    "id": "[variables('messageSuspendProcessorLogicAppResourceId')]"
                                                }
                                            }
                                        }
                                    },
                                    "Failure:_Send_Fault_Response": {
                                        "inputs": {
                                            "body": {
                                                "fault": {
                                                    "faultActor": "@{workflow()['name']} (@{workflow()?['run']?['name']})",
                                                    "faultCategory": "Error",
                                                    "faultCode": "500",
                                                    "faultMessage": "@variables('ErrorMessage')",
                                                    "faultReason": ""
                                                }
                                            },
                                            "headers": {
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 500
                                        },
                                        "kind": "Http",
                                        "runAfter": {
                                            "Failure:_Send_NACK_to_SuspendQueue": [
                                                "Succeeded",
                                                "Failed",
                                                "Skipped",
                                                "TimedOut"
                                            ]
                                        },
                                        "type": "Response"
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "IgnoreFile"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ConstructMessageACK"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(parameters('scenario'))}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@parameters('clearCache')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_TwoWayResponseContent_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Validate_Configuration": {
                            "actions": {
                                "ValidateConfiguration:_Have_Valid_Properties": {
                                    "actions": {
                                        "ValidateConfiguration:Success:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "ValidateConfiguration"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "ValidateConfiguration:Failure:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): property btsReceivePortName is not set in configuration"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortName'], '')",
                                                        ""
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Construct Message": {
                            "actions": {
                                "ConstructMessage:_Call_MessageConstructor": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": {
                                            "$content": "@triggerBody()",
                                            "$contentTransferEncoding": "none",
                                            "$contentType": "@triggerOutputs()?['headers']?['Content-Type']",
                                            "properties": {
                                                "scenario": "@{parameters('scenario')}",
                                                "btsReceivePortName": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortName'], '(unknownReceivePortName)')}",
                                                "btsReceivePortId": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['btsReceivePortId'], '(unknownReceivePortId)')}"
                                            }
                                        },
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('messageConstructorLogicAppResourceId')]"
                                            }
                                        }
                                    }
                                },
                                "ConstructMessage:_Check_StatusCode": {
                                    "runAfter": {
                                        "ConstructMessage:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "ConstructMessage:Success:_Check_EnvelopeType": {
                                                    "runAfter": {},
                                                    "cases": {
                                                        "ACK": {
                                                            "case": "ack",
                                                            "actions": {
                                                                "ACK:_Set_ResponseMessage_variable": {
                                                                    "runAfter": {},
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "ResponseMessage",
                                                                        "value": "@body('ConstructMessage:_Call_MessageConstructor')"
                                                                    }
                                                                },
                                                                "ACK:_Set_Checkpoint_variable": {
                                                                    "runAfter": {
                                                                        "ACK:_Set_ResponseMessage_variable": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "Checkpoint",
                                                                        "value": "ConstructMessageACK"
                                                                    }
                                                                }
                                                            }
                                                        },
                                                        "NACK": {
                                                            "case": "nack",
                                                            "actions": {
                                                                "NACK:_Set_ResponseMessage_variable": {
                                                                    "runAfter": {},
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "ResponseMessage",
                                                                        "value": "@body('ConstructMessage:_Call_MessageConstructor')"
                                                                    }
                                                                },
                                                                "NACK:_Set_Checkpoint_variable": {
                                                                    "runAfter": {
                                                                        "NACK:_Set_ResponseMessage_variable": [
                                                                            "Succeeded"
                                                                        ]
                                                                    },
                                                                    "type": "SetVariable",
                                                                    "inputs": {
                                                                        "name": "Checkpoint",
                                                                        "value": "ConstructMessageNACK"
                                                                    }
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "default": {
                                                        "actions": {
                                                            "ConstructMessage:UnknownEnvelope:_Compose_NACK_Message": {
                                                                "runAfter": {},
                                                                "type": "Compose",
                                                                "inputs": {
                                                                    "body": [
                                                                        {
                                                                            "$content": {
                                                                                "code": "500",
                                                                                "message": "@concat('Body returned by action ', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' is not an ACK or NACK. Envelope type is: ', coalesce(body('ConstructMessage:_Call_MessageConstructor')?['header']?['properties']?['envelopeType'], '(unknown)'))"
                                                                            },
                                                                            "$contentType": "application/json",
                                                                            "$part": 1,
                                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                                        }
                                                                    ],
                                                                    "header": {
                                                                        "properties": {
                                                                            "createDate": "@utcNow()",
                                                                            "envelopeType": "nack",
                                                                            "messageId": "@guid()",
                                                                            "rootPart": 1,
                                                                            "trackingId": ""
                                                                        },
                                                                        "routing": {
                                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                                        },
                                                                        "routingSlip": {},
                                                                        "state": {}
                                                                    }
                                                                }
                                                            },
                                                            "ConstructMessage:UnknownEnvelope:_Set_ResponseMessage_variable": {
                                                                "runAfter": {
                                                                    "ConstructMessage:UnknownEnvelope:_Compose_NACK_Message": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "ResponseMessage",
                                                                    "value": "@outputs('ConstructMessage:UnknownEnvelope:_Compose_NACK_Message')"
                                                                }
                                                            },
                                                            "ConstructMessage:UnknownEnvelope:_Set_Checkpoint_variable": {
                                                                "runAfter": {
                                                                    "ConstructMessage:UnknownEnvelope:_Set_ResponseMessage_variable": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "Checkpoint",
                                                                    "value": "ConstructMessageNACK"
                                                                }
                                                            }
                                                        }
                                                    },
                                                    "expression": "@body('ConstructMessage:_Call_MessageConstructor')?['header']?['properties']?['envelopeType']",
                                                    "type": "Switch"
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "ConstructMessage:Failure:_Create_NACK_Message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['statusCode'], outputs('ConstructMessage:_Call_MessageConstructor')?['body']?['statusCode'])}",
                                                                    "faultMessage": "@{coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['error']?['message'], outputs('ConstructMessage:_Call_MessageConstructor')?['body']?['message'])}",
                                                                    "faultReason": ""
                                                                },
                                                                "message": "@concat('Action ', actions('ConstructMessage:_Call_MessageConstructor')?['name'], ' resulted in an error response.')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": ""
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "ConstructMessage:Failure:_Set_ResponseMessage_variable": {
                                                "runAfter": {
                                                    "ConstructMessage:Failure:_Create_NACK_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ResponseMessage",
                                                    "value": "@outputs('ConstructMessage:Failure:_Create_NACK_Message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "ConstructMessage:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ConstructMessage:_Call_MessageConstructor": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('ConstructMessage:_Call_MessageConstructor')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Validate_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ValidateConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    },
                    "scenario": {
                        "value": "[parameters('scenario')]"
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "suspendQueueTopicName": {
                        "value": "[parameters('suspendQueueTopicName')]"
                    },
                    "responseTopicName": {
                        "value": "[parameters('responseTopicName')]"
                    },
                    "responseSubscriptionName": {
                        "value": "[parameters('responseSubscriptionName')]"
                    }
                }
            }
        }
    ]
}
tools\templates\endpoints\http\receive\httpreceiveadapter.logicapp.dev.parameters.json.liquid
 
tools\templates\endpoints\http\receive\Deploy-105-HttpReceiveAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\ftp\send\TearDown-105-FtpSendAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\ftp\send\TearDown-100-FtpSendAdapter-ApiConnection.ps1.liquid
 
tools\templates\endpoints\ftp\send\Remove-FtpSendAdapter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the ftp adapter.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
./Remove-FtpSendAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -resourceName "logic-Aim-FtpPassthru-ReceiveLocation-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

if ($resourceExists) {
    Write-Host "Removing the ftp adapter resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

    Write-Host "Removed the ftp adapter resource: $resourceName"
}
else {
    Write-Host "The ftp adapter resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\ftp\send\Remove-FtpSendAdapter-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the ftp connector.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
./Remove-FtpSendAdapter-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -resourceName "ftpreceiveconnector-Aim-FtpPassthru-ReceiveLocation-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the ftp connector resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the ftp connector resource: $resourceName"
}
else {
    Write-Host "The ftp connector resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\ftp\send\ftpsendadapter.apiconnection.prod.parameters.json.liquid
 
tools\templates\endpoints\ftp\send\ftpsendadapter.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectorName": {
            "type": "string",
            "metadata": {
                "description": "FTP Server Name"
            }
        },
        "apiConnectorLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this connection is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "serverAddress": {
            "type": "string",
            "metadata": {
                "description": "FTP Server Address"
            }
        },
        "userName": {
            "type": "string",
            "metadata": {
                "description": "User Name for the FTP Server"
            }
        },
        "password": {
            "type": "securestring",
            "metadata": {
                "description": "Password for the FTP Server"
            }
        },
        "isBinaryTransport": {
            "type": "bool",
            "metadata": {
                "description": "Indicates if Binary or ASCII mode should be used"
            }
        },
        "serverPort": {
            "type": "int",
            "defaultValue": 21,
            "metadata": {
                "description": "FTP Port Number (example: 21)"
            }
        },
        "isSSL": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Indicates if SSL needs to be enabled (i.e. FTPS)"
            }
        },
        "disableCertificateValidation": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Indicates if Certificate Validation needs to be disabled"
            }
        },
        "closeConnectionAfterRequestCompletion": {
            "type": "bool",
            "defaultValue": false,
            "metadata": {
                "description": "Indicates if the session should be closed every time after request completes. Enable if you hit Max Connections limit."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectorName')]",
            "location": "[parameters('apiConnectorLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/', 'ftp')]"
                },
                "displayName": "Ftp-Send-Connector",
                "parameterValues": {
                    "serverAddress": "[parameters('serverAddress')]",
                    "userName": "[parameters('userName')]",
                    "password": "[parameters('password')]",
                    "serverPort": "[parameters('serverPort')]",
                    "isSSL": "[parameters('isSSL')]",
                    "isBinaryTransport": "[parameters('isBinaryTransport')]",
                    "disableCertificateValidation": "[parameters('disableCertificateValidation')]",
                    "closeConnectionAfterRequestCompletion": "[parameters('closeConnectionAfterRequestCompletion')]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\endpoints\ftp\send\ftpsendadapter.apiconnection.dev.parameters.json.liquid
 
tools\templates\endpoints\ftp\send\Deploy-105-FtpSendAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\ftp\send\Deploy-100-FtpSendAdapter-ApiConnection.ps1.liquid
 
tools\templates\endpoints\ftp\receive\TearDown-105-FtpReceiveAdapter-LogicApp.ps1.liquid
 
tools\templates\endpoints\ftp\receive\TearDown-100-FtpReceiveAdapterServiceBus-ApiConnection.ps1.liquid
 
tools\templates\endpoints\ftp\receive\TearDown-100-FtpReceiveAdapterFtp-ApiConnection.ps1.liquid
 
tools\templates\endpoints\ftp\receive\Remove-FtpReceiveAdapterServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the ftp receive adapters service bus api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-FtpReceiveAdapterServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth" -resourceName "topicpublisherconnector-ftpreceiveadapater-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the ftp receive adapters service bus api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the ftp receive adapters service bus api connection resource: $resourceName"
}
else {
    Write-Host "The ftp receive adapters service bus api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\ftp\receive\Remove-FtpReceiveAdapterFtp-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the ftp api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-FtpReceiveAdapterFtp-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth" -resourceName "ftpreceiveconnector-Aim-FtpPassthru-ReceiveLocation-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the ftp api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the ftp api connection resource: $resourceName"
}
else {
    Write-Host "The ftp api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\ftp\receive\Remove-FtpReceiveAdapter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the ftp receive adapter.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-FtpReceiveAdapter-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -resourceName "logic-Aim-FtpPassthru-ReceiveLocation-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

if ($resourceExists) {
    Write-Host "Removing the ftp receive adapter resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "workflows" --namespace "Microsoft.Logic"

    Write-Host "Removed the ftp receive adapter resource: $resourceName"
}
else {
    Write-Host "The ftp receive adapter resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\endpoints\ftp\receive\New-FtpReceiveAdapterServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Creates a service bus api connection for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FtpReceiveAdapterServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth" -templateFile ".\ftpreceiveadaptersb.apiconnection.json" -templateParameterFile ".\ftpreceiveadaptersb.apiconnection.dev.parameters.json" -deploymentName "ftpreceiveadaptersb.apiconnection.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying a service bus api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\endpoints\ftp\receive\New-FtpReceiveAdapterFtp-ApiConnection.ps1
<#
.SYNOPSIS
Creates an ftp api connection for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FtpReceiveAdapterFtp-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth" -templateFile ".\ftpreceiveadapterftp.apiconnection.json" -templateParameterFile ".\ftpreceiveadapterftp.apiconnection.dev.parameters.json" -deploymentName "ftpreceiveadapterftp.apiconnection.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying an ftp api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\intermediaries\flatfilemessageprocessor\flatfilemessageprocessor.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\flatfilemessageprocessor\New-FlatFileMessageProcessor-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-FlatFileMessageProcessor-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\flatfilemessageprocessor.logicapp.json" -templateParameterFile ".\flatfilemessageprocessor.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "flatfilemessageprocessor.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the content promoter Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\flatfilemessageprocessor\Remove-FlatFileMessageProcessor-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-FlatFileMessageProcessor-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimflatfilemessageprocessor-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\flatfilemessageprocessor\TearDown-90-FlatFileMessageProcessor-LogicApp.ps1.liquid
 
tools\templates\intermediaries\jsondecoder\Deploy-90-JsonDecoder-LogicApp.ps1.liquid
 
tools\templates\intermediaries\jsondecoder\jsondecoder.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\jsondecoder\jsondecoder.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "String",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "jsonDecoder",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. jsonDecoder."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. jsonDecoder."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Decode_Json": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "DecodeJson"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Validate_Configuration": {
                            "actions": {
                                "ValidateConfiguration:_Have_Valid_Properties": {
                                    "actions": {
                                        "ValidateConfiguration:Success:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "ValidateConfiguration"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "ValidateConfiguration:Failure:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): properties rootNode and rootNodeNamespace are not both set in configuration"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['rootNode'], '')",
                                                        ""
                                                    ]
                                                }
                                            },
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['rootNodeNamespace'], '')",
                                                        ""
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContentType": {
                            "actions": {
                                "CheckBodyContentType:_Body_Content_Type_is_JSON": {
                                    "actions": {
                                        "CheckBodyContentType:Error:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): Expected body to have a json content type. Content type is '@{coalesce(body('CheckBodyContentType:_Select_Root_Part')?[0]?['$contentType'], '')}'. Unable to continue."
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContentType:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContentType:Present:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContentType"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(body('CheckBodyContentType:_Select_Root_Part')?[0]?['$contentType'], '')",
                                                        "text/json"
                                                    ]
                                                }
                                            },
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(body('CheckBodyContentType:_Select_Root_Part')?[0]?['$contentType'], '')",
                                                        "application/json"
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContentType:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Validate_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ValidateConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Missing": {
                                            "actions": {
                                                "CheckBodyContent:Missing:Continue:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "CheckBodyContentMissingContinue"
                                                    }
                                                }
                                            },
                                            "else": {
                                                "actions": {
                                                    "CheckBodyContent:Missing:Error:_Set_ErrorMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): No Root Body content can be found in the supplied Envelope and the addMessageBodyForEmptyMessage property if set to False in configuration. Unable to continue."
                                                        }
                                                    }
                                                }
                                            },
                                            "runAfter": {},
                                            "expression": {
                                                "and": [
                                                    {
                                                        "equals": [
                                                            "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['addMessageBodyForEmptyMessage'], 'false')",
                                                            "true"
                                                        ]
                                                    }
                                                ]
                                            },
                                            "type": "if"
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Present:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContentType": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContentType"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Decode_Json": {
                            "actions": {
                                "DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('BodyContent')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/convertjsontoxml"
                                        },
                                        "queries": {
                                            "addMessageBodyForEmptyMessage": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['addMessageBodyForEmptyMessage'], 'false')",
                                            "rootNode": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['rootNode'], '')",
                                            "rootNodeNamespace": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['rootNodeNamespace'], '')",
                                            "writeArrayAttribute": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['writeArrayAttribute'], 'true')",
                                            "encodeSpecialCharacters": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['encodeSpecialCharacters'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "DecodeJson:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')['statusCode'], 500)"
                                    }
                                },
                                "DecodeJson:_Check_StatusCode": {
                                    "runAfter": {
                                        "DecodeJson:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "DecodeJson:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{body('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')}"
                                                    }
                                                },
                                                "DecodeJson:Success:_Add_new_Root_Body_Part_to_Envelope": {
                                                    "runAfter": {
                                                        "DecodeJson:Success:_Remove_existing_Root_Body_Part_from_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": "@setProperty(variables('Envelope'), 'body', union(outputs('DecodeJson:Success:_Remove_existing_Root_Body_Part_from_Envelope')?['body'], array(outputs('DecodeJson:Success:_Create_new_Body_Part'))))"
                                                },
                                                "DecodeJson:Success:_Create_new_Body_Part": {
                                                    "runAfter": {
                                                        "DecodeJson:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": {
                                                        "$content": "@base64(variables('BodyContent'))",
                                                        "$contentTransferEncoding": "base64",
                                                        "$contentType": "text/xml",
                                                        "$part": "@variables('Envelope')?['header']?['properties']?['rootPart']",
                                                        "$partType": "http://schemas.myorg.com/part@{variables('Envelope')?['header']?['properties']?['rootPart']}#root"
                                                    }
                                                },
                                                "DecodeJson:Success:_Remove_existing_Root_Body_Part_from_Envelope": {
                                                    "runAfter": {
                                                        "DecodeJson:Success:_Create_new_Body_Part": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Query",
                                                    "inputs": {
                                                        "from": "@variables('Envelope')?['body']",
                                                        "where": "@not(equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart']))"
                                                    }
                                                },
                                                "DecodeJson:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "DecodeJson:Success:_Update_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "DecodeJson"
                                                    }
                                                },
                                                "DecodeJson:Success:_Update_Envelope_variable": {
                                                    "runAfter": {
                                                        "DecodeJson:Success:_Add_new_Root_Body_Part_to_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@outputs('DecodeJson:Success:_Add_new_Root_Body_Part_to_Envelope')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "DecodeJson:Failure:_Create_Fault_message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "fault": {
                                                        "faultActor": "@concat(workflow()?['name'], '.', actions('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                        "faultCategory": "Error",
                                                        "faultCode": "@{coalesce(outputs('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['statusCode'], outputs('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['body']?['statusCode'], actions('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['error']?['code'])}",
                                                        "faultMessage": "@{coalesce(outputs('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['error']?['message'], outputs('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['body']?['message'], actions('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['error']?['message'])}",
                                                        "faultReason": "@{actions('DecodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['status']}"
                                                    }
                                                }
                                            },
                                            "DecodeJson:Failure:_Set_ErrorMessage_variable": {
                                                "runAfter": {
                                                    "DecodeJson:Failure:_Set_FaultMessage_variable": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to decode JSON content"
                                                }
                                            },
                                            "DecodeJson:Failure:_Set_FaultMessage_variable": {
                                                "runAfter": {
                                                    "DecodeJson:Failure:_Create_Fault_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "FaultMessage",
                                                    "value": "@outputs('DecodeJson:Failure:_Create_Fault_message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContentMissingContinue"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\jsondecoder\jsondecoder.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\jsondecoder\New-JsonDecoder-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-JsonDecoder-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\jsondecoder.logicapp.json" -templateParameterFile ".\jsondecoder.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "jsondecoder.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the content promoter Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\jsondecoder\Remove-JsonDecoder-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-JsonDecoder-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimjsondecoder-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\jsondecoder\TearDown-90-JsonDecoder-LogicApp.ps1.liquid
 
tools\templates\intermediaries\jsonencoder\Deploy-90-JsonEncoder-LogicApp.ps1.liquid
 
tools\templates\intermediaries\jsonencoder\jsonencoder.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\jsonencoder\jsonencoder.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "String",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "jsonEncoder",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. jsonEncoder."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. jsonEncoder."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Encode_Json": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "EncodeJson"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Validate_Configuration": {
                            "actions": {
                                "ValidateConfiguration:_Have_Valid_Properties": {
                                    "actions": {
                                        "ValidateConfiguration:Success:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "ValidateConfiguration"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "ValidateConfiguration:Failure:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): property RemoveOuterEnvelope is not set in configuration."
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['RemoveOuterEnvelope'], '')",
                                                        ""
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContentType": {
                            "actions": {
                                "CheckBodyContentType:_Body_Content_Type_is_XML": {
                                    "actions": {
                                        "CheckBodyContentType:Error:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): Expected body to have an XML content type. Content type is '@{coalesce(body('CheckBodyContentType:_Select_Root_Part')?[0]?['$contentType'], '')}'. Unable to continue."
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContentType:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContentType:Present:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContentType"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(body('CheckBodyContentType:_Select_Root_Part')?[0]?['$contentType'], '')",
                                                        "text/xml"
                                                    ]
                                                }
                                            },
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(body('CheckBodyContentType:_Select_Root_Part')?[0]?['$contentType'], '')",
                                                        "application/xml"
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContentType:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Validate_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ValidateConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Missing": {
                                            "actions": {
                                                "CheckBodyContent:Missing:Continue:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "CheckBodyContentMissingContinue"
                                                    }
                                                }
                                            },
                                            "else": {
                                                "actions": {
                                                    "CheckBodyContent:Missing:Error:_Set_ErrorMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): No Root Body content can be found in the supplied Envelope. Unable to continue."
                                                        }
                                                    }
                                                }
                                            },
                                            "runAfter": {},
                                            "expression": {
                                                "and": [
                                                    {
                                                        "equals": [
                                                            "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['addMessageBodyForEmptyMessage'], 'false')",
                                                            "true"
                                                        ]
                                                    }
                                                ]
                                            },
                                            "type": "if"
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Present:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContentType": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContentType"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Encode_Json": {
                            "actions": {
                                "EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('BodyContent')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/convertxmltojson"
                                        },
                                        "queries": {
                                            "removeOuterEnvelope": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['RemoveOuterEnvelope'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "EncodeJson:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')['statusCode'], 500)"
                                    }
                                },
                                "EncodeJson:_Check_StatusCode": {
                                    "runAfter": {
                                        "EncodeJson:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "EncodeJson:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{body('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')}"
                                                    }
                                                },
                                                "EncodeJson:Success:_Add_new_Root_Body_Part_to_Envelope": {
                                                    "runAfter": {
                                                        "EncodeJson:Success:_Remove_existing_Root_Body_Part_from_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": "@setProperty(variables('Envelope'), 'body', union(outputs('EncodeJson:Success:_Remove_existing_Root_Body_Part_from_Envelope')?['body'], array(outputs('EncodeJson:Success:_Create_new_Body_Part'))))"
                                                },
                                                "EncodeJson:Success:_Create_new_Body_Part": {
                                                    "runAfter": {
                                                        "EncodeJson:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": {
                                                        "$content": "@base64(variables('BodyContent'))",
                                                        "$contentTransferEncoding": "base64",
                                                        "$contentType": "text/json",
                                                        "$part": "@variables('Envelope')?['header']?['properties']?['rootPart']",
                                                        "$partType": "http://schemas.myorg.com/part@{variables('Envelope')?['header']?['properties']?['rootPart']}#root"
                                                    }
                                                },
                                                "EncodeJson:Success:_Remove_existing_Root_Body_Part_from_Envelope": {
                                                    "runAfter": {
                                                        "EncodeJson:Success:_Create_new_Body_Part": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Query",
                                                    "inputs": {
                                                        "from": "@variables('Envelope')?['body']",
                                                        "where": "@not(equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart']))"
                                                    }
                                                },
                                                "EncodeJson:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "EncodeJson:Success:_Update_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "EncodeJson"
                                                    }
                                                },
                                                "EncodeJson:Success:_Update_Envelope_variable": {
                                                    "runAfter": {
                                                        "EncodeJson:Success:_Add_new_Root_Body_Part_to_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@outputs('EncodeJson:Success:_Add_new_Root_Body_Part_to_Envelope')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "EncodeJson:Failure:_Create_Fault_message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "fault": {
                                                        "faultActor": "@concat(workflow()?['name'], '.', actions('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                        "faultCategory": "Error",
                                                        "faultCode": "@{coalesce(outputs('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['statusCode'], outputs('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['body']?['statusCode'], actions('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['error']?['code'])}",
                                                        "faultMessage": "@{coalesce(outputs('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['error']?['message'], outputs('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['body']?['message'], actions('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['error']?['message'])}",
                                                        "faultReason": "@{actions('EncodeJson:_Call_APIM_MessageManager.ConvertJsonToXml')?['status']}"
                                                    }
                                                }
                                            },
                                            "EncodeJson:Failure:_Set_ErrorMessage_variable": {
                                                "runAfter": {
                                                    "EncodeJson:Failure:_Set_FaultMessage_variable": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to encode JSON content"
                                                }
                                            },
                                            "EncodeJson:Failure:_Set_FaultMessage_variable": {
                                                "runAfter": {
                                                    "EncodeJson:Failure:_Create_Fault_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "FaultMessage",
                                                    "value": "@outputs('EncodeJson:Failure:_Create_Fault_message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContentMissingContinue"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\jsonencoder\jsonencoder.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\jsonencoder\New-JsonEncoder-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-JsonEncoder-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\jsonencoder.logicapp.json" -templateParameterFile ".\jsonencoder.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "jsonencoder.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the content promoter Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\jsonencoder\Remove-JsonEncoder-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-JsonEncoder-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimjsonencoder-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\jsonencoder\TearDown-90-JsonEncoder-LogicApp.ps1.liquid
 
tools\templates\intermediaries\processmanager\Deploy-100-ProcessManagerServiceBus-ApiConnection.ps1.liquid
 
tools\templates\intermediaries\processmanager\Deploy-105-ProcessManager-LogicApp.ps1.liquid
 
tools\templates\intermediaries\processmanager\New-ProcessManager-LogicApp.ps1
<#
.SYNOPSIS
Creates a process manager Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-ProcessManager-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -templateFile "$PSScriptRoot\processmanager.logicapp.json" -templateParameterFile "$PSScriptRoot\processmanager.logicapp.dev.parameters.json" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "processmanager.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the process manager Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\processmanager\New-ProcessManagerServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Creates a process manager service bus connection for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-ProcessManagerServiceBus-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -templateFile "$PSScriptRoot\processmanagerservicebus.apiconnection.json" -templateParameterFile "$PSScriptRoot\processmanagerservicebus.apiconnection.dev.parameters.json" -deploymentName "processmanagerservicebus.apic.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying a process manager service bus api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\intermediaries\processmanager\processmanagerservicebus.apiconnection.dev.parameters.json.liquid
 
tools\templates\intermediaries\processmanager\processmanagerservicebus.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "serviceBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that contains the Azure Service Bus resource."
            }
        },
        "serviceBusNamespaceName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Namespace this API Connection connects to."
            }
        },
        "serviceBusPolicyName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Policy this API Connection connects to."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'servicebus')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "connectionString": "[listKeys(resourceId(parameters('serviceBusResourceGroupName'), 'Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('serviceBusNamespaceName'), parameters('serviceBusPolicyName')), '2017-04-01').primaryConnectionString]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\intermediaries\processmanager\processmanagerservicebus.apiconnection.prod.parameters.json.liquid
 
tools\templates\intermediaries\processmanager\Remove-ProcessManager-LogicApp.ps1
<#
.SYNOPSIS
Tears down the process manager Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-ProcessManager-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimprocessmanager-processmanager-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\processmanager\Remove-ProcessManagerServiceBus-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the process manager service bus api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-ProcessManagerServiceBus-ApiConnection.ps1 -resourceGroup "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -resourceName "apic-aimsbconnector-processmanager-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the process manager service bus api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the process manager service bus api connection resource: $resourceName"
}
else {
    Write-Host "The process manager service bus api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\processmanager\snippets\activatable\processmanager.activitycontainer.workflow.decodesbmsg.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\activatable\processmanager.activitycontainer.workflow.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\activatable\processmanager.channel.trigger.servicebustopic.snippet.json
{
    "workflowTrigger": {
        "When_a_message_is_received_in_a_topic_subscription_(peek-lock)": {
            "inputs": {
                "host": {
                    "connection": {
                        "name": "@parameters('$connections')['servicebussubscribe']['connectionId']"
                    }
                },
                "method": "get",
                "path": "/@{encodeURIComponent(parameters('serviceBusTopicName'))}/subscriptions/@{encodeURIComponent(parameters('serviceBusTopicSubscriptionName'))}/messages/head/peek",
                "queries": {
                    "sessionId": "None",
                    "subscriptionType": "Main"
                }
            },
            "recurrence": {
                "frequency": "@{parameters('serviceBusRecurrenceFrequency')}",
                "interval": "@parameters('serviceBusRecurrenceInterval')"
            },
            "type": "ApiConnection"
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\activatable\processmanager.parametersdefinition.snippet.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "value": "{{ resource_template.resource_name }}"
        },
        "logicAppLocation": {
            "value": "{{ resource_template.parameters.azure_primary_region }}"
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\activatable\processmanager.workflowdefinition.snippet.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "triggers": {},
                    "actions": {},
                    "outputs": {}
                },
                "parameters": {}
            }
        }
    ]
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activity.codeexpression.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activity.invokeworkflow.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activity.messageconstruction.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activity.messagetransform.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activity.placeholder.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activitycontainer.decision.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activitycontainer.decisionbranch.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activitycontainer.placeholder.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activitycontainer.task.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.activitycontainer.workflow.getconfiguration.snippet.json
{
    "workflowDefinitionAction": {
        "Action:_Get_Configuration": {
            "runAfter": {},
            "type": "ApiManagement",
            "description": "Gets configuration for scenario step @(parameters('scenarioStep'))",
            "inputs": {
                "api": {
                    "id": "[variables('configurationManagerApiResourceId')]"
                },
                "method": "get",
                "pathTemplate": {
                    "parameters": {
                        "scenario": "@{encodeURIComponent(parameters('scenario'))}",
                        "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                    },
                    "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                },
                "queries": {
                    "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                },
                "retryPolicy": "[parameters('apimRetryPolicy')]",
                "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.channel.receive.servicebustopic.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.channel.send.servicebustopic.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.message.placeholder.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.apimretrypolicy.snippet.json
{
    "armTemplateParameter": {
        "apimRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.apimservice.snippet.json
{
    "armParameter": {
        "apimServiceName": {
            "value": "{{ resource_template.parameters.apim_service_name }}"
        }
    },
    "armTemplateParameter": {
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.scenario.snippet.json
{
    "armParameter": {
        "scenario": {
            "value": "{{ resource_template.parameters.scenario_name }}"
        }
    },
    "armTemplateParameter": {
        "scenario": {
            "type": "string",
            "metadata": {
                "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
            }
        }
    },
    "workflowParameter": {
        "scenario": {
            "value": "[parameters('scenario')]"
        }
    },
    "workflowDefinitionParameter": {
        "scenario": {
            "type": "String",
            "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.scenariostep.snippet.json
{
    "armParameter": {
        "scenarioStep": {
            "value": "{{ resource_template.parameters.scenario_step_name }}"
        }
    },
    "armTemplateParameter": {
        "scenarioStep": {
            "type": "string",
            "defaultValue": "processManagerTemplate",
            "metadata": {
                "description": "The step within a route (scenario) that this LogicApp represents."
            }
        }
    },
    "workflowParameter": {
        "scenarioStep": {
            "value": "[parameters('scenarioStep')]"
        }
    },
    "workflowDefinitionParameter": {
        "scenarioStep": {
            "type": "String",
            "description": "The step within a route (scenario) that this LogicApp represents, for example, contentPromoter."
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.servicebusrecurrencefrequency.snippet.json
{
    "armParameter": {
        "serviceBusRecurrenceFrequency": {
            "value": "{{ resource_template.parameters.azure_service_bus_recurrence_frequency }}"
        }
    },
    "armTemplateParameter": {
        "serviceBusRecurrenceFrequency": {
            "type": "string",
            "allowedValues": [ "Second", "Minute", "Hour", "Day", "Month", "Year" ],
            "metadata": {
                "description": "The frequency with which to check for new messages on the ServiceBus Topic Subscription."
            }
        }
    },
    "workflowParameter": {
        "serviceBusRecurrenceFrequency": {
            "value": "[parameters('serviceBusRecurrenceFrequency')]"
        }
    },
    "workflowDefinitionParameter": {
        "serviceBusRecurrenceFrequency": {
            "type": "string",
            "allowedValues": [ "Second", "Minute", "Hour", "Day", "Month", "Year" ],
            "description": "The frequency with which to check for new messages on the ServiceBus Topic Subscription."
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.servicebusrecurrenceinterval.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.servicebustopic.snippet.json
{
    "armParameter": {
        "serviceBusTopicName": {
            "value": "{{ resource_template.parameters.azure_service_bus_topic_name }}"
        }
    },
    "armTemplateParameter": {
        "serviceBusTopicName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic used to subscribe to messages."
            }
        }
    },
    "workflowParameter": {
        "serviceBusTopicName": {
            "value": "[parameters('serviceBusTopicName')]"
        }
    },
    "workflowDefinitionParameter": {
        "serviceBusTopicName": {
            "type": "String",
            "description": "Name of the ServiceBus Topic used to subscribe to messages."
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.servicebustopicpublishapiconnection.snippet.json
{
    "armParameter": {
        "serviceBusTopicPublishApiConnectionName": {
            "value": "{{ resource_template.parameters.azure_topic_publisher_api_connection_name }}"
        }
    },
    "armTemplateParameter": {
        "serviceBusTopicPublishApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for ServiceBus Topic Publish operations."
            }
        }
    },
    "workflowParameter": {
        "$connections": {
            "value": {
                "servicebuspublish": {
                    "connectionId": "[variables('serviceBusTopicPublishApiConnectionResourceId')]",
                    "connectionName": "[parameters('serviceBusTopicPublishApiConnectionName')]",
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/servicebus')]"
                }
            }
        }
    },
    "workflowDefinitionParameter": {
        "$connections": {
            "defaultValue": {},
            "type": "Object"
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.servicebustopicsubscribeapiconnection.snippet.json
{
    "armParameter": {
        "serviceBusTopicSubscribeApiConnectionName": {
            "value": "{{ resource_template.parameters.azure_topic_subscriber_api_connection_name }}"
        }
    },
    "armTemplateParameter": {
        "serviceBusTopicSubscribeApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for ServiceBus Topic Subscribe operations."
            }
        }
    },
    "workflowParameter": {
        "$connections": {
            "value": {
                "servicebussubscribe": {
                    "connectionId": "[variables('serviceBusTopicSubscribeApiConnectionResourceId')]",
                    "connectionName": "[parameters('serviceBusTopicSubscribeApiConnectionName')]",
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/servicebus')]"
                }
            }
        }
    },
    "workflowDefinitionParameter": {
        "$connections": {
            "defaultValue": {},
            "type": "Object"
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.servicebustopicsubscription.snippet.json
{
    "armParameter": {
        "serviceBusTopicSubscriptionName": {
            "value": "{{ resource_template.parameters.azure_service_bus_subscription_name }}"
        }
    },
    "armTemplateParameter": {
        "serviceBusTopicSubscriptionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic Subscription used to subscribe to messages."
            }
        }
    },
    "workflowParameter": {
        "serviceBusTopicSubscriptionName": {
            "value": "[parameters('serviceBusTopicSubscriptionName')]"
        }
    },
    "workflowDefinitionParameter": {
        "serviceBusTopicSubscriptionName": {
            "type": "String",
            "description": "Name of the ServiceBus Topic Subscription used to subscribe to messages."
        }        
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.suspendqueuetopic.snippet.json
{
    "armParameter": {
        "suspendQueueTopicName": {
            "value": "{{ resource_template.parameters.azure_service_bus_suspend_queue_topic_name }}"
        }
    },
    "armTemplateParameter": {
        "suspendQueueTopicName": {
            "type": "string",
            "metadata": {
                "description": "The name of the Service Bus topic for the Suspend Queue."
            }
        }
    },
    "workflowParameter": {
        "suspendQueueTopicName": {
            "value": "[parameters('suspendQueueTopicName')]"
        }
    },
    "workflowDefinitionParameter": {
        "suspendQueueTopicName": {
            "type": "String",
            "description": "The name of the Service Bus topic for the Suspend Queue."
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.systemapplicationresourcegroup.snippet.json
{
    "armParameter": {
        "systemApplicationResourceGroupName": {
            "value": "{{ resource_template.parameters.azure_system_application_resource_group_name }}"
        }
    },
    "armTemplateParameter": {
        "systemApplicationResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the resource group that common system artifacts are deployed to."
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.tags.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.property.integrationaccount.snippet.json
{
    "workflowProperty": {
        "integrationAccount": {
            "id": "[variables('integrationAccountResourceId')]"
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.property.tags.snippet.json
{
    "workflowResourceProperty": {
        "tags": "[parameters('tags')]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.apimservice.snippet.json
{
    "armTemplateVariable": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.configurationmanager.snippet.json
{
    "armTemplateVariable": {
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.initialize.configuration.snippet.json
{
    "workflowDefinitionVariable": {
        "Initialize_Configuration_variable": {
            "runAfter": {},
            "type": "InitializeVariable",
            "inputs": {
                "variables": [
                    {
                        "name": "Configuration",
                        "type": "object"
                    }
                ]
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.initialize.errormessage.snippet.json
{
    "workflowDefinitionVariable": {
        "Initialize_ErrorMessage_variable": {
            "runAfter": {},
            "type": "InitializeVariable",
            "inputs": {
                "variables": [
                    {
                        "name": "ErrorMessage",
                        "type": "string",
                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp."
                    }
                ]
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.initialize.faultmessage.snippet.json
{
    "workflowDefinitionVariable": {
        "Initialize_FaultMessage_variable": {
            "runAfter": {},
            "type": "InitializeVariable",
            "inputs": {
                "variables": [
                    {
                        "name": "FaultMessage",
                        "type": "object"
                    }
                ]
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.initialize.messagetype.snippet.json
{
    "workflowDefinitionVariable": {
        "Initialize_MessageType_variable": {
            "runAfter": {},
            "type": "InitializeVariable",
            "inputs": {
                "variables": [
                    {
                        "name": "MessageType",
                        "type": "string"
                    }
                ]
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.initialize.statuscode.snippet.json
{
    "workflowDefinitionVariable": {
        "Initialize_StatusCode_variable": {
            "runAfter": {},
            "type": "InitializeVariable",
            "inputs": {
                "variables": [
                    {
                        "name": "StatusCode",
                        "type": "integer",
                        "value": 500
                    }
                ]
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.integrationaccount.snippet.json
{
    "armTemplateVariable": {
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.messagesuspendprocessorlogicapp.snippet.json
{
    "armTemplateVariable": {
        "messageSuspendProcessorLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageSuspendProcessorLogicAppName'))]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.messagingmanager.snippet.json
{
    "armTemplateVariable": {
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.placeholder.snippet.json.liquid
 
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.routingmanager.snippet.json
{
    "armTemplateVariable": {
        "routingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimroutingmanager')]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.routingsliprouterlogicapp.snippet.json
{
    "armTemplateVariable": {
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.servicebustopicpublishapiconnection.snippet.json
{
    "armTemplateVariable": {
        "serviceBusTopicPublishApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('serviceBusTopicPublishApiConnectionName'))]"
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.variable.servicebustopicsubscribeapiconnection.snippet.json
{
    "armTemplateVariable": {
        "serviceBusTopicSubscribeApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('serviceBusTopicSubscribeApiConnectionName'))]"
    }
}
tools\templates\intermediaries\processmanager\snippets\invokable\processmanager.channel.trigger.http.snippet.json
{
    "workflowTrigger": {
        "manual": {
            "correlation": {
                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
            },
            "type": "Request",
            "kind": "Http",
            "inputs": {
                "schema": {}
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\invokable\processmanager.parametersdefinition.snippet.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentParameters.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "value": "{{ resource_template.resource_name }}"
        },
        "logicAppLocation": {
            "value": "{{ resource_template.parameters.azure_primary_region }}"
        }
    }
}
tools\templates\intermediaries\topicpublisher\New-TopicPublisher-LogicApp.ps1
<#
.SYNOPSIS
Creates a topic publisher Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-TopicPublisher-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\topicpublisher.logicapp.json" -templateParameterFile ".\topicpublisher.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "topicpublisher.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the topic publisher Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\topicpublisher\Remove-TopicPublisher-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the api connection for the topic publisher.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-TopicPublisher.ApiConnection.ps1 -resourceGroupName "sb-aimmsgbox-dev-uksouth-xxxxx" -resourceName "Aim-TopicPublisher-Channel"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the topic publisher api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the topic publisher api connection resource: $resourceName"
}
else {
    Write-Host "The topic publisher api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\topicsubscriber\New-TopicSubscriber-LogicApp.ps1
<#
.SYNOPSIS
Creates a topic subscriber Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-TopicSubscriber-LogicApp.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -templateFile "$PSScriptRoot\topicsubscriber.logicapp.json" -templateParameterFile "$PSScriptRoot\topicsubscriber.logicapp.dev.parameters.json" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "topicsubscriber.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the topic subscriber Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\topicsubscriber\Remove-TopicSubscriber-ApiConnection.ps1
<#
.SYNOPSIS
Tears down the topic subscriber api connection.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
.\Remove-TopicSubscriber-ApiConnection.ps1 -resourceGroup "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -resourceName "topicsubscriberconnector-aim-ftppassthru-sendport-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az resource show --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

if ($resourceExists) {
    Write-Host "Removing the topic subscriber api connection resource: $resourceName"

    az resource delete --name $resourceName --resource-group $resourceGroupName --resource-type "connections" --namespace "Microsoft.Web"

    Write-Host "Removed the topic subscriber api connection resource: $resourceName"
}
else {
    Write-Host "The topic subscriber api connection resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\topicsubscriber\New-TopicSubscriber-ApiConnection.ps1
<#
.SYNOPSIS
Creates a topic subscriber connection for an application.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-TopicSubscriber-ApiConnection.ps1 -resourceGroupName "rg-aimapp-aim-ftppassthru-dev-uksouth-xxxxx" -templateFile "$PSScriptRoot\topicsubscriber.apiconnection.json" -templateParameterFile "$PSScriptRoot\topicsubscriber.apiconnection.dev.parameters.json" -deploymentName "topicsubscriber.apic.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying a topic subscriber api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\intermediaries\topicsubscriber\Deploy-105-TopicSubscriber-LogicApp.ps1.liquid
 
tools\templates\intermediaries\topicsubscriber\Deploy-100-TopicSubscriber-ApiConnection.ps1.liquid
 
tools\templates\intermediaries\topicpublisher\topicpublisher.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\topicpublisher\topicpublisher.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "serviceBusTopicPublishApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for ServiceBus Topic Publish operations."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "topicPublisher",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. topicPublisher."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "serviceBusTopicPublishApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('serviceBusTopicPublishApiConnectionName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "$connections": {
                            "defaultValue": {},
                            "type": "Object"
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. topicPublisher."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Publish_To_Topic": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "PublishToTopic"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_TopicId": {
                            "actions": {
                                "CheckTopicId:_TopicId_is_blank": {
                                    "actions": {
                                        "CheckTopicId:Failure:_Set_ErrorMessage": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): No TopicId is set in the configuration entry for this step"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "CheckTopicId:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckTopicId"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['topicName'], '')}",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Publish_To_Topic": {
                            "actions": {
                                "PublishToTopic:_Check_Status_Code": {
                                    "runAfter": {
                                        "PublishToTopic:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "PublishToTopic:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "PublishToTopic"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "PublishToTopic:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "PublishToTopic:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "PublishToTopic:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to publish a message to ServiceBus"
                                                        }
                                                    },
                                                    "PublishToTopic:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('PublishToTopic:_Send_to_ServiceBus')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "PublishToTopic:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('PublishToTopic:_Send_to_ServiceBus')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('PublishToTopic:_Send_to_ServiceBus')?['statusCode'], outputs('PublishToTopic:_Send_to_ServiceBus')?['body']?['statusCode'], actions('PublishToTopic:_Send_to_ServiceBus')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('PublishToTopic:_Send_to_ServiceBus')?['error']?['message'], outputs('PublishToTopic:_Send_to_ServiceBus')?['body']?['message'], actions('PublishToTopic:_Send_to_ServiceBus')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('PublishToTopic:_Send_to_ServiceBus')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "PublishToTopic:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "PublishToTopic:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to publish a message to ServiceBus"
                                                            }
                                                        },
                                                        "PublishToTopic:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "PublishToTopic:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('PublishToTopic:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('PublishToTopic:_Send_to_ServiceBus')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "PublishToTopic:_Send_to_ServiceBus": {
                                    "runAfter": {},
                                    "type": "ApiConnection",
                                    "inputs": {
                                        "body": {
                                            "ContentData": "@{base64(variables('Envelope'))}",
                                            "ContentType": "application/json",
                                            "MessageId": "@coalesce(variables('Envelope')?['header']?['properties']?['messageId'], guid())",
                                            "Properties": "@variables('Envelope')?['header']?['routing']",
                                            "SessionId": "@if(equals(coalesce(variables('Configuration')?[parameters('scenarioStep')]?['useSessions'], false), true), coalesce(variables('Envelope')?['header']?['properties']?[variables('Configuration')?[parameters('scenarioStep')]?['sessionPropertyName']], 'none'), 'none')"
                                        },
                                        "host": {
                                            "connection": {
                                                "name": "@parameters('$connections')['servicebuspublish']['connectionId']"
                                            }
                                        },
                                        "method": "post",
                                        "path": "/@{encodeURIComponent(coalesce(variables('Configuration')?[parameters('scenarioStep')]?['topicName'], '(topic name not set)'))}/messages",
                                        "queries": {
                                            "systemProperties": "None"
                                        }
                                    }
                                },
                                "PublishToTopic:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "PublishToTopic:_Send_to_ServiceBus": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('PublishToTopic:_Send_to_ServiceBus')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_TopicId": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckTopicId"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "$connections": {
                        "value": {
                            "servicebuspublish": {
                                "connectionId": "[variables('serviceBusTopicPublishApiConnectionResourceId')]",
                                "connectionName": "[parameters('serviceBusTopicPublishApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/servicebus')]"
                            }
                        }
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\topicsubscriber\topicsubscriber.apiconnection.prod.parameters.json.liquid
 
tools\templates\intermediaries\topicsubscriber\topicsubscriber.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\topicsubscriber\topicsubscriber.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "systemApplicationResourceGroupName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ResourceGroup that SystemApplication artifacts are deployed to (e.g. ServiceBus or MessageConstructor LogicApp)."
            }
        },
        "messageSuspendProcessorLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle suspending of messages."
            }
        },
        "suspendQueueTopicName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic that suspended messages are sent to."
            }
        },
        "serviceBusTopicSubscribeApiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the API Connection used for ServiceBus Topic Subscribe operations."
            }
        },
        "serviceBusTopicName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic used to subscribe to messages."
            }
        },
        "serviceBusTopicSubscriptionName": {
            "type": "string",
            "metadata": {
                "description": "Name of the ServiceBus Topic Subscription used to subscribe to messages."
            }
        },
        "serviceBusRecurrenceFrequency": {
            "type": "string",
            "allowedValues": [ "Second", "Minute", "Hour", "Day", "Month", "Year" ],
            "metadata": {
                "description": "The frequency with which to check for new messages on the ServiceBus Topic Subscription."
            }
        },
        "serviceBusRecurrenceInterval": {
            "type": "int",
            "metadata": {
                "description": "The interval with which to check for new messages on the ServiceBus Topic Subscription."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenario": {
            "type": "string",
            "metadata": {
                "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
            }
        },
        "scenarioStep": {
            "defaultValue": "template",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. template."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "messageSuspendProcessorLogicAppResourceId": "[resourceId(parameters('systemApplicationResourceGroupName'), 'Microsoft.Logic/workflows', parameters('messageSuspendProcessorLogicAppName'))]",
        "serviceBusTopicSubscribeApiConnectionResourceId": "[resourceId('Microsoft.Web/connections', parameters('serviceBusTopicSubscribeApiConnectionName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "$connections": {
                            "defaultValue": {},
                            "type": "Object"
                        },
                        "serviceBusTopicName": {
                            "type": "String",
                            "description": "Name of the ServiceBus Topic used to subscribe to messages."
                        },
                        "serviceBusTopicSubscriptionName": {
                            "type": "String",
                            "description": "Name of the ServiceBus Topic Subscription used to subscribe to messages."
                        },
                        "serviceBusRecurrenceFrequency": {
                            "type": "string",
                            "allowedValues": [ "Second", "Minute", "Hour", "Day", "Month", "Year" ],
                            "description": "The frequency with which to check for new messages on the ServiceBus Topic Subscription."
                        },
                        "serviceBusRecurrenceInterval": {
                            "type": "int",
                            "description": "The interval with which to check for new messages on the ServiceBus Topic Subscription."
                        },
                        "scenario": {
                            "type": "String",
                            "description": "The name of the Scenario that this LogicApp is running under e.g. ApplicationName + ReceivePort/Location Name."
                        },
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. template."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        },
                        "clearCache": {
                            "defaultValue": true,
                            "type": "Bool",
                            "description": "Indicates if we should clear APIM cache before retrieved config items e.g. configurationEntries or routingSlips."
                        },
                        "suspendQueueTopicName": {
                            "type": "String",
                            "description": "Name of the ServiceBus Topic that suspended messages are sent to."
                        }
                    },
                    "triggers": {
                        "When_a_message_is_received_in_a_topic_subscription_(peek-lock)": {
                            "inputs": {
                                "host": {
                                    "connection": {
                                        "name": "@parameters('$connections')['servicebussubscribe']['connectionId']"
                                    }
                                },
                                "method": "get",
                                "path": "/@{encodeURIComponent(parameters('serviceBusTopicName'))}/subscriptions/@{encodeURIComponent(parameters('serviceBusTopicSubscriptionName'))}/messages/head/peek",
                                "queries": {
                                    "sessionId": "None",
                                    "subscriptionType": "Main"
                                }
                            },
                            "recurrence": {
                                "frequency": "@{parameters('serviceBusRecurrenceFrequency')}",
                                "interval": "@parameters('serviceBusRecurrenceInterval')"
                            },
                            "type": "ApiConnection"
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_NewEnvelope_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "NewEnvelope",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_NewEnvelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('NewEnvelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                            "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                            "Aim-Tracking-Id": "@{variables('Envelope')?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Do_we_have_an_ACK": {
                                                    "actions": {
                                                        "Routing:Success:_Complete_the_message": {
                                                            "inputs": {
                                                                "host": {
                                                                    "connection": {
                                                                        "name": "@parameters('$connections')['servicebussubscribe']['connectionId']"
                                                                    }
                                                                },
                                                                "method": "delete",
                                                                "path": "/@{encodeURIComponent(parameters('serviceBusTopicName'))}/subscriptions/@{encodeURIComponent(parameters('serviceBusTopicSubscriptionName'))}/messages/complete",
                                                                "queries": {
                                                                    "lockToken": "@triggerBody()?['LockToken']",
                                                                    "subscriptionType": "Main"
                                                                }
                                                            },
                                                            "runAfter": {},
                                                            "type": "ApiConnection"
                                                        }
                                                    },
                                                    "expression": {
                                                        "and": [
                                                            {
                                                                "equals": [
                                                                    "@{body('Routing:_Call_RoutingSlipRouter')?['header']?['properties']?['envelopeType']}",
                                                                    "ack"
                                                                ]
                                                            }
                                                        ]
                                                    },
                                                    "runAfter": {},
                                                    "else": {
                                                        "actions": {
                                                            "Routing:Failure:_Set_ErrorMessage_variable": {
                                                                "runAfter": {},
                                                                "type": "SetVariable",
                                                                "inputs": {
                                                                    "name": "ErrorMessage",
                                                                    "value": "An NACK was returned by RoutingSlipRouter in @{workflow()?['name']} (@{workflow()?['run']?['name']})"
                                                                }
                                                            },
                                                            "Routing:Failure:_Suspend_Messages": {
                                                                "runAfter": {
                                                                    "Routing:Failure:_Set_ErrorMessage_variable": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "Workflow",
                                                                "inputs": {
                                                                    "body": {
                                                                        "nackMessage": "@body('Routing:_Call_RoutingSlipRouter')",
                                                                        "originalMessage": "@variables('Envelope')",
                                                                        "suspendQueueTopicName": "@{parameters('suspendQueueTopicName')}",
                                                                        "failedMessageRouting": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['failedMessageRouting'], false)",
                                                                        "scenario": "@{parameters('scenario')}"
                                                                    },
                                                                    "headers": {
                                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                                                    },
                                                                    "host": {
                                                                        "triggerName": "manual",
                                                                        "workflow": {
                                                                            "id": "[variables('messageSuspendProcessorLogicAppResourceId')]"
                                                                        }
                                                                    }
                                                                }
                                                            },
                                                            "Routing:Failure:_Dead-letter_the_message": {
                                                                "inputs": {
                                                                    "host": {
                                                                        "connection": {
                                                                            "name": "@parameters('$connections')['servicebussubscribe']['connectionId']"
                                                                        }
                                                                    },
                                                                    "method": "post",
                                                                    "path": "/@{encodeURIComponent(parameters('serviceBusTopicName'))}/subscriptions/@{encodeURIComponent(parameters('serviceBusTopicSubscriptionName'))}/messages/deadletter",
                                                                    "queries": {
                                                                        "deadLetterErrorDescription": "@string(body('Routing:_Call_RoutingSlipRouter'))",
                                                                        "deadLetterReason": "@variables('ErrorMessage')",
                                                                        "lockToken": "@triggerBody()?['LockToken']"
                                                                    }
                                                                },
                                                                "runAfter": {
                                                                    "Routing:Failure:_Suspend_Messages": [
                                                                        "Succeeded"
                                                                    ]
                                                                },
                                                                "type": "ApiConnection"
                                                            }
                                                        }
                                                    },
                                                    "type": "If"
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@variables('Envelope')?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Suspend_Messages": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Workflow",
                                                "inputs": {
                                                    "body": {
                                                        "nackMessage": "@outputs('Routing:Error:_Build_NACK_message')",
                                                        "originalMessage": "@variables('Envelope')",
                                                        "suspendQueueTopicName": "@{parameters('suspendQueueTopicName')}",
                                                        "failedMessageRouting": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['failedMessageRouting'], false)",
                                                        "scenario": "@{parameters('scenario')}"
                                                    },
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                                    },
                                                    "host": {
                                                        "triggerName": "manual",
                                                        "workflow": {
                                                            "id": "[variables('messageSuspendProcessorLogicAppResourceId')]"
                                                        }
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Dead-letter_the_message": {
                                                "inputs": {
                                                    "host": {
                                                        "connection": {
                                                            "name": "@parameters('$connections')['servicebussubscribe']['connectionId']"
                                                        }
                                                    },
                                                    "method": "post",
                                                    "path": "/@{encodeURIComponent(parameters('serviceBusTopicName'))}/subscriptions/@{encodeURIComponent(parameters('serviceBusTopicSubscriptionName'))}/messages/deadletter",
                                                    "queries": {
                                                        "deadLetterErrorDescription": "@outputs('Routing:Error:_Build_NACK_message')",
                                                        "deadLetterReason": "@variables('ErrorMessage')",
                                                        "lockToken": "@triggerBody()?['LockToken']"
                                                    }
                                                },
                                                "runAfter": {
                                                    "Routing:Error:_Suspend_Messages": [
                                                        "Succeeded",
                                                        "Failed",
                                                        "TimedOut"
                                                    ]
                                                },
                                                "type": "ApiConnection"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Merge_Properties": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Suspend_Messages": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Workflow",
                                        "inputs": {
                                            "body": {
                                                "nackMessage": "@outputs('Failure:_Build_NACK_message')",
                                                "originalMessage": "@variables('Envelope')",
                                                "suspendQueueTopicName": "@{parameters('suspendQueueTopicName')}",
                                                "failedMessageRouting": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['failedMessageRouting'], false)",
                                                "scenario": "@{parameters('scenario')}"
                                            },
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                            },
                                            "host": {
                                                "triggerName": "manual",
                                                "workflow": {
                                                    "id": "[variables('messageSuspendProcessorLogicAppResourceId')]"
                                                }
                                            }
                                        }
                                    },
                                    "Failure:_Dead-letter_the_message": {
                                        "inputs": {
                                            "host": {
                                                "connection": {
                                                    "name": "@parameters('$connections')['servicebussubscribe']['connectionId']"
                                                }
                                            },
                                            "method": "post",
                                            "path": "/@{encodeURIComponent(parameters('serviceBusTopicName'))}/subscriptions/@{encodeURIComponent(parameters('serviceBusTopicSubscriptionName'))}/messages/deadletter",
                                            "queries": {
                                                "deadLetterErrorDescription": "@outputs('Failure:_Build_NACK_message')",
                                                "deadLetterReason": "@variables('ErrorMessage')",
                                                "lockToken": "@triggerBody()?['LockToken']",
                                                "sessionId": "@triggerBody()?['SessionId']"
                                            }
                                        },
                                        "runAfter": {
                                            "Failure:_Suspend_Messages": [
                                                "Succeeded",
                                                "Failed",
                                                "TimedOut"
                                            ]
                                        },
                                        "type": "ApiConnection"
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "MergeProperties"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Envelope": {
                            "cases": {
                                "Json": {
                                    "actions": {
                                        "GetEnvelope:Json:_Set_Envelope_variable": {
                                            "inputs": {
                                                "name": "Envelope",
                                                "value": "@if(equals(triggerBody()?['ContentTransferEncoding'], 'Base64'), json(decodeBase64(triggerBody()?['ContentData'])), triggerBody()?['ContentData'])"
                                            },
                                            "runAfter": {},
                                            "type": "SetVariable"
                                        },
                                        "GetEnvelope:Json:_Set_Checkpoint_variable": {
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "GetEnvelope"
                                            },
                                            "runAfter": {
                                                "GetEnvelope:Json:_Set_Envelope_variable": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "type": "SetVariable"
                                        }
                                    },
                                    "case": "json"
                                },
                                "Xml": {
                                    "actions": {
                                        "GetEnvelope:Xml:_Build_Content_Message": {
                                            "inputs": {
                                                "$content": "@triggerBody()?['ContentData']",
                                                "$contentTransferEncoding": "@triggerBody()?['ContentTransferEncoding']",
                                                "$contentType": "@triggerBody()?['ContentType']"
                                            },
                                            "runAfter": {},
                                            "type": "Compose"
                                        },
                                        "GetEnvelope:Xml:_Set_Envelope_variable": {
                                            "inputs": {
                                                "name": "Envelope",
                                                "value": "@outputs('GetEnvelope:Xml:_Build_Content_Message')"
                                            },
                                            "runAfter": {
                                                "GetEnvelope:Xml:_Build_Content_Message": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "type": "SetVariable"
                                        },
                                        "GetEnvelope:Xml:_Set_Checkpoint_variable": {
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "GetEnvelope"
                                            },
                                            "runAfter": {
                                                "GetEnvelope:Xml:_Set_Envelope_variable": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "type": "SetVariable"
                                        }
                                    },
                                    "case": "xml"
                                }
                            },
                            "default": {
                                "actions": {
                                    "GetInboundMessage:Unsupported:_Set_ErrorMessage_variable": {
                                        "inputs": {
                                            "name": "ErrorMessage",
                                            "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp: the subscribed ServiceBus message has an unsupported ContentType value of @{coalesce(triggerBody()?['ContentType'], '(none)')}."
                                        },
                                        "runAfter": {},
                                        "type": "SetVariable"
                                    }
                                }
                            },
                            "expression": "@if(greaterOrEquals(indexOf(triggerBody()?['ContentType'], '/'), 0), split(triggerBody()?['ContentType'], '/')?[1], triggerBody()?['ContentType'])",
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "type": "Switch"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(parameters('scenario'))}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@parameters('clearCache')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Envelope": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetEnvelope"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Build_New_Envelope": {
                            "actions": {
                                "BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "headers": {
                                            "Content-Transfer-Encoding": "none",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {
                                                "envelopeType": "@{encodeURIComponent('document')}",
                                                "scenario": "@{encodeURIComponent(parameters('scenario'))}"
                                            },
                                            "template": "/aimmessagingmanager/buildenvelope/{envelopeType}/{scenario}"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "BuildNewEnvelope:_Check_Status_Code": {
                                    "runAfter": {
                                        "BuildNewEnvelope:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "BuildNewEnvelope:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "BuildNewEnvelope:Success:_Set_NewEnvelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "BuildNewEnvelope"
                                                    }
                                                },
                                                "BuildNewEnvelope:Success:_Set_NewEnvelope_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "NewEnvelope",
                                                        "value": "@body('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "BuildNewEnvelope:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "BuildNewEnvelope:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "BuildNewEnvelope:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager BuildNewEnvelope operation"
                                                        }
                                                    },
                                                    "BuildNewEnvelope:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "BuildNewEnvelope:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['statusCode'], outputs('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['body']?['statusCode'], actions('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['error']?['message'], outputs('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['body']?['message'], actions('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "BuildNewEnvelope:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "BuildNewEnvelope:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager BuildNewEnvelope operation"
                                                            }
                                                        },
                                                        "BuildNewEnvelope:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "BuildNewEnvelope:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('BuildNewEnvelope:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@outputs('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['body']?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "BuildNewEnvelope:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('BuildNewEnvelope:_Call_APIM_MessagingManager.BuildNewEnvelope')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Merge_Properties": {
                            "actions": {
                                "MergeProperties:_Exception_Scope": {
                                    "actions": {
                                        "MergeProperties:_Merge_RoutingSlip": {
                                            "runAfter": {},
                                            "type": "Compose",
                                            "inputs": "@setProperty(variables('Envelope'), 'header', setProperty(variables('Envelope')?['header'], 'routingSlip', variables('NewEnvelope')?['header']?['routingSlip']))"
                                        },
                                        "MergeProperties:_Update_Scenario": {
                                            "runAfter": {
                                                "MergeProperties:_Merge_RoutingSlip": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "type": "Compose",
                                            "inputs": "@setProperty(outputs('MergeProperties:_Merge_RoutingSlip'), 'header', setProperty(outputs('MergeProperties:_Merge_RoutingSlip')?['header'], 'properties', setProperty(outputs('MergeProperties:_Merge_RoutingSlip')?['header']?['properties'], 'scenario', parameters('scenario'))))"
                                        },
                                        "MergeProperties:Success_Set_NewEnvelope_variable": {
                                            "runAfter": {
                                                "MergeProperties:_Update_Scenario": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "NewEnvelope",
                                                "value": "@outputs('MergeProperties:_Update_Scenario')"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "type": "Scope"
                                },
                                "MergeProperties:Failure:_Get_Failed_Items": {
                                    "runAfter": {
                                        "MergeProperties:_Exception_Scope": [
                                            "Failed",
                                            "TimedOut",
                                            "Skipped"
                                        ]
                                    },
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@result('MergeProperties:_Exception_Scope')",
                                        "where": "@or(equals(item()['status'], 'Failed'), equals(item()['status'], 'TimedOut'), equals(item()['status'], 'Skipped'))"
                                    }
                                },
                                "MergeProperties:Failure:_Set_ErrorMessage_variable": {
                                    "runAfter": {
                                        "MergeProperties:Failure:_Get_Failed_Items": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "ErrorMessage",
                                        "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) in an ExceptionScope. Error: Action: @{body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['name']}, StatusCode: @{body('MergeProperties:Failure:_Get_Failed_Items')?[0]?.outputs?['statusCode']}, Message: @{coalesce(body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['error']?['message'], body('MergeProperties:Failure:_Get_Failed_Items')?[0]?.outputs?['body']?['message'])}"
                                    }
                                },
                                "MergeProperties:Failure:_Create_Fault_Message": {
                                    "runAfter": {
                                        "MergeProperties:Failure:_Set_ErrorMessage_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "Compose",
                                    "inputs": {
                                        "fault": {
                                            "faultActor": "@concat(workflow()?['name'], '.', body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['name'], ' (', workflow()?['run']?['name'], ')')",
                                            "faultCategory": "Error",
                                            "faultCode": "@{coalesce(body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['outputs']?['statusCode'], body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['outputs']?['body']?['statusCode'], body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['error']?['code'])}",
                                            "faultMessage": "@{coalesce(body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['outputs']?['error']?['message'], body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['outputs']?['body']?['message'], body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['error']?['message'])}",
                                            "faultReason": "@{body('MergeProperties:Failure:_Get_Failed_Items')?[0]?['status']}"
                                        }
                                    }
                                },
                                "MergeProperties:Failure:_Set_FaultMessage_variable": {
                                    "runAfter": {
                                        "MergeProperties:Failure:_Create_Fault_Message": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "FaultMessage",
                                        "value": "@outputs('MergeProperties:Failure:_Create_Fault_Message')"
                                    }
                                },
                                "MergeProperties:Success:_Set_Checkpoint_variable": {
                                    "runAfter": {
                                        "MergeProperties:_Exception_Scope": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "Checkpoint",
                                        "value": "MergeProperties"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Build_New_Envelope": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "BuildNewEnvelope"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "$connections": {
                        "value": {
                            "servicebussubscribe": {
                                "connectionId": "[variables('serviceBusTopicSubscribeApiConnectionResourceId')]",
                                "connectionName": "[parameters('serviceBusTopicSubscribeApiConnectionName')]",
                                "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', resourceGroup().location, '/managedApis/servicebus')]"
                            }
                        }
                    },
                    "serviceBusTopicName": {
                        "value": "[parameters('serviceBusTopicName')]"
                    },
                    "serviceBusTopicSubscriptionName": {
                        "value": "[parameters('serviceBusTopicSubscriptionName')]"
                    },
                    "serviceBusRecurrenceFrequency": {
                        "value": "[parameters('serviceBusRecurrenceFrequency')]"
                    },
                    "serviceBusRecurrenceInterval": {
                        "value": "[parameters('serviceBusRecurrenceInterval')]"
                    },
                    "scenario": {
                        "value": "[parameters('scenario')]"
                    },
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    },
                    "suspendQueueTopicName": {
                        "value": "[parameters('suspendQueueTopicName')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\topicsubscriber\topicsubscriber.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\xmlenvelopewrapper\Deploy-85-XmlEnvelopeWrapper-LogicApp.ps1.liquid
 
tools\templates\intermediaries\topicpublisher\topicpublisher.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\topicpublisher\topicpublisher.apiconnection.prod.parameters.json.liquid
 
tools\templates\intermediaries\topicpublisher\topicpublisher.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "serviceBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that contains the Azure Service Bus resource."
            }
        },
        "serviceBusNamespaceName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Namespace this API Connection connects to)."
            }
        },
        "serviceBusPolicyName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Policy this API Connection connects to)."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'servicebus')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "connectionString": "[listKeys(resourceId(parameters('serviceBusResourceGroupName'), 'Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('serviceBusNamespaceName'), parameters('serviceBusPolicyName')), '2017-04-01').primaryConnectionString]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\intermediaries\topicpublisher\New-TopicPublisher-ApiConnection.ps1
<#
.SYNOPSIS
Creates an API connection resource for the topic publisher.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-TopicPublisher-ApiConnection.ps1 -resourceGroupName "sb-aimmsgbox-dev-uksouth-xxxxx" -templateFile ".\topicpublisher.apiconnection.json" -templateParameterFile ".\topicpublisher.apiconnection.dev.parameters.json" -deploymentName "topicpublisher.apiconnection.xxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Deploying the topic publisher api connection`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"
tools\templates\intermediaries\topicpublisher\Deploy-95-TopicPublisher-LogicApp.ps1.liquid
 
tools\templates\intermediaries\topicpublisher\Deploy-90-TopicPublisher-ApiConnection.ps1.liquid
 
tools\templates\intermediaries\processmanager\TearDown-105-ProcessManager-LogicApp.ps1.liquid
 
tools\templates\intermediaries\processmanager\TearDown-100-ProcessManagerServiceBus-ApiConnection.ps1.liquid
 
tools\templates\intermediaries\processmanager\snippets\invokable\processmanager.workflowdefinition.snippet.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {},
                    "triggers": {},
                    "actions": {},
                    "outputs": {}
                },
                "parameters": {}
            }
        }
    ]
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.routingsliprouterretrypolicy.snippet.json
{
    "armTemplateParameter": {
        "routerRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.routingsliprouterlogicapp.snippet.json
{
    "armParameter": {
        "routingSlipRouterLogicAppName": {
            "value": "{{ resource_template.parameters.routing_slip_router_name }}"
        }
    },
    "armTemplateParameter": {
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.messagesuspendprocessorlogicapp.snippet.json
{
    "armParameter": {
        "messageSuspendProcessorLogicAppName": {
            "value": "{{ resource_template.parameters.azure_message_suspend_processor_logic_app_name }}"
        }
    },
    "armTemplateParameter": {
        "messageSuspendProcessorLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to handle failed messages."
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.messagebusresourcegroup.snippet.json
{
    "armParameter": {
        "messageBusResourceGroupName": {
            "value": "{{ resource_template.parameters.azure_message_bus_resource_group_name }}"
        }
    },
    "armTemplateParameter": {
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the resource group that MessageBus artifacts are deployed to."
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.integrationaccount.snippet.json
{
    "armParameter": {
        "integrationAccountName": {
            "value": "{{ resource_template.parameters.azure_integration_account_name }}"
        }
    },
    "armTemplateParameter": {
        "integrationAccountName": {
            "type": "String",
            "metadata": {
                "description": "Name of the integration account for the MessageBus."
            }
        }
    }
}
tools\templates\intermediaries\processmanager\snippets\common\processmanager.parameter.apimsubscriptionkey.snippet.json
{
    "armTemplateParameter": {
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access the Message Bus API Management service."
            }
        }
    },
    "workflowParameter": {
        "apimSubscriptionKey": {
            "value": "[parameters('apimSubscriptionKey')]"
        }
    },
    "workflowDefinitionParameter": {
        "apimSubscriptionKey": {
            "type": "SecureString",
            "description": "Subscription Key used to access the Message Bus API Management service."
        }
    }
}
tools\templates\intermediaries\topicsubscriber\Remove-TopicSubscriber-LogicApp.ps1
<#
.SYNOPSIS
Tears down the topic subscriber Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-TopicSubscriber-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimtopicpublisher-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\topicsubscriber\TearDown-100-TopicSubscriber-ApiConnection.ps1.liquid
 
tools\templates\intermediaries\xmlmessagetranslator\xmlmessagetranslator.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\xmlmessagetranslator\xmlmessagetranslator.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "String",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "xmlMessageTranslator",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. xmlMessageTranslator."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. xmlMessageTranslator."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_MessageType_variable": {
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "MessageType",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_MapName_variable": {
                            "runAfter": {
                                "Initialize_MessageType_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "MapName",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_TransformedContent_variable": {
                            "runAfter": {
                                "Initialize_MapName_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "TransformedContent",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Update_MessageType": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SkipXmlTranslation"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "UpdateMessageType"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_TransformedContent_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_MapName": {
                            "actions": {
                                "GetMapName:_Filter_Maps_Array": {
                                    "inputs": {
                                        "from": "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['maps'], array(''))",
                                        "where": "@equals(item()?['messageType'], coalesce(variables('Envelope')?['header']?['properties']?['btsMessageType'], '(undefined)'))"
                                    },
                                    "runAfter": {},
                                    "type": "Query"
                                },
                                "GetMapName:_Set_MapName_variable": {
                                    "inputs": {
                                        "name": "MapName",
                                        "value": "@if(equals(length(body('GetMapName:_Filter_Maps_Array')), 1), body('GetMapName:_Filter_Maps_Array')?[0]?['mapName'], '')"
                                    },
                                    "runAfter": {
                                        "GetMapName:_Filter_Maps_Array": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable"
                                },
                                "GetMapName:Success:_Set_Checkpoint_variable": {
                                    "runAfter": {
                                        "GetMapName:_Set_MapName_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "Checkpoint",
                                        "value": "GetMapName"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_MapName": {
                            "actions": {
                                "CheckMapName:_Is_MapName_blank": {
                                    "actions": {
                                        "CheckMapName:MapNameBlank:_Allow_unrecognized_MessageType": {
                                            "actions": {
                                                "CheckMapName:MapNameBlank:SKipXmlTranslation:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "SkipXmlTranslation"
                                                    }
                                                }
                                            },
                                            "runAfter": {},
                                            "else": {
                                                "actions": {
                                                    "CheckMapName:Failure:_Set_ErrorMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): Unable to find a Map for the current MessageType for this envelope, and the allowUnrecognizedMessages config value is set to False. MessageType is: '@{coalesce(variables('Envelope')?['properties']?['btsMessageType'], '(undefined)')}'."
                                                        }
                                                    }
                                                }
                                            },
                                            "expression": {
                                                "and": [
                                                    {
                                                        "equals": [
                                                            "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['allowUnrecognizedMessages'], true)",
                                                            true
                                                        ]
                                                    }
                                                ]
                                            },
                                            "type": "If"
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "CheckMapName:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "PerformXmlTranslation"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@{coalesce(variables('MapName'), '')}",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_MapName": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetMapName"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Failure:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): No Root Body content can be found in the supplied Envelope"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_MapName": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "PerformXmlTranslation"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Transform_Xml": {
                            "actions": {
                                "TransformXml:Failure:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "TransformXml:_Transform_Xml": [
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 500
                                    }
                                },
                                "TransformXml:Success:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "TransformXml:_Transform_Xml": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 200
                                    }
                                },
                                "TransformXml:_Check_StatusCode": {
                                    "runAfter": {
                                        "TransformXml:Failure:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ],
                                        "TransformXml:Success:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "TransformXml:Success:_Set_TransformedContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "TransformedContent",
                                                        "value": "@body('TransformXml:_Transform_Xml')"
                                                    }
                                                },
                                                "TransformXml:Success:_Add_new_Root_Body_Part_to_Envelope": {
                                                    "runAfter": {
                                                        "TransformXml:Success:_Remove_existing_Root_Body_Part_from_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": "@setProperty(variables('Envelope'), 'body', union(outputs('TransformXml:Success:_Remove_existing_Root_Body_Part_from_Envelope')?['body'], array(outputs('TransformXml:Success:_Create_new_Body_Part'))))"
                                                },
                                                "TransformXml:Success:_Create_new_Body_Part": {
                                                    "runAfter": {
                                                        "TransformXml:Success:_Set_TransformedContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": {
                                                        "$content": "@base64(variables('TransformedContent'))",
                                                        "$contentTransferEncoding": "base64",
                                                        "$contentType": "application/xml",
                                                        "$part": "@variables('Envelope')?['header']?['properties']?['rootPart']",
                                                        "$partType": "http://schemas.myorg.com/part@{variables('Envelope')?['header']?['properties']?['rootPart']}#root"
                                                    }
                                                },
                                                "TransformXml:Success:_Remove_existing_Root_Body_Part_from_Envelope": {
                                                    "runAfter": {
                                                        "TransformXml:Success:_Create_new_Body_Part": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Query",
                                                    "inputs": {
                                                        "from": "@variables('Envelope')?['body']",
                                                        "where": "@not(equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart']))"
                                                    }
                                                },
                                                "TransformXml:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "TransformXml:Success:_Update_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "TransformXml"
                                                    }
                                                },
                                                "TransformXml:Success:_Update_Envelope_variable": {
                                                    "runAfter": {
                                                        "TransformXml:Success:_Add_new_Root_Body_Part_to_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@outputs('TransformXml:Success:_Add_new_Root_Body_Part_to_Envelope')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "TransformXml:Failure:_Create_Fault_message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "fault": {
                                                        "faultActor": "@concat(workflow()?['name'], '.', actions('TransformXml:_Transform_Xml')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                        "faultCategory": "Error",
                                                        "faultCode": "@{coalesce(outputs('TransformXml:_Transform_Xml')?['statusCode'], outputs('TransformXml:_Transform_Xml')?['body']?['statusCode'], actions('TransformXml:_Transform_Xml')?['error']?['code'])}",
                                                        "faultMessage": "@{coalesce(outputs('TransformXml:_Transform_Xml')?['error']?['message'], outputs('TransformXml:_Transform_Xml')?['body']?['message'], actions('TransformXml:_Transform_Xml')?['error']?['message'])}",
                                                        "faultReason": "@{actions('TransformXml:_Transform_Xml')?['status']}"
                                                    }
                                                }
                                            },
                                            "TransformXml:Failure:_Set_ErrorMessage_variable": {
                                                "runAfter": {
                                                    "TransformXml:Failure:_Set_FaultMessage_variable": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to transform Xml"
                                                }
                                            },
                                            "TransformXml:Failure:_Set_FaultMessage_variable": {
                                                "runAfter": {
                                                    "TransformXml:Failure:_Create_Fault_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "FaultMessage",
                                                    "value": "@outputs('TransformXml:Failure:_Create_Fault_message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "TransformXml:_Transform_Xml": {
                                    "runAfter": {},
                                    "type": "Xslt",
                                    "inputs": {
                                        "content": "@variables('BodyContent')",
                                        "integrationAccount": {
                                            "map": {
                                                "name": "@{coalesce(variables('MapName'), '')}"
                                            }
                                        },
                                        "transformOptions": "ApplyXsltOutputAttributes"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Update_MessageType": {
                            "actions": {
                                "UpdateMessageType:_Set_MessageType_variable": {
                                    "runAfter": {},
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "MessageType",
                                        "value": "@{coalesce(xpath(xml(variables('TransformedContent')), 'namespace-uri(/*)'), '')}#@{coalesce(xpath(xml(variables('TransformedContent')), 'local-name(/*)'), '')}"
                                    }
                                },
                                "UpdateMessageType:Failure:_Set_ErrorMessage_variable": {
                                    "runAfter": {
                                        "UpdateMessageType:_Set_MessageType_variable": [
                                            "Failed",
                                            "TimedOut",
                                            "Skipped"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "ErrorMessage",
                                        "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to update the MessageType: @{coalesce(outputs('UpdateMessageType:_Set_MessageType_variable')?['error']?['message'], actions('UpdateMessageType:_Set_MessageType_variable')?['error']?['message'], '(unknown error)')}"
                                    }
                                },
                                "UpdateMessageType:Success:_Update_Properties": {
                                    "runAfter": {
                                        "UpdateMessageType:_Set_MessageType_variable": [
                                            "Succeeded"
                                        ]

                                    },
                                    "type": "Compose",
                                    "inputs": "@setProperty(variables('Envelope'), 'header', setProperty(variables('Envelope')?['header'], 'properties', setProperty(variables('Envelope')?['header']?['properties'], 'btsMessageType', variables('MessageType'))))"
                                },
                                "UpdateMessageType:Success:_Update_Routing": {
                                    "runAfter": {
                                        "UpdateMessageType:Success:_Update_Properties": [
                                            "Succeeded"
                                        ]

                                    },
                                    "type": "Compose",
                                    "inputs": "@setProperty(outputs('UpdateMessageType:Success:_Update_Properties'), 'header', setProperty(outputs('UpdateMessageType:Success:_Update_Properties')?['header'], 'routing', setProperty(outputs('UpdateMessageType:Success:_Update_Properties')?['header']?['routing'], 'btsMessageType', variables('MessageType'))))"
                                },
                                "UpdateMessageType:Success:_Set_Envelope_variable": {
                                    "runAfter": {
                                        "UpdateMessageType:Success:_Update_Routing": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "Envelope",
                                        "value": "@outputs('UpdateMessageType:Success:_Update_Routing')"
                                    }
                                },
                                "UpdateMessageType:Success:_Set_Checkpoint_variable": {
                                    "runAfter": {
                                        "UpdateMessageType:Success:_Set_Envelope_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "Checkpoint",
                                        "value": "UpdateMessageType"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Transform_Xml": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "TransformXml"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\xmlmessagetranslator\xmlmessagetranslator.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\xmlmessagevalidator\Deploy-85-XmlMessageValidator-LogicApp.ps1.liquid
 
tools\templates\intermediaries\xmlmessagevalidator\New-XmlMessageValidator-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-XmlMessageValidator-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\xmlmessagevalidator.logicapp.json" -templateParameterFile ".\xmlmessagevalidator.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "xmlmessagevalidator.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName    
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the xml message validator Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\xmlmessagevalidator\Remove-XmlMessageValidator-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-XmlMessageValidator-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-xmlmessagevalidator-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\xmlmessagevalidator\TearDown-85-XmlMessageValidator-LogicApp.ps1.liquid
 
tools\templates\intermediaries\xmlmessagevalidator\xmlmessagevalidator.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\xmlmessagevalidator\xmlmessagevalidator.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "String",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "xmlMessageTranslator",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. xmlMessageTranslator."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. xmlMessageTranslator."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_SchemaName_variable": {
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "SchemaName",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Validate_Xml": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ValidateXml"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SkipXmlValidation"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_SchemaName_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_MessageType": {
                            "actions": {
                                "CheckMessageType:_Is_MessageType_blank": {
                                    "actions": {
                                        "CheckMessageType:Failure:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): Unable to find a btsMessageType property for this envelope."
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "CheckMessageType:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckMessageType"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@{coalesce(variables('Envelope')?['header']?['properties']?['btsMessageType'], '')}",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_SchemaName": {
                            "actions": {
                                "GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "messageType": "@{encodeUriComponent(coalesce(variables('Envelope')?['header']?['properties']?['btsMessageType'], '(undefined)'))}"
                                            },
                                            "template": "/aimconfigurationmanager/schemabymessagetype/{messageType}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['clearCache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetSchemaName:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetSchemaName:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetSchemaName:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetSchemaName:Success:_Set_SchemaName_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetSchemaName"
                                                    }
                                                },
                                                "GetSchemaName:Success:_Set_SchemaName_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "SchemaName",
                                                        "value": "@body('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['schemaName']"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetSchemaName:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetSchemaName:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetSchemaName:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetSchemaNameByMessageType operation"
                                                        }
                                                    },
                                                    "GetSchemaName:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetSchemaName:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['statusCode'], outputs('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['body']?['statusCode'], actions('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['error']?['message'], outputs('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['body']?['message'], actions('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetSchemaName:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetSchemaName:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetSchemaNameByMessageType operation"
                                                            }
                                                        },
                                                        "GetSchemaName:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetSchemaName:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetSchemaName:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetSchemaName:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetSchemaName:_Call_APIM_ConfigurationManager.GetSchemaNameByMessageType')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_MessageType": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckMessageType"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_SchemaName": {
                            "actions": {
                                "CheckSchemaName:_Is_SchemaName_blank": {
                                    "actions": {
                                        "CheckSchemaName:SchemaNameBlank:_Allow_unrecognized_MessageType": {
                                            "actions": {
                                                "CheckMapName:MapNameBlank:SKipXmlTranslation:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "SkipXmlValidation"
                                                    }
                                                }
                                            },
                                            "runAfter": {},
                                            "else": {
                                                "actions": {
                                                    "CheckSchemaName:Failure:_Set_ErrorMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): Unable to find a Schema for the current MessageType for this envelope, and the allowUnrecognizedMessages config value is set to False. MessageType is: '@{coalesce(variables('Envelope')?['properties']?['btsMessageType'], '(undefined)')}'."
                                                        }
                                                    }
                                                }
                                            },
                                            "expression": {
                                                "and": [
                                                    {
                                                        "equals": [
                                                            "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['allowUnrecognizedMessages'], true)",
                                                            true
                                                        ]
                                                    }
                                                ]
                                            },
                                            "type": "If"
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "CheckSchemaName:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "PerformXmlValidation"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@{coalesce(variables('SchemaName'), '')}",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_SchemaName": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetSchemaName"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Failure:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): No Root Body content can be found in the supplied Envelope"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_SchemaName": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "PerformXmlValidation"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Validate_Xml": {
                            "actions": {
                                "ValidateXml:Failure:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ValidateXml:_Validate_Xml": [
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 500
                                    }
                                },
                                "ValidateXml:Success:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "ValidateXml:_Validate_Xml": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": 200
                                    }
                                },
                                "ValidateXml:_Check_StatusCode": {
                                    "runAfter": {
                                        "ValidateXml:Failure:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ],
                                        "ValidateXml:Success:_Set_StatusCode_variable": [
                                            "Succeeded",
                                            "Skipped"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "ValidateXml:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "ValidateXml"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "ValidateXml:Failure:_Create_Fault_message": {
                                                "runAfter": {},
                                                "type": "Compose",
                                                "inputs": {
                                                    "fault": {
                                                        "faultActor": "@concat(workflow()?['name'], '.', actions('ValidateXml:_Validate_Xml')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                        "faultCategory": "Error",
                                                        "faultCode": "@{coalesce(outputs('ValidateXml:_Validate_Xml')?['statusCode'], outputs('ValidateXml:_Validate_Xml')?['body']?['statusCode'], actions('ValidateXml:_Validate_Xml')?['error']?['code'])}",
                                                        "faultMessage": "@{coalesce(if(greater(length(outputs('ValidateXml:_Validate_Xml')?['errors']), 0), outputs('ValidateXml:_Validate_Xml')?['errors']?[0]?['message'], null), outputs('ValidateXml:_Validate_Xml')?['error']?['message'], outputs('ValidateXml:_Validate_Xml')?['body']?['message'], actions('ValidateXml:_Validate_Xml')?['error']?['message'])}",
                                                        "faultReason": "@{actions('ValidateXml:_Validate_Xml')?['status']}"
                                                    }
                                                }
                                            },
                                            "ValidateXml:Failure:_Set_ErrorMessage_variable": {
                                                "runAfter": {
                                                    "ValidateXml:Failure:_Set_FaultMessage_variable": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to validate XML"
                                                }
                                            },
                                            "ValidateXml:Failure:_Set_FaultMessage_variable": {
                                                "runAfter": {
                                                    "ValidateXml:Failure:_Create_Fault_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "FaultMessage",
                                                    "value": "@outputs('ValidateXml:Failure:_Create_Fault_message')"
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "ValidateXml:_Validate_Xml": {
                                    "runAfter": {},
                                    "type": "XmlValidation",
                                    "inputs": {
                                        "content": "@variables('BodyContent')",
                                        "integrationAccount": {
                                            "schema": {
                                                "name": "@{coalesce(variables('SchemaName'), '')}"
                                            }
                                        }
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\xmlmessagevalidator\xmlmessagevalidator.logicapp.prod.parameters.json.liquid
 
tools\templates\LICENSE
 
tools\templates\messagebus\artifactstore\artifactstore.dev.parameters.json.liquid
 
tools\templates\messagebus\artifactstore\artifactstore.json.liquid
 
tools\templates\messagebus\artifactstore\artifactstore.prod.parameters.json.liquid
 
tools\templates\messagebus\artifactstore\Deploy-20-ArtifactStore.ps1.liquid
 
tools\templates\messagebus\artifactstore\New-ArtifactStore.ps1.liquid
 
tools\templates\messagebus\artifactstore\Remove-ArtifactStore.ps1.liquid
 
tools\templates\messagebus\artifactstore\TearDown-20-ArtifactStore.ps1.liquid
 
tools\templates\messagebus\configmanager\configmanager.apim.dev.parameters.json.liquid
 
tools\templates\messagebus\configmanager\configmanager.apim.json.liquid
 
tools\templates\messagebus\configmanager\configmanager.apim.prod.parameters.json.liquid
 
tools\templates\messagebus\configmanager\Deploy-40-ConfigManager-ApiManagement.ps1.liquid
 
tools\templates\messagebus\configmanager\New-ConfigManager-ApiManagement.ps1
<#
.SYNOPSIS
Creates an API resource in API Management for the configuration manager.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the API Management service is located.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER apimServiceName
The name of the API Management service.

.PARAMETER apiName
The name of the API being deployed.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-ConfigManager-ApiManagement.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -apimServiceName "apim-aimmsgbussvc-dev" -apiName "aimconfigurationmanager" -templateFile ".\configmanager.apim.json" -templateParameterFile ".\configmanager.apim.dev.parameters" -deploymentName "configmanager.apim"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $apimServiceName,
    [parameter(Mandatory = $true)]
    [string] $apiName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

Write-Host "Deploying the API for the configuration manager`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"

Write-Host "Associating the API Management service $apimServiceName products to the API $apiName"

$products = az rest -m GET -u https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$apimServiceName/products?api-version=2018-01-01 | ConvertFrom-Json | Select-Object -ExpandProperty value

if ($products) {
    Write-Host "Found products for API Management service $apimServiceName"

    ForEach ($product in $products) {
        $productName = $product.name

        Write-Host "Associating product $productName with the configuration manager API"

        # PowerShell doesn't like variable expansion when a ? follows the variable
        $url = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$apimServiceName/products/$productName/apis/" + $apiName + "?api-version=2018-01-01"
		
        az rest -m PUT -u $url
    }
}
else {
    throw "Failed to get products for API Management service $apimServiceName"
}
tools\templates\messagebus\configmanager\Remove-ConfigManager-ApiManagement.ps1
<#
.SYNOPSIS
Tears down the API resource in API Management for the configuration manager.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER serviceName
The name of the API Management service to find the resource.

.PARAMETER apiName
The name of the API resource in API Management to remove.

.EXAMPLE
./Remove-ConfigManager-ApiManagement.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -serviceName "apim-aimmsgbussvc-dev" -apiName "aimconfigurationmanager"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $serviceName,
    [parameter(Mandatory = $true)]
    [string] $apiName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $apiName --namespace "Microsoft.ApiManagement" --parent "service/$serviceName" --resource-type "apis"

if ($resourceExists) {
    Write-Host "Removing the API resource for service $serviceName : $apiName"

    az resource delete --resource-group $resourceGroupName --name $apiName --namespace "Microsoft.ApiManagement" --parent "service/$serviceName" --resource-type "apis"

    Write-Host "Removed the API resource for service $serviceName : $apiName"
}
else {
    Write-Host "The API resource $apiName for service $serviceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\configmanager\TearDown-40-ConfigManager-ApiManagement.ps1.liquid
 
tools\templates\messagebus\messagebusgroup\Deploy-10-MessageBusGroup.ps1.liquid
 
tools\templates\messagebus\messagebusgroup\messagebusgroup.dev.parameters.json.liquid
 
tools\templates\messagebus\messagebusgroup\messagebusgroup.json.liquid
 
tools\templates\messagebus\messagebusgroup\messagebusgroup.prod.parameters.json.liquid
 
tools\templates\messagebus\messagebusgroup\New-MessageBusGroup.ps1.liquid
 
tools\templates\messagebus\messagebusgroup\Remove-MessageBusGroup.ps1.liquid
 
tools\templates\messagebus\messagebusgroup\TearDown-10-MessageBusGroup.ps1.liquid
 
tools\templates\intermediaries\topicsubscriber\TearDown-105-TopicSubscriber-LogicApp.ps1.liquid
 
tools\templates\intermediaries\topicsubscriber\topicsubscriber.apiconnection.dev.parameters.json.liquid
 
tools\templates\intermediaries\topicsubscriber\topicsubscriber.apiconnection.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apiConnectionName": {
            "type": "string",
            "metadata": {
                "description": "Resource Name of the API Connection"
            }
        },
        "apiConnectionDisplayName": {
            "type": "string",
            "defaultValue": "[parameters('apiConnectionName')]",
            "metadata": {
                "description": "Display Name of the API Connection"
            }
        },
        "apiConnectionLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "serviceBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that contains the Azure Service Bus resource."
            }
        },
        "serviceBusNamespaceName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Namespace this API Connection connects to."
            }
        },
        "serviceBusPolicyName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ServiceBus Policy this API Connection connects to."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {},
    "resources": [
        {
            "type": "Microsoft.Web/connections",
            "apiVersion": "2016-06-01",
            "name": "[parameters('apiConnectionName')]",
            "location": "[parameters('apiConnectionLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "api": {
                    "id": "[concat(subscription().id, '/providers/Microsoft.Web/locations/', parameters('apiConnectionLocation'), '/managedApis/', 'servicebus')]"
                },
                "displayName": "[parameters('apiConnectionDisplayName')]",
                "parameterValues": {
                    "connectionString": "[listKeys(resourceId(parameters('serviceBusResourceGroupName'), 'Microsoft.ServiceBus/namespaces/AuthorizationRules', parameters('serviceBusNamespaceName'), parameters('serviceBusPolicyName')), '2017-04-01').primaryConnectionString]"
                }
            }
        }
    ],
    "outputs": {}
}
tools\templates\intermediaries\topicpublisher\topicpublisher.apiconnection.dev.parameters.json.liquid
 
tools\templates\intermediaries\topicpublisher\TearDown-95-TopicPublisher-LogicApp.ps1.liquid
 
tools\templates\intermediaries\topicpublisher\TearDown-90-TopicPublisher-ApiConnection.ps1.liquid
 
tools\templates\intermediaries\topicpublisher\Remove-TopicPublisher-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-TopicPublisher-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-aimtopicpublisher-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\xmlmessagetranslator\TearDown-85-XmlMessageTranslator-LogicApp.ps1.liquid
 
tools\templates\intermediaries\xmlenvelopewrapper\New-XmlEnvelopeWrapper-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-XmlEnvelopeWrapper-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\xmlenvelopewrapper.logicapp.json" -templateParameterFile ".\xmlenvelopewrapper.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "xmlenvelopewrapper.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName    
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the xml message processor Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\xmlenvelopewrapper\Remove-XmlEnvelopeWrapper-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-XmlEnvelopeWrapper-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-xmlenvelopewrapper-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\xmlenvelopewrapper\TearDown-85-XmlEnvelopeWrapper-LogicApp.ps1.liquid
 
tools\templates\intermediaries\xmlenvelopewrapper\xmlenvelopewrapper.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\xmlenvelopewrapper\xmlenvelopewrapper.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "String",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "xmlMessageProcessor",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. xmlMessageProcessor."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. xmlMessageProcessor."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_UpdatedBodyContent_variable": {
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "UpdatedBodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_WrapXmlEnvelope": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "WrapXmlEnvelope"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SkipXmlWrapping"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_UpdatedBodyContent_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Validate_Configuration": {
                            "actions": {
                                "ValidateConfiguration:_Have_Valid_Properties": {
                                    "actions": {
                                        "ValidateConfiguration:Success:_Set_Checkpoint_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "ValidateConfiguration"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "ValidateConfiguration:Failure:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "ErrorMessage",
                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): property envelopeSpecNames is not set in configuration"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "not": {
                                                    "equals": [
                                                        "@coalesce(variables('Configuration')?[parameters('scenarioStep')]?['envelopeSpecNames'], '')",
                                                        ""
                                                    ]
                                                }
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_MessageType": {
                            "actions": {
                                "CheckMessageType:_Is_MessageType_blank": {
                                    "actions": {
                                        "CheckMessageType:Failure:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): Unable to find a btsMessageType property for this envelope."
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "CheckMessageType:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckMessageType"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@{coalesce(variables('Envelope')?['header']?['properties']?['btsMessageType'], '')}",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Validate_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ValidateConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Failure:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): No Root Body content can be found in the supplied Envelope"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_MessageType": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckMessageType"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_WrapXmlEnvelope": {
                            "actions": {
                                "WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('BodyContent')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/xml"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {
                                                "envelopeSpecNames": "@{coalesce(variables('Configuration')?[parameters('scenarioStep')]?['envelopeSpecNames'], '')}"
                                            },
                                            "template": "/aimroutingmanager/wrapxmlenvelope/{envelopeSpecNames}"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "WrapXmlEnvelope:_Check_Status_Code": {
                                    "runAfter": {
                                        "WrapXmlEnvelope:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "WrapXmlEnvelope:Success:_Set_UpdatedBodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "UpdatedBodyContent",
                                                        "value": "@body('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')"
                                                    }
                                                },
                                                "WrapXmlEnvelope:Success:_Create_new_Body_Part": {
                                                    "runAfter": {
                                                        "WrapXmlEnvelope:Success:_Set_UpdatedBodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": {
                                                        "$content": "@base64(variables('UpdatedBodyContent'))",
                                                        "$contentTransferEncoding": "base64",
                                                        "$contentType": "application/xml",
                                                        "$part": "@variables('Envelope')?['header']?['properties']?['rootPart']",
                                                        "$partType": "http://schemas.myorg.com/part@{variables('Envelope')?['header']?['properties']?['rootPart']}#root"
                                                    }
                                                },
                                                "WrapXmlEnvelope:Success:_Remove_existing_Root_Body_Part_from_Envelope": {
                                                    "runAfter": {
                                                        "WrapXmlEnvelope:Success:_Create_new_Body_Part": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Query",
                                                    "inputs": {
                                                        "from": "@variables('Envelope')?['body']",
                                                        "where": "@not(equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart']))"
                                                    }
                                                },
                                                "WrapXmlEnvelope:Success:_Add_new_Root_Body_Part_to_Envelope": {
                                                    "runAfter": {
                                                        "WrapXmlEnvelope:Success:_Remove_existing_Root_Body_Part_from_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "Compose",
                                                    "inputs": "@setProperty(variables('Envelope'), 'body', union(outputs('WrapXmlEnvelope:Success:_Remove_existing_Root_Body_Part_from_Envelope')?['body'], array(outputs('WrapXmlEnvelope:Success:_Create_new_Body_Part'))))"
                                                },
                                                "WrapXmlEnvelope:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "WrapXmlEnvelope:Success:_Update_Envelope_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "WrapXmlEnvelope"
                                                    }
                                                },
                                                "WrapXmlEnvelope:Success:_Update_Envelope_variable": {
                                                    "runAfter": {
                                                        "WrapXmlEnvelope:Success:_Add_new_Root_Body_Part_to_Envelope": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Envelope",
                                                        "value": "@outputs('WrapXmlEnvelope:Success:_Add_new_Root_Body_Part_to_Envelope')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "WrapXmlEnvelope:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "WrapXmlEnvelope:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "WrapXmlEnvelope:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessagingManager WrapXmlEnvelope operation"
                                                        }
                                                    },
                                                    "WrapXmlEnvelope:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "WrapXmlEnvelope:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['statusCode'], outputs('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['body']?['statusCode'], actions('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['error']?['message'], outputs('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['body']?['message'], actions('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "WrapXmlEnvelope:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "WrapXmlEnvelope:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessagingManager WrapXmlEnvelope operation"
                                                            }
                                                        },
                                                        "WrapXmlEnvelope:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "WrapXmlEnvelope:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('WrapXmlEnvelope:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "WrapXmlEnvelope:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('WrapXmlEnvelope:_Call_APIM_MessagingManager.WrapXmlEnvelope')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\xmlenvelopewrapper\xmlenvelopewrapper.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\xmlmessageprocessor\Deploy-85-XmlMessageProcessor-LogicApp.ps1.liquid
 
tools\templates\intermediaries\xmlmessageprocessor\New-XmlMessageProcessor-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-XmlMessageProcessor-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\xmlmessageprocessor.logicapp.json" -templateParameterFile ".\xmlmessageprocessor.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "xmlmessageprocessor.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName    
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the xml message processor Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\xmlmessageprocessor\Remove-XmlMessageProcessor-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-XmlMessageProcessor-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-xmlmessageprocessor-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\intermediaries\xmlmessageprocessor\TearDown-85-XmlMessageProcessor-LogicApp.ps1.liquid
 
tools\templates\intermediaries\xmlmessageprocessor\xmlmessageprocessor.logicapp.dev.parameters.json.liquid
 
tools\templates\intermediaries\xmlmessageprocessor\xmlmessageprocessor.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "defaultValue": "[resourceGroup().location]",
            "type": "string",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "metadata": {
                "description": "Name of the ResourceGroup that MessageBus artifacts are deployed to (e.g. APIM or RoutingSlipRouter LogicApp)."
            }
        },
        "integrationAccountName": {
            "type": "String",
            "metadata": {
                "description": "Name of the IntegrationAccount connected to this LogicApp."
            }
        },
        "routingSlipRouterLogicAppName": {
            "type": "string",
            "metadata": {
                "description": "Name of the LogicApp to call to route via the RoutingSlip."
            }
        },
        "routerRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling RoutingSlipRouter."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "type": "object",
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "xmlMessageProcessor",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. xmlMessageProcessor."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "messagingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimmessagingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]",
        "routingSlipRouterLogicAppResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/workflows', parameters('routingSlipRouterLogicAppName'))]",
        "integrationAccountResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.Logic/integrationAccounts', parameters('integrationAccountName'))]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "integrationAccount": {
                    "id": "[variables('integrationAccountResourceId')]"
                },
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. xmlMessageProcessor."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "triggerBody()?['header']?['properties']?['trackingId']"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_BodyContent_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "BodyContent",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_MessageType_variable": {
                            "runAfter": {
                                "Initialize_BodyContent_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "MessageType",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_Successful": {
                            "actions": {
                                "Routing:_Call_RoutingSlipRouter": {
                                    "runAfter": {},
                                    "type": "Workflow",
                                    "inputs": {
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "host": {
                                            "triggerName": "manual",
                                            "workflow": {
                                                "id": "[variables('routingSlipRouterLogicAppResourceId')]"
                                            }
                                        },
                                        "retryPolicy": "[parameters('routerRetryPolicy')]"
                                    }
                                },
                                "Routing:_Check_StatusCode": {
                                    "runAfter": {
                                        "Routing:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "Routing:Success:_Send_ACK-Content_response": {
                                                    "runAfter": {},
                                                    "type": "Response",
                                                    "kind": "Http",
                                                    "inputs": {
                                                        "body": "@body('Routing:_Call_RoutingSlipRouter')",
                                                        "headers": {
                                                            "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                            "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                            "Content-Type": "application/json"
                                                        },
                                                        "statusCode": 200
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "Routing:Error:_Build_NACK_message": {
                                                "runAfter": {
                                                    "Routing:Error:_Do_we_have_a_Fault_Message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Compose",
                                                "inputs": {
                                                    "body": [
                                                        {
                                                            "$content": {
                                                                "code": "500",
                                                                "message": "@variables('ErrorMessage')",
                                                                "lastCheckpoint": "@variables('Checkpoint')",
                                                                "fault": "@variables('FaultMessage')"
                                                            },
                                                            "$contentType": "application/json",
                                                            "$part": 1,
                                                            "$partType": "http://schemas.microsoft.com/aim#nack"
                                                        }
                                                    ],
                                                    "header": {
                                                        "properties": {
                                                            "createDate": "@utcNow()",
                                                            "envelopeType": "nack",
                                                            "messageId": "@guid()",
                                                            "rootPart": 1,
                                                            "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                        },
                                                        "routing": {
                                                            "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                        },
                                                        "routingSlip": {},
                                                        "state": {}
                                                    }
                                                }
                                            },
                                            "Routing:Error:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "Routing:Error:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "Routing:Error:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                        }
                                                    },
                                                    "Routing:Error:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('Routing:_Call_RoutingSlipRouter')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "Routing:Error:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('Routing:_Call_RoutingSlipRouter')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['statusCode'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['error']?['message'], outputs('Routing:_Call_RoutingSlipRouter')?['body']?['message'], actions('Routing:_Call_RoutingSlipRouter')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('Routing:_Call_RoutingSlipRouter')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the RoutingSlipRouter Logic App"
                                                            }
                                                        },
                                                        "Routing:Error:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "Routing:Error:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('Routing:Error:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('Routing:_Call_RoutingSlipRouter')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            },
                                            "Routing:Error:_Send_NACK_response": {
                                                "runAfter": {
                                                    "Routing:Error:_Build_NACK_message": [
                                                        "Succeeded"
                                                    ]
                                                },
                                                "type": "Response",
                                                "kind": "Http",
                                                "inputs": {
                                                    "body": "@outputs('Routing:Error:_Build_NACK_message')",
                                                    "headers": {
                                                        "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                        "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                        "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "Content-Type": "application/json"
                                                    },
                                                    "statusCode": 200
                                                }
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "Routing:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "Routing:_Call_RoutingSlipRouter": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('Routing:_Call_RoutingSlipRouter')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Set_MessageType": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                                "Aim-Enable-Trace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "SetMessageType"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_MessageType_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_BodyContent": {
                            "actions": {
                                "CheckBodyContent:_Body_Content_is_missing": {
                                    "actions": {
                                        "CheckBodyContent:Failure:_Set_ErrorMessage_variable": {
                                            "runAfter": {},
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ErrorMessage",
                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): No Root Body content can be found in the supplied Envelope"
                                            }
                                        }
                                    },
                                    "runAfter": {
                                        "CheckBodyContent:_Select_Root_Part": [
                                            "Succeeded"
                                        ]
                                    },
                                    "else": {
                                        "actions": {
                                            "CheckBodyContent:Success:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "CheckBodyContent"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "and": [
                                            {
                                                "equals": [
                                                    "@coalesce(body('CheckBodyContent:_Select_Root_Part')?[0]?['$content'], '')",
                                                    ""
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                },
                                "CheckBodyContent:_Select_Root_Part": {
                                    "runAfter": {},
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@variables('Envelope')?['body']",
                                        "where": "@equals(item()?['$part'], variables('Envelope')?['header']?['properties']?['rootPart'])"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_BodyContent": {
                            "actions": {
                                "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('messagingManagerApiResourceId')]"
                                        },
                                        "body": "@variables('Envelope')",
                                        "headers": {
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "method": "post",
                                        "pathTemplate": {
                                            "parameters": {},
                                            "template": "/aimmessagingmanager/getbodycontent"
                                        },
                                        "queries": {
                                            "clearCache": "@coalesce(variables('Configuration')?['globalConfig']?['clearCache'], 'false')",
                                            "enableTrace": "@coalesce(variables('Configuration')?['globalConfig']?['enableTrace'], 'false')"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetBodyContent:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetBodyContent:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetBodyContent:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetBodyContent:Success:_Set_BodyContent_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetBodyContent"
                                                    }
                                                },
                                                "GetBodyContent:Success:_Set_BodyContent_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "BodyContent",
                                                        "value": "@{base64ToString(body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['$content'])}"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetBodyContent:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetBodyContent:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetBodyContent:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                        }
                                                    },
                                                    "GetBodyContent:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetBodyContent:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['statusCode'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['statusCode'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'], outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['body']?['message'], actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager GetBodyContent operation"
                                                            }
                                                        },
                                                        "GetBodyContent:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetBodyContent:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetBodyContent:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetBodyContent:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetBodyContent:_Call_APIM_MessageManager.GetBodyContent": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetBodyContent:_Call_APIM_MessageManager.GetBodyContent')['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Check_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "CheckBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Set_MessageType": {
                            "actions": {
                                "SetMessageType:_Set_MessageType_variable": {
                                    "runAfter": {},
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "MessageType",
                                        "value": "@{coalesce(xpath(xml(variables('BodyContent')), 'namespace-uri(/*)'), '')}#@{coalesce(xpath(xml(variables('BodyContent')), 'local-name(/*)'), '')}"
                                    }
                                },
                                "SetMessageType:Failure:_Set_ErrorMessage_variable": {
                                    "runAfter": {
                                        "SetMessageType:_Set_MessageType_variable": [
                                            "Failed",
                                            "TimedOut",
                                            "Skipped"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "ErrorMessage",
                                        "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to get the MessageType: @{coalesce(outputs('SetMessageType:_Set_MessageType_variable')?['error']?['message'], actions('SetMessageType:_Set_MessageType_variable')?['error']?['message'], '(unknown error)')}"
                                    }
                                },
                                "SetMessageType:Success:_Update_Properties": {
                                    "runAfter": {
                                        "SetMessageType:_Set_MessageType_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "Compose",
                                    "inputs": "@setProperty(variables('Envelope'), 'header', setProperty(variables('Envelope')?['header'], 'properties', setProperty(variables('Envelope')?['header']?['properties'], 'btsMessageType', variables('MessageType'))))"
                                },
                                "SetMessageType:Success:_Update_Routing": {
                                    "runAfter": {
                                        "SetMessageType:Success:_Update_Properties": [
                                            "Succeeded"
                                        ]

                                    },
                                    "type": "Compose",
                                    "inputs": "@setProperty(outputs('SetMessageType:Success:_Update_Properties'), 'header', setProperty(outputs('SetMessageType:Success:_Update_Properties')?['header'], 'routing', setProperty(outputs('SetMessageType:Success:_Update_Properties')?['header']?['routing'], 'btsMessageType', variables('MessageType'))))"
                                },
                                "SetMessageType:Success:_Set_Envelope_variable": {
                                    "runAfter": {
                                        "SetMessageType:Success:_Update_Routing": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "Envelope",
                                        "value": "@outputs('SetMessageType:Success:_Update_Routing')"
                                    }
                                },
                                "SetMessageType:Success:_Set_Checkpoint_variable": {
                                    "runAfter": {
                                        "SetMessageType:Success:_Set_Envelope_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "Checkpoint",
                                        "value": "SetMessageType"
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Get_BodyContent": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetBodyContent"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\intermediaries\xmlmessageprocessor\xmlmessageprocessor.logicapp.prod.parameters.json.liquid
 
tools\templates\intermediaries\xmlmessagetranslator\Deploy-85-XmlMessageTranslator-LogicApp.ps1.liquid
 
tools\templates\intermediaries\xmlmessagetranslator\New-XmlMessageTranslator-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
.\New-XmlMessageTranslator-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\xmlmessagetranslator.logicapp.json" -templateParameterFile ".\xmlmessagetranslator.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "xmlmessagetranslator.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName    
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the xml message translator Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --parameters "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName 

Write-Host "Deployment complete"
tools\templates\intermediaries\xmlmessagetranslator\Remove-XmlMessageTranslator-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
.\Remove-XmlMessageTranslator-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "logic-xmlmessagetranslator-dev-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\messagebusops\Deploy-20-MessageBusOps-AppInsights.ps1.liquid
 
tools\templates\messagebus\messagebusops\messagebusops.appi.dev.psparameters.json.liquid
 
tools\templates\messagebus\messagebusops\messagebusops.appi.prod.psparameters.json.liquid
 
tools\templates\messagebus\messagebusops\New-MessageBusOps-AppInsights.ps1.liquid
 
tools\templates\messagebus\messagebusops\Remove-MessageBusOps-AppInsights.ps1.liquid
 
tools\templates\messagebus\messagebusops\TearDown-20-MessageBusOps-AppInsights.ps1.liquid
 
tools\templates\messagebus\messagebusservice\Deploy-20-MessageBusService-StorageAccount.ps1.liquid
 
tools\templates\messagebus\messagebusservice\Deploy-30-MessageBusService-ApiManagement.ps1.liquid
 
tools\templates\messagebus\messagebusservice\Deploy-30-MessageBusService-AppService.ps1.liquid
 
tools\templates\messagebus\messagebusservice\Deploy-35-MessageBusService-ApiManagement-RoleAssignment.ps1.liquid
 
tools\templates\messagebus\messagebusservice\Deploy-5-MessageBusService-Role.ps1.liquid
 
tools\templates\messagebus\messagebusservice\messagebusservice.apim.dev.psparameters.json.liquid
 
tools\templates\messagebus\messagebusservice\messagebusservice.apim.prod.psparameters.json.liquid
 
tools\templates\messagebus\messagebusservice\messagebusservice.logicappsrole.json
{
    "Name": "Get Logic App Callback Url",
    "IsCustom": true,
    "Description": "Allows API Management to get the Logic App callback URL.",
    "Actions": [
        "Microsoft.Logic/workflows/triggers/listCallbackUrl/action",
        "Microsoft.Logic/workflows/listCallbackUrl/action"
    ],
    "DataActions": [
    ],
    "NotDataActions": [
    ],
    "AssignableScopes": [
        "/subscriptions/{subscriptionId}"
    ]
}
tools\templates\messagebus\messagebusservice\messagebusservice.plan.dev.parameters.json.liquid
 
tools\templates\messagebus\messagebusservice\messagebusservice.plan.json.liquid
 
tools\templates\messagebus\messagebusservice\messagebusservice.plan.prod.parameters.json.liquid
 
tools\templates\messagebus\messagebusservice\messagebusservice.st.dev.psparameters.json.liquid
 
tools\templates\messagebus\messagebusservice\messagebusservice.st.prod.psparameters.json.liquid
 
tools\templates\messagebus\messagebusservice\New-MessageBusService-ApiManagement-RoleAssignment.ps1
<#
.SYNOPSIS
Assigns a role to the specified resource group for the managed identity of the API Management service.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the resource group is located.

.PARAMETER resourceGroupName
Name of the resource group for the role assignment scope.

.PARAMETER name
Name of the API Management service that will be used for the role assignment.

.PARAMETER messageBusResourceGroupName
Name of the resource group where the API Management service is located.

.PARAMETER role
The role to assign to the resource group for the API Management service managed identity.

.EXAMPLE
./New-MessageBusService-ApiManagement-RoleAssignment.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -name "apim-aimmsgbussvc-dev" -messageBusResourceGroupName "rg-aimmsgbus-dev-uksouth" -role "Get Logic App Callback Url xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $name,
    [parameter(Mandatory = $true)]
    [string] $messageBusResourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $role
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

# --------------------------------------------------------------------------

Write-Host "Getting managed identity principal ID for API Management service $name"

$principalId = az apim show --name $name --resource-group $messageBusResourceGroupName | ConvertFrom-Json | Select-Object -ExpandProperty identity | Select-Object -ExpandProperty principalId

# Reset console colour because the show command breaks the colours and outputs black on black
[Console]::ResetColor()

if ($principalId) {
    Write-Host "Principal ID is $principalId"
}
else {
    throw "Unable to get managed identity principal ID for $name"
}

Write-Host "Adding role assignment for $principalId to role $role for resource group $resourceGroupName"

az role assignment create --assignee $principalId --role "$role" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName

Write-Host "Assigned managed identity of API Management service $name to $resourceGroupName"
tools\templates\messagebus\messagebusservice\New-MessageBusService-ApiManagement.ps1
<#
.SYNOPSIS
Creates an API Management resource for use by various AIM components.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the App Configuration service is located.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER name
Name of the API Management service that will be created.

.PARAMETER location
Location where the resource will be created.

.PARAMETER appConfigName
The name of the Azure App Configuration service.

.PARAMETER keyVaultName
The name of the Azure Key Vault service.

.PARAMETER publisherName
Name of the publisher organisation.

.PARAMETER publisherEmail
Email address that will receive emails from Azure when the service is published.

.PARAMETER sku
The SKU level for the API Management service.

.PARAMETER skuCapacity
The SKU capacity level for the API Management service.

.PARAMETER tags
The tags to apply to the API Management service.

.EXAMPLE
./New-MessageBusService-ApiManagement.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -name "apim-aimmsgbussvc-dev" -location "UK South" -appConfigName "appcfg-aimrstore-dev"  -keyVaultName "kv-aimrstore-dev" -publisherName "Microsoft" -publisherEmail "[email protected]"
./New-MessageBusService-ApiManagement.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -name "apim-aimmsgbussvc-dev" -location "UK South" -appConfigName "appcfg-aimrstore-dev"  -keyVaultName "kv-aimrstore-dev" -publisherName "Microsoft" -publisherEmail "[email protected]" -sku "Premium" -skuCapacity 5
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $name,
    [parameter(Mandatory = $true)]
    [string] $location,
    [parameter(Mandatory = $true)]
    [string] $appConfigName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $publisherName,
    [parameter(Mandatory = $true)]
    [string] $publisherEmail,
    [parameter(Mandatory = $false)]
    [string] $sku = "Developer",
    [parameter(Mandatory = $false)]
    [int] $skuCapacity = 1,
    [parameter(Mandatory = $false)]
    [string[]] $tags = ""
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

# --------------------------------------------------------------------------

Write-Host "Deploying the API management service"

az apim create --name $name --location $location --publisher-email $publisherEmail --publisher-name $publisherName --resource-group $resourceGroupName --sku-name $sku --sku-capacity $skuCapacity --tags $tags #--enable-managed-identity
if (!$?)
{
    # API Management is a global resource, so this may cause a failure if it already exists in
    # another subscription.
    throw "Deployment failed, aborting"
}

# Update apim instance to enable managed identities due to az CLI issue.
# https://github.com/Azure/azure-cli/issues/11614
az apim update --name $name --resource-group $resourceGroupName --enable-managed-identity

Write-Host "Deployment complete"

# --------------------------------------------------------------------------

Write-Host "Getting managed identity principal ID for API Management service $name"

$principalId = az apim show --name $name --resource-group $resourceGroupName | ConvertFrom-Json | Select-Object -ExpandProperty identity | Select-Object -ExpandProperty principalId

# Reset console colour because the show command breaks the colours and outputs black on black
[Console]::ResetColor()

if ($principalId) {
    Write-Host "Principal ID is $principalId"
}
else {
    throw "Unable to get managed identity principal ID for $name"
}

$role = "Contributor"

Write-Host "Adding role assignment for $principalId to role $role for App Configuration service $appConfigName"

az role assignment create --assignee $principalId --role "$role" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.AppConfiguration/configurationStores/$appConfigName

Write-Host "Assigned managed identity of API Management service $name to $appConfigName"

# --------------------------------------------------------------------------

Write-Host "Uploading product subscription keys for API Management service $name products to Key Vault $keyVaultName"

$products = az rest -m GET -u https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$name/products?api-version=2018-01-01 | ConvertFrom-Json | Select-Object -ExpandProperty value
$subscriptions = az rest -m GET -u https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$name/subscriptions?api-version=2018-01-01 | ConvertFrom-Json | Select-Object -ExpandProperty value | Select-Object -ExpandProperty properties

if ($products -and $subscriptions) {
    Write-Host "Found products and subscriptions for API Management service $name"

    ForEach ($product in $products)
    {
        $productName = $product.name
        $subscriptionKey = $null

        Write-Host "Finding subscription key for product $productName"

        ForEach ($subscription in $subscriptions)
        {
            if ($subscription.productId -eq $product.Id) {
                Write-Host "Found subscription key for product $productName"

                $subscriptionKey = $subscription.primaryKey

                Break
            }
        }

        if ($subscriptionKey) {
            Write-Host "Uploading subscription key for product $productName to Key Vault"

            az keyvault secret set --name "aim-apim-subscriptionkey-$productName" --vault-name $keyVaultName --value "$subscriptionKey"
        }
        else {
            throw "Failed to find subscription key for product $productName"
        }
    }
}
else {
    throw "Failed to get products and subscriptions for API Management service $name"
}
tools\templates\messagebus\messagebusservice\New-MessageBusService-AppService.ps1.liquid
 
tools\templates\messagebus\messagebusservice\New-MessageBusService-Role.ps1
<#
.SYNOPSIS
Creates a custom Role resource for use by API Management service.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the Key Vault service is located.

.EXAMPLE
./New-MessageBusService-Role.ps1 -subscriptionId "<azure-subs-id>" -role "Get Logic App Callback Url xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]
    [string] $role
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

# --------------------------------------------------------------------------

Write-Host "Load role definition and update subscription scope"

$roleDefinition = Get-Content -Raw -Path "$PSScriptRoot\messagebusservice.logicappsrole.json" | ConvertFrom-Json

if ($roleDefinition) {
    Write-Host "Updating role name to $role"

    $roleDefinition.Name = "$role"
    
    Write-Host "Updating subscription assignable scope to $subscriptionId"

    $roleDefinition.AssignableScopes[0] = "/subscriptions/$subscriptionId"
}
else {
    throw "Unable to load role definition"
}

Write-Host "Checking for existing role $role"

$resourceExists = az role definition list --name "$role" --custom-role-only true -o tsv

if ($resourceExists) {
    Write-Host "Updating the role $role"

    # When a command is invoked in PowerShell, there is a lot of removing of double quotes in strings when the command is
    # invoked.  There is also some weirdness around having spaces in values.  The replace calls escape the double quotes
    # and the spaces in the string, which allows it to work.  Key also is the -Compress on the ConvertTo-Json call so the
    # json is a single line string.
    az role definition update --role-definition ($roleDefinition | ConvertTo-Json -Compress).Replace('"', '\"').Replace(' ', '\u0020')
    if (!$?) {
        throw "Update failed, aborting"
    }

    Write-Host "Updated the role $role"
}
else {
    Write-Host "Deploying the role $role"

    # See above for comment on double quote and space escaping.
    az role definition create --role-definition ($roleDefinition | ConvertTo-Json -Compress).Replace('"', '\"').Replace(' ', '\u0020')
    if (!$?) {
        throw "Deployment failed, aborting"
    }
    
    Write-Host "Deployment complete"
}
tools\templates\messagebus\messagebusservice\New-MessageBusService-StorageAccount.ps1.liquid
 
tools\templates\messagebus\messagebusservice\Remove-MessageBusService-ApiManagement-RoleAssignment.ps1
<#
.SYNOPSIS
Removes a role assignment from the specified resource group for the managed identity of the API Management service.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the resource group is located.

.PARAMETER resourceGroupName
Name of the resource group for the role assignment scope.

.PARAMETER name
Name of the API Management service that will be used for the operation.

.PARAMETER messageBusResourceGroupName
Name of the resource group where the API Management service is located.

.PARAMETER role
The role to delete from the resource group for the API Management service managed identity.

.EXAMPLE
./Remove-MessageBusService-ApiManagement-RoleAssignment.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -name "apim-aimmsgbussvc-dev" -messageBusResourceGroupName "rg-aimmsgbus-dev-uksouth" -role "Get Logic App Callback Url xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $name,
    [parameter(Mandatory = $true)]
    [string] $messageBusResourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $role
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

# --------------------------------------------------------------------------

Write-Host "Getting managed identity principal ID for API Management service $name"

$principalId = az apim show --name $name --resource-group $messageBusResourceGroupName | ConvertFrom-Json | Select-Object -ExpandProperty identity | Select-Object -ExpandProperty principalId

# Reset console colour because the show command breaks the colours and outputs black on black
[Console]::ResetColor()

if ($principalId) {
    Write-Host "Principal ID is $principalId"
}
else {
    throw "Unable to get managed identity principal ID for $name"
}

Write-Host "Deleting role assignment for $principalId for role $role from resource group $resourceGroupName"

az role assignment delete --assignee $principalId --role "$role" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName --yes

Write-Host "Deleted managed identity of API Management service $name from $resourceGroupName"
tools\templates\messagebus\messagebusservice\Remove-MessageBusService-ApiManagement.ps1
<#
.SYNOPSIS
Tears down the API Management resource.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
./Remove-MessageBusService-ApiManagement.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -resourceName "apim-aimmsgbussvc-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az apim show --name $resourceName --resource-group $resourceGroupName

# Reset console colour because the show command breaks the colours and outputs black on black
[Console]::ResetColor()

if ($resourceExists) {
    Write-Host "Removing the API management resource: $resourceName"

    az apim delete --name $resourceName --resource-group $resourceGroupName --yes

    Write-Host "Removed the API management resource: $resourceName"
}
else {
    Write-Host "The API management resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\messagebusservice\Remove-MessageBusService-AppService.ps1.liquid
 
tools\templates\messagebus\messagebusservice\Remove-MessageBusService-Role.ps1
<#
.SYNOPSIS
Tears down the Role resource.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.EXAMPLE
./Remove-MessageBusService-Role.ps1 -role "Get Logic App Callback Url xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $role
)

$resourceExists = az role definition list --name "$role" --custom-role-only true

if ($resourceExists) {
    Write-Host "Removing the role $role"

    az role definition delete --name "$role"

    Write-Host "Removed the role $role"
}
else {
    Write-Host "The role $role does not exist in the subscription"
}
tools\templates\messagebus\messagebusservice\Remove-MessageBusService-StorageAccount.ps1.liquid
 
tools\templates\messagebus\messagebusservice\TearDown-20-MessageBusService-StorageAccount.ps1.liquid
 
tools\templates\messagebus\messagebusservice\TearDown-30-MessageBusService-ApiManagement.ps1.liquid
 
tools\templates\messagebus\messagebusservice\TearDown-30-MessageBusService-AppService.ps1.liquid
 
tools\templates\messagebus\messagebusservice\TearDown-35-MessageBusService-ApiManagement-RoleAssignment.ps1.liquid
 
tools\templates\messagebus\messagebusservice\TearDown-5-MessageBusService-Role.ps1.liquid
 
tools\templates\messagebus\messagingmanager\Deploy-50-MessagingManager-Function.ps1.liquid
 
tools\templates\messagebus\messagingmanager\Deploy-60-MessagingManager-ApiManagement.ps1.liquid
 
tools\templates\messagebus\messagingmanager\messagingmanager.apim.dev.parameters.json.liquid
 
tools\templates\messagebus\messagingmanager\messagingmanager.apim.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "apimServiceName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50
        },
        "apiName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 256,
            "defaultValue": "aimmessagingmanager"
        },
        "messagingManagerAppServiceName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 60
        }
    },
    "variables": {
        "apiTagName": "[concat(parameters('apiName'), 'tag')]"
    },
    "resources": [
        {
            "type": "Microsoft.ApiManagement/service/apis",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'))]",
            "dependsOn": [
            ],
            "properties": {
                "displayName": "Messaging Manager",
                "description": "AIM Message Manager API - handles creation and update of messages.",
                "apiRevision": "1",
                "subscriptionRequired": true,
                "path": "aimmessagingmanager",
                "protocols": [
                    "https"
                ],
                "isCurrent": true
            },
            "resources": [
            ]
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/tags",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/', variables('apiTagName'))]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/tags', parameters('apimServiceName'), variables('apiTagName'))]",
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/backends",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'))]",
            "dependsOn": [],
            "properties": {
                "description": "AIM Messaging Manager Function Backend",
                "url": "[concat('https://', parameters('messagingManagerAppServiceName'), '.azurewebsites.net/api')]",
                "protocol": "http",
                "resourceId": "[concat('https://management.azure.com', resourceId('Microsoft.Web/sites', parameters('messagingManagerAppServiceName')))]",
                "credentials": {
                    "header": {
                        "x-functions-key": [
                            "[listkeys(concat(resourceId('Microsoft.Web/sites/', parameters('messagingManagerAppServiceName')), '/host/default/'),'2016-08-01').functionKeys.apiManagement]"
                        ]
                    }
                }
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/buildenvelope')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "displayName": "BuildEnvelope",
                "description": "Builds an envelope using the supplied body.",
                "method": "POST",
                "urlTemplate": "/buildenvelope/{envelopeType}/{scenario}",
                "templateParameters": [
                    {
                        "name": "envelopeType",
                        "description": "Type of envelope to build.",
                        "type": "string",
                        "required": true,
                        "values": []
                    },
                    {
                        "name": "scenario",
                        "description": "Name of the scenario to build the envelope for.",
                        "type": "string",
                        "required": false,
                        "values": []
                    }
                ],
                "request": {
                    "description": "Body content to use for the envelope's root part.",
                    "queryParameters": [
                        {
                            "name": "clearCache",
                            "description": "If true, then any cached config is cleared, and config is retrieved from App Config again.",
                            "type": "bool",
                            "defaultValue": "false",
                            "values": [
                                "false",
                                "true"
                            ]
                        },
                        {
                            "name": "enableTrace",
                            "description": "If true, then an APIM trace URL is returned as a response header.",
                            "type": "bool",
                            "defaultValue": "false",
                            "values": [
                                "false",
                                "true"
                            ]
                        },
                        {
                            "name": "encodeBody",
                            "description": "If true, then body content is always encoded using Bse64.",
                            "type": "bool",
                            "defaultValue": "true",
                            "values": [
                                "false",
                                "true"
                            ]
                        }
                    ],
                    "headers": [
                        {
                            "name": "Content-Transfer-Encoding",
                            "description": "Transfer encoding used for the supplied body.",
                            "type": "string",
                            "required": false,
                            "defaultValue": "none",
                            "values": [
                                "none",
                                "base64"
                            ]
                        },
                        {
                            "name": "Aim-Tracking-Id",
                            "description": "Tracking ID used to link disparate messages together by AIM.",
                            "type": "string",
                            "required": false,
                            "defaultValue": ""
                        }
                    ],
                    "representations": [
                        {
                            "contentType": "text/plain"
                        },
                        {
                            "contentType": "text/json"
                        },
                        {
                            "contentType": "text/xml"
                        },
                        {
                            "contentType": "text/csv"
                        },
                        {
                            "contentType": "application/json"
                        },
                        {
                            "contentType": "application/xml"
                        }
                    ]
                },
                "responses": [
                    {
                        "statusCode": 200,
                        "description": "Have successfully built and returned an envelope message.",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n    \"header\": {\r\n        \"properties\": {\r\n            \"createDate\": \"2020-06-18T12:07:48.8125659Z\",\r\n            \"envelopeType\": \"ack\",\r\n            \"messageId\": \"f655c39f-55af-4255-afc2-813d765b6156\",\r\n            \"rootPart\": 1\r\n        },\r\n        \"routing\": {\r\n            \"MessageType\": \"http://schemas.microsoft.com/aim#ack\"\r\n        },\r\n        \"routingSlip\": {},\r\n        \"state\": {}\r\n    }\r\n    \"body\": [\r\n        {\r\n            \"$contentType\": \"application/json\",\r\n            \"$part\": 1,\r\n            \"$partType\": \"http://schemas.microsoft.com/aim#ack\",\r\n\t\t\t\"$content\": \"No more routes to process in RoutingSlip\"\r\n        }\r\n    ]\r\n}"
                            }
                        ],
                        "headers": []
                    },
                    {
                        "statusCode": 500,
                        "description": "An internal error has occurred, and a fault object has been returned.",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n  \"fault\": {\r\n    \"faultActor\": \"BuildEnvelope\",\r\n    \"faultCode\": \"500\",\r\n    \"faultReason\": \"Unknown error\",\r\n    \"faultCategory\": \"Error\",\r\n    \"faultMessage\": \"The supplied request body contains an empty JSON array\"\r\n  }\r\n}"
                            }
                        ],
                        "headers": []
                    }
                ]
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/convertxmltojson')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "displayName": "ConvertXmlToJson",
                "method": "POST",
                "urlTemplate": "/convertxmltojson",
                "templateParameters": [],
                "description": "Converts a given XML Body to JSON. Can optionally remove the root node form the XML before converting.",
                "request": {
                    "queryParameters": [
                        {
                            "name": "removeOuterEnvelope",
                            "description": "Indicates if we should remove the outer element from the supplied XML before converting it.",
                            "type": "boolean",
                            "defaultValue": "false",
                            "values": [
                                "true",
                                "false"
                            ]
                        }
                    ],
                    "headers": [],
                    "representations": [
                        {
                            "contentType": "application/json"
                        }
                    ]
                },
                "responses": [
                    {
                        "statusCode": 200,
                        "description": "The supplied XML has been successfully converted to JSON.",
                        "representations": [
                            {
                                "contentType": "application/xml"
                            }
                        ],
                        "headers": []
                    },
                    {
                        "statusCode": 500,
                        "description": "An error occurred trying to convert the XML to JSON and a Fault object has been returned.",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n  \"fault\": {\r\n    \"faultActor\": \"ConvertXmlToJson\",\r\n    \"faultCode\": \"500\",\r\n    \"faultReason\": \"Unknown error\",\r\n    \"faultCategory\": \"Error\",\r\n    \"faultMessage\": \"The supplied request body contains an empty JSON array\"\r\n  }\r\n}"
                            }
                        ],
                        "headers": []
                    }
                ]
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/convertjsontoxml')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "displayName": "ConvertJsonToXml",
                "method": "POST",
                "urlTemplate": "/convertjsontoxml",
                "templateParameters": [],
                "description": "Converts a given JSON Body to XML. Can optionally wrap the converted JSON in a root node with a namespace. Note: if the JSON message contains multiple root properties, an XML Root Node must be supplied.",
                "request": {
                    "queryParameters": [
                        {
                            "name": "addMessageBodyForEmptyMessage",
                            "description": "Indicates if we create an XML body if an empty JSON message is supplied.",
                            "type": "boolean",
                            "defaultValue": "false",
                            "values": [
                                "true",
                                "false"
                            ]
                        },
                        {
                            "name": "rootNode",
                            "description": "Optional XML Root Node name, used to wrap the generated XML.",
                            "type": "string",
                            "values": []
                        },
                        {
                            "name": "rootNodeNamespace",
                            "description": "Optional XML Root Node Namespace to use.",
                            "type": "string",
                            "values": []
                        },
                        {
                            "name": "writeArrayAttribute",
                            "description": "Indicates if we should add a special attribute to arrays, so that if we convert back to JSON, arrays with a single element are correctly handled",
                            "type": "boolean",
                            "defaultValue": "true",
                            "values": [
                                "true",
                                "false"
                            ]
                        },
                        {
                            "name": "encodeSpecialCharacters",
                            "description": "Indicates if we encode JSON control characters.",
                            "type": "boolean",
                            "defaultValue": "false",
                            "values": [
                                "true",
                                "false"
                            ]
                        }
                    ],
                    "headers": [],
                    "representations": [
                        {
                            "contentType": "application/json"
                        }
                    ]
                },
                "responses": [
                    {
                        "statusCode": 200,
                        "description": "The supplied JSON has been successfully converted to XML.",
                        "representations": [
                            {
                                "contentType": "application/xml"
                            }
                        ],
                        "headers": []
                    },
                    {
                        "statusCode": 500,
                        "description": "An error occurred trying to convert the JSON to XML and a Fault object has been returned",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n  \"fault\": {\r\n    \"faultActor\": \"ConvertJsonToXml\",\r\n    \"faultCode\": \"500\",\r\n    \"faultReason\": \"Unknown error\",\r\n    \"faultCategory\": \"Error\",\r\n    \"faultMessage\": \"The supplied request body contains an empty JSON array\"\r\n  }\r\n}"
                            }
                        ],
                        "headers": []
                    }
                ]
            }
        },
         {
            "type": "Microsoft.ApiManagement/service/apis/operations",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/wrapxmlenvelope')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "displayName": "WrapXmlEnvelope",
                "method": "POST",
                "urlTemplate": "/wrapxmlenvelope",
                "templateParameters": [],
                "description": "Wraps an XML envelope around the supplied XML body content.",
                "request": {
                    "queryParameters": [
                        {
                            "name": "emitXMlDeclaration",
                            "description": "Indicates if we emit an XML Declaration at the start of the returned content.",
                            "type": "boolean",
                            "defaultValue": "false",
                            "values": [
                                "true",
                                "false"
                            ]
                        },
                        {
                            "name": "envelopeSpecNames",
                            "description": "Pipe-separated list of envelope schema names.",
                            "type": "string",
                            "values": []
                        }
                    ],
                    "headers": [],
                    "representations": [
                        {
                            "contentType": "application/xml"
                        },
                        {
                            "contentType": "text/xml"
                        }
                    ]
                },
                "responses": [
                    {
                        "statusCode": 200,
                        "description": "The supplied XML content has been successfully wrapped in an envelope.",
                        "representations": [
                            {
                                "contentType": "application/xml"
                            }
                        ],
                        "headers": []
                    },
                    {
                        "statusCode": 500,
                        "description": "An error occurred trying to wrap the content in an Envelope and a Fault object has been returned",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n  \"fault\": {\r\n    \"faultActor\": \"WrapXmlEnvelope\",\r\n    \"faultCode\": \"500\",\r\n    \"faultReason\": \"Unknown error\",\r\n    \"faultCategory\": \"Error\",\r\n    \"faultMessage\": \"The supplied request body does not contain XML.\"\r\n  }\r\n}"
                            }
                        ],
                        "headers": []
                    }
                ]
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/decodebodycontent')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "displayName": "DecodeBodyContent",
                "description": "Decodes and returns the content from the root body part in the supplied envelope message.",
                "method": "POST",
                "urlTemplate": "/decodebodycontent",
                "templateParameters": [],
                "request": {
                    "queryParameters": [
                        {
                            "name": "clearCache",
                            "description": "If true, then any cached config is cleared, and config is retrieved from App Config again.",
                            "type": "bool",
                            "defaultValue": "false",
                            "values": [
                                "false"
                            ]
                        },
                        {
                            "name": "enableTrace",
                            "description": "If true, then an APIM trace URL is returned as a response header.",
                            "type": "bool",
                            "defaultValue": "false",
                            "values": [
                                "false"
                            ]
                        }
                    ],
                    "headers": [
                        {
                            "name": "Aim-Tracking-Id",
                            "description": "Tracking ID used to link disparate messages together by AIM.",
                            "type": "string",
                            "required": false,
                            "defaultValue": ""
                        }
                    ],
                    "representations": [
                        {
                            "contentType": "text/json",
                            "sample": "{\r\n    \"header\": {\r\n        \"properties\": {},\r\n        \"state\": {},\r\n        \"routing\": {},\r\n        \"routingSlip\": {\r\n            \"scenario\": \"\",\r\n            \"nextRoute\": 0,\r\n            \"routes\": []\r\n        }\r\n    },\r\n    \"body\": []\r\n}"
                        },
                        {
                            "contentType": "application/json",
                            "sample": "{\r\n    \"header\": {\r\n        \"properties\": {},\r\n        \"state\": {},\r\n        \"routing\": {},\r\n        \"routingSlip\": {\r\n            \"scenario\": \"\",\r\n            \"nextRoute\": 0,\r\n            \"routes\": []\r\n        }\r\n    },\r\n    \"body\": []\r\n}"
                        }
                    ]
                },
                "responses": [
                    {
                        "statusCode": 200,
                        "description": "Body content has been retrieved and returned.",
                        "representations": [
                            {
                                "contentType": "text/plain"
                            },
                            {
                                "contentType": "text/json"
                            },
                            {
                                "contentType": "text/xml"
                            },
                            {
                                "contentType": "text/csv"
                            },
                            {
                                "contentType": "application/json"
                            },
                            {
                                "contentType": "application/xml"
                            }
                        ],
                        "headers": []
                    },
                    {
                        "statusCode": 500,
                        "description": "An internal error has occurred, and a fault object has been returned.",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n  \"fault\": {\r\n    \"faultActor\": \"DecodeBodyContent\",\r\n    \"faultCode\": \"500\",\r\n    \"faultReason\": \"Unknown error\",\r\n    \"faultCategory\": \"Error\",\r\n    \"faultMessage\": \"The supplied request body contains an empty JSON array\"\r\n  }\r\n}"
                            }
                        ],
                        "headers": []
                    }
                ]
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/getbodycontent')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "displayName": "GetBodyContent",
                "description": "Returns encoded content from the root body part in the supplied envelope message.",
                "method": "POST",
                "urlTemplate": "/getbodycontent",
                "templateParameters": [],
                "request": {
                    "queryParameters": [
                        {
                            "name": "clearCache",
                            "description": "If true, then any cached config is cleared, and config is retrieved from App Config again.",
                            "type": "bool",
                            "defaultValue": "false",
                            "values": [
                                "false"
                            ]
                        },
                        {
                            "name": "enableTrace",
                            "description": "If true, then an APIM trace URL is returned as a response header.",
                            "type": "bool",
                            "defaultValue": "false",
                            "values": [
                                "false"
                            ]
                        }
                    ],
                    "headers": [
                        {
                            "name": "Aim-Tracking-Id",
                            "description": "Tracking ID used to link disparate messages together by AIM.",
                            "type": "string",
                            "required": false,
                            "defaultValue": ""
                        }
                    ],
                    "representations": [
                        {
                            "contentType": "text/json",
                            "sample": "{\r\n    \"header\": {\r\n        \"properties\": {},\r\n        \"state\": {},\r\n        \"routing\": {},\r\n        \"routingSlip\": {\r\n            \"scenario\": \"\",\r\n            \"nextRoute\": 0,\r\n            \"routes\": []\r\n        }\r\n    },\r\n    \"body\": []\r\n}"
                        },
                        {
                            "contentType": "application/json",
                            "sample": "{\r\n    \"header\": {\r\n        \"properties\": {},\r\n        \"state\": {},\r\n        \"routing\": {},\r\n        \"routingSlip\": {\r\n            \"scenario\": \"\",\r\n            \"nextRoute\": 0,\r\n            \"routes\": []\r\n        }\r\n    },\r\n    \"body\": []\r\n}"
                        }
                    ]
                },
                "responses": [
                    {
                        "statusCode": 200,
                        "description": "Body content has been retrieved and returned.",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n    \"$contentType\": \"text/plain\",\r\n    \"$content\": \"SGVsbG8\"\r\n}"
                            }
                        ],
                        "headers": []
                    },
                    {
                        "statusCode": 500,
                        "description": "An internal error has occurred, and a fault object has been returned.",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n  \"fault\": {\r\n    \"faultActor\": \"GetBodyContent\",\r\n    \"faultCode\": \"500\",\r\n    \"faultReason\": \"Unknown error\",\r\n    \"faultCategory\": \"Error\",\r\n    \"faultMessage\": \"The supplied request body contains an empty JSON array\"\r\n  }\r\n}"
                            }
                        ],
                        "headers": []
                    }
                ]
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/mergeproperties')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "displayName": "MergeProperties",
                "description": "Merges the contents of an array of property bags together and returns the result.",
                "method": "POST",
                "urlTemplate": "/mergeproperties",
                "templateParameters": [],
                "request": {
                    "queryParameters": [],
                    "headers": [
                        {
                            "name": "Aim-Tracking-Id",
                            "description": "Tracking ID used to link disparate messages together by AIM.",
                            "type": "string",
                            "required": false,
                            "defaultValue": ""
                        }
                    ],
                    "representations": [
                        {
                            "contentType": "text/json",
                            "sample": "[\r\n    {\r\n        \"properties\": \r\n        {\r\n            \"property1\": \"value1\",\r\n            \"property2\": \"value2\"\r\n        }\r\n    },\r\n    {\r\n        \"properties\": \r\n        {\r\n            \"property1\": \"value3\",\r\n            \"property4\": \"value4\"\r\n        }\r\n    }\r\n]\r\n"
                        },
                        {
                            "contentType": "application/json",
                            "sample": "[\r\n    {\r\n        \"properties\": \r\n        {\r\n            \"property1\": \"value1\",\r\n            \"property2\": \"value2\"\r\n        }\r\n    },\r\n    {\r\n        \"properties\": \r\n        {\r\n            \"property1\": \"value3\",\r\n            \"property4\": \"value4\"\r\n        }\r\n    }\r\n]\r\n"
                        }
                    ]
                },
                "responses": [
                    {
                        "statusCode": 200,
                        "description": "Property bags have been merged successfully.",
                        "representations": [
                            {
                                "contentType": "application/json"
                            }
                        ],
                        "headers": []
                    },
                    {
                        "statusCode": 500,
                        "description": "An internal error has occurred, and a fault object has been returned.",
                        "representations": [
                            {
                                "contentType": "application/json",
                                "sample": "{\r\n  \"fault\": {\r\n    \"faultActor\": \"MergeProperties\",\r\n    \"faultCode\": \"500\",\r\n    \"faultReason\": \"Unknown error\",\r\n    \"faultCategory\": \"Error\",\r\n    \"faultMessage\": \"The supplied request body contains an empty JSON array\"\r\n  }\r\n}"
                            }
                        ],
                        "headers": []
                    }
                ]
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations/policies",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/buildenvelope/policy')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('apimServiceName'), parameters('apiName'), 'buildenvelope')]",
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]",
                "[resourceId('Microsoft.ApiManagement/service/backends', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-backend-service id=\"apim-generated-policy\" backend-id=\"aimmessagingmanager\" />\r\n  </inbound>\r\n  <backend>\r\n    <base />\r\n  </backend>\r\n  <outbound>\r\n    <base />\r\n  </outbound>\r\n  <on-error>\r\n    <base />\r\n  </on-error>\r\n</policies>",
                "format": "xml"
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations/policies",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/convertjsontoxml/policy')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('apimServiceName'), parameters('apiName'), 'convertjsontoxml')]",
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]",
                "[resourceId('Microsoft.ApiManagement/service/backends', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-backend-service id=\"apim-generated-policy\" backend-id=\"aimmessagingmanager\" />\r\n  </inbound>\r\n  <backend>\r\n    <base />\r\n  </backend>\r\n  <outbound>\r\n    <base />\r\n  </outbound>\r\n  <on-error>\r\n    <base />\r\n  </on-error>\r\n</policies>",
                "format": "xml"
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations/policies",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/convertxmltojson/policy')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('apimServiceName'), parameters('apiName'), 'convertxmltojson')]",
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]",
                "[resourceId('Microsoft.ApiManagement/service/backends', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-backend-service id=\"apim-generated-policy\" backend-id=\"aimmessagingmanager\" />\r\n  </inbound>\r\n  <backend>\r\n    <base />\r\n  </backend>\r\n  <outbound>\r\n    <base />\r\n  </outbound>\r\n  <on-error>\r\n    <base />\r\n  </on-error>\r\n</policies>",
                "format": "xml"
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations/policies",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/wrapxmlenvelope/policy')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('apimServiceName'), parameters('apiName'), 'wrapxmlenvelope')]",
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]",
                "[resourceId('Microsoft.ApiManagement/service/backends', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-backend-service id=\"apim-generated-policy\" backend-id=\"aimmessagingmanager\" />\r\n  </inbound>\r\n  <backend>\r\n    <base />\r\n  </backend>\r\n  <outbound>\r\n    <base />\r\n  </outbound>\r\n  <on-error>\r\n    <base />\r\n  </on-error>\r\n</policies>",
                "format": "xml"
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations/policies",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/decodebodycontent/policy')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('apimServiceName'), parameters('apiName'), 'decodebodycontent')]",
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]",
                "[resourceId('Microsoft.ApiManagement/service/backends', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-backend-service id=\"apim-generated-policy\" backend-id=\"aimmessagingmanager\" />\r\n  </inbound>\r\n  <backend>\r\n    <base />\r\n  </backend>\r\n  <outbound>\r\n    <base />\r\n  </outbound>\r\n  <on-error>\r\n    <base />\r\n  </on-error>\r\n</policies>",
                "format": "xml"
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations/policies",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/getbodycontent/policy')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('apimServiceName'), parameters('apiName'), 'getbodycontent')]",
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]",
                "[resourceId('Microsoft.ApiManagement/service/backends', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-backend-service id=\"apim-generated-policy\" backend-id=\"aimmessagingmanager\" />\r\n  </inbound>\r\n  <backend>\r\n    <base />\r\n  </backend>\r\n  <outbound>\r\n    <base />\r\n  </outbound>\r\n  <on-error>\r\n    <base />\r\n  </on-error>\r\n</policies>",
                "format": "xml"
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/apis/operations/policies",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', parameters('apiName'), '/mergeproperties/policy')]",
            "dependsOn": [
                "[resourceId('Microsoft.ApiManagement/service/apis/operations', parameters('apimServiceName'), parameters('apiName'), 'mergeproperties')]",
                "[resourceId('Microsoft.ApiManagement/service/apis', parameters('apimServiceName'), parameters('apiName'))]",
                "[resourceId('Microsoft.ApiManagement/service/backends', parameters('apimServiceName'), parameters('apiName'))]"
            ],
            "properties": {
                "value": "<policies>\r\n  <inbound>\r\n    <base />\r\n    <set-backend-service id=\"apim-generated-policy\" backend-id=\"aimmessagingmanager\" />\r\n  </inbound>\r\n  <backend>\r\n    <base />\r\n  </backend>\r\n  <outbound>\r\n    <base />\r\n  </outbound>\r\n  <on-error>\r\n    <base />\r\n  </on-error>\r\n</policies>",
                "format": "xml"
            }
        },
        {
            "type": "Microsoft.ApiManagement/service/tags",
            "apiVersion": "2019-12-01",
            "name": "[concat(parameters('apimServiceName'), '/', variables('apiTagName'))]",
            "dependsOn": [
            ],
            "properties": {
                "displayName": "messagingmanager"
            }
        }
    ]
}
tools\templates\messagebus\messagingmanager\messagingmanager.apim.prod.parameters.json.liquid
 
tools\templates\messagebus\messagingmanager\messagingmanager.func.dev.parameters.json.liquid
 
tools\templates\messagebus\messagingmanager\messagingmanager.func.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "functionAppName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 60
        },
        "functionAppLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "storageAccountName": {
            "type": "string",
            "minLength": 3,
            "maxLength": 24
        },
        "appInsightsName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 260
        },
        "appServicePlanName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40
        },
        "apimServiceName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50
        },
        "enableOAuthForApim": {
            "type": "bool",
            "defaultValue": false
        },
        "enableOAuthForLogicApps": {
            "type": "bool",
            "defaultValue": false
        },
        "enableOAuthForManagementAPI": {
            "type": "bool",
            "defaultValue": false
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "storageAccountId": "[resourceId(resourceGroup().name, 'Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
    },
    "resources": [
        {
            "apiVersion": "2019-08-01",
            "type": "Microsoft.Web/sites",
            "name": "[parameters('functionAppName')]",
            "location": "[parameters('functionAppLocation')]",
            "tags": "[parameters('tags')]",
            "kind": "functionapp",
            "properties": {
                "serverFarmId": "[concat(resourceId(resourceGroup().name, 'Microsoft.Web/serverfarms', parameters('appServicePlanName')))]",
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountId'), '2019-06-01').keys[0].value)]"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference(resourceId(resourceGroup().name, 'Microsoft.Insights/components', parameters('appInsightsName')), '2015-05-01').InstrumentationKey]"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountId'), '2019-06-01').keys[0].value)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[toLower(parameters('functionAppName'))]"
                        },
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "dotnet"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~3"
                        },
                        {
                            "name": "ApimSubscriptionKey",
                            "value": "[reference(resourceId('Microsoft.ApiManagement/service/subscriptions', parameters('apimServiceName'), 'master'), '2019-01-01').primaryKey]"
                        },
                        {
                            "name": "ApimInstanceName",
                            "value": "[parameters('apimServiceName')]"
                        },
                        {
                            "name": "EnableOAuthForApim",
                            "value": "[parameters('enableOAuthForApim')]"
                        },
                        {
                            "name": "EnableOAuthForLogicApps",
                            "value": "[parameters('enableOAuthForLogicApps')]"
                        },
                        {
                            "name": "EnableOAuthForManagementAPI",
                            "value": "[parameters('enableOAuthForManagementAPI')]"
                        }
                    ]
                }
            }
        },
        {
            "apiVersion": "2018-11-01",
            "type": "Microsoft.Web/sites/host/functionKeys",
            "name": "[concat(parameters('functionAppName'), '/default/apiManagement')]",
            "properties": {
                "name": "[parameters('apimServiceName')]"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]"
            ]
        }
    ]
}
tools\templates\messagebus\messagingmanager\messagingmanager.func.prod.parameters.json.liquid
 
tools\templates\messagebus\messagingmanager\Microsoft.AzureIntegrationMigration.FunctionApp.MessagingManager.zip
md5: B728AE1ACD624FAAF4AAF6BE97C7D0BA | sha1: A5CABD46C48A8D5C6C697F72549BE4EDD2E01FF8 | sha256: 8CA5B2917B9986829EB15BBD3175929DFB8A0AD4CBF157C391EE99AC23CAD460 | sha512: 18352EBE8F0DF2E89666E3F658E0166F13938A97DC98BCE184C0C5130369548A8C0A8D77851BEE770037556312F1A53A0DA71D83B2230BDA2E97DF5EF23C61FD
tools\templates\messagebus\messagingmanager\New-MessagingManager-ApiManagement.ps1
<#
.SYNOPSIS
Creates an API resource in API Management for the messaging manager.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the API Management service is located.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER apimServiceName
The name of the API Management service.

.PARAMETER apiName
The name of the API being deployed.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-MessagingManager-ApiManagement.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -apimServiceName "apim-aimmsgbussvc-dev" -apiName "aimroutingmanager" -templateFile ".\routingmanager.apim.json" -templateParameterFile ".\routingmanager.apim.dev.parameters" -deploymentName "routingmanager.apim"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $apimServiceName,
    [parameter(Mandatory = $true)]
    [string] $apiName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

Write-Host "Deploying the API for the messaging manager`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"

Write-Host "Associating the API Management service $apimServiceName products to the API $apiName"

$products = az rest -m GET -u https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$apimServiceName/products?api-version=2018-01-01 | ConvertFrom-Json | Select-Object -ExpandProperty value

if ($products) {
    Write-Host "Found products for API Management service $apimServiceName"

    ForEach ($product in $products) {
        $productName = $product.name

        Write-Host "Associating product $productName with the messaging manager API"

        # PowerShell doesn't like variable expansion when a ? follows the variable
        $url = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$apimServiceName/products/$productName/apis/" + $apiName + "?api-version=2018-01-01"
		
        az rest -m PUT -u $url
    }
}
else {
    throw "Failed to get products for API Management service $apimServiceName"
}
tools\templates\messagebus\messagingmanager\New-MessagingManager-Function.ps1
<#
.SYNOPSIS
Creates a Function resource which implements the messaging manager operations.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER resourceName
Name of the Function App.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.PARAMETER zipFile
Name of the zip file containing the Function App.

.EXAMPLE
./New-MessagingManager-Function.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -templateFile ".\messagingmanager.func.json" -templateParameterFile ".\messagingmanager.func.dev.parameters" -deploymentName "messagingmanager.func"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName,
    [parameter(Mandatory = $true)]
    [string] $zipFile
)

Write-Host "Deploying the messaging manager function`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"

Write-Host "Uploading the messaging manager function zip package $zipFile"

if (!(Test-Path $zipFile)) {
    throw "Zip file $zipFile doesn't exist, unable to upload"
}

az functionapp deployment source config-zip --resource-group $resourceGroupName --name $resourceName --src $zipFile

Write-Host "Upload complete"
tools\templates\messagebus\messagingmanager\Remove-MessagingManager-ApiManagement.ps1
<#
.SYNOPSIS
Tears down the API resource in API Management for the messaging manager.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER serviceName
The name of the API Management service to find the resource.

.PARAMETER apiName
The name of the API resource in API Management to remove.

.EXAMPLE
./Remove-MessagingManager-ApiManagement.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -serviceName "apim-aimmsgbussvc-dev" -apiName "aimmessagingmanager"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $serviceName,
    [parameter(Mandatory = $true)]
    [string] $apiName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $apiName --namespace "Microsoft.ApiManagement" --parent "service/$serviceName" --resource-type "apis"

if ($resourceExists) {
    Write-Host "Removing the API resource for service $serviceName : $apiName"

    az resource delete --resource-group $resourceGroupName --name $apiName --namespace "Microsoft.ApiManagement" --parent "service/$serviceName" --resource-type "apis"

    Write-Host "Removed the API resource for service $serviceName : $apiName"
}
else {
    Write-Host "The API resource $apiName for service $serviceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\messagingmanager\Remove-MessagingManager-Function.ps1
<#
.SYNOPSIS
Tears down the Function resource.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
./Remove-MessagingManager-Function.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -resourceName "func-aimmsgmgr-dev-001"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az functionapp show --name $resourceName --resource-group $resourceGroupName

if ($resourceExists) {
    Write-Host "Removing the messaging manager function resource: $resourceName"

    az functionapp delete --name $resourceName --resource-group $resourceGroupName

    Write-Host "Removed the messaging manager function resource: $resourceName"
}
else {
    Write-Host "The messaging manager function resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\messagingmanager\TearDown-50-MessagingManager-Function.ps1.liquid
 
tools\templates\messagebus\messagingmanager\TearDown-60-MessagingManager-ApiManagement.ps1.liquid
 
tools\templates\messagebus\routingmanager\Deploy-50-RoutingManager-Function.ps1.liquid
 
tools\templates\messagebus\routingmanager\Deploy-60-RoutingManager-ApiManagement.ps1.liquid
 
tools\templates\messagebus\routingmanager\Microsoft.AzureIntegrationMigration.FunctionApp.RoutingManager.zip
md5: 76D30DC317C67C126F8CA27F1EC663B0 | sha1: AADFAD76C24A3B0F9C7F73981E6D9BF19E787216 | sha256: AD69B9BE6307BF32A16082A2642C4C761719D36A9FD4738D36AAE7A142103B18 | sha512: 39EA2FDFEB45F04E226DEA72E769B26D5E4E0CC2DFBB38B198AA9BCD007FC9D87D54EF9F38E0BFDDD160837E28742852D80C1FFD4B440695647E6663EEB35375
tools\templates\messagebus\routingmanager\New-RoutingManager-ApiManagement.ps1
<#
.SYNOPSIS
Creates an API resource in API Management for the routing manager.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the API Management service is located.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER apimServiceName
The name of the API Management service.

.PARAMETER apiName
The name of the API being deployed.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-RoutingManager-ApiManagement.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -apimServiceName "apim-aimmsgbussvc-dev" -apiName "aimroutingmanager" -templateFile ".\routingmanager.apim.json" -templateParameterFile ".\routingmanager.apim.dev.parameters" -deploymentName "routingmanager.apim"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $apimServiceName,
    [parameter(Mandatory = $true)]
    [string] $apiName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

Write-Host "Deploying the API for the routing manager`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"

Write-Host "Associating the API Management service $apimServiceName products to the API $apiName"

$products = az rest -m GET -u https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$apimServiceName/products?api-version=2018-01-01 | ConvertFrom-Json | Select-Object -ExpandProperty value

if ($products) {
    Write-Host "Found products for API Management service $apimServiceName"

    ForEach ($product in $products) {
        $productName = $product.name

        Write-Host "Associating product $productName with the routing manager API"

        # PowerShell doesn't like variable expansion when a ? follows the variable
        $url = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$apimServiceName/products/$productName/apis/" + $apiName + "?api-version=2018-01-01"
		
        az rest -m PUT -u $url
    }
}
else {
    throw "Failed to get products for API Management service $apimServiceName"
}
tools\templates\messagebus\routingmanager\New-RoutingManager-Function.ps1
<#
.SYNOPSIS
Creates a Function resource which implements the routing manager operations.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER resourceName
Name of the Function App.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.PARAMETER zipFile
Name of the zip file containing the Function App.

.EXAMPLE
./New-RoutingManager-Function.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -templateFile ".\routingmanager.func.json" -templateParameterFile ".\routingmanager.func.dev.parameters" -deploymentName "routingmanager.func"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName,
    [parameter(Mandatory = $true)]
    [string] $zipFile
)

Write-Host "Deploying the routing manager function`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"

Write-Host "Uploading the routing manager function zip package $zipFile"

if (!(Test-Path $zipFile)) {
    throw "Zip file $zipFile doesn't exist, unable to upload"
}

az functionapp deployment source config-zip --resource-group $resourceGroupName --name $resourceName --src $zipFile

Write-Host "Upload complete"
tools\templates\messagebus\routingmanager\Remove-RoutingManager-ApiManagement.ps1
<#
.SYNOPSIS
Tears down the API resource in API Management for the routing manager.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER serviceName
The name of the API Management service to find the resource.

.PARAMETER apiName
The name of the API resource in API Management to remove.

.EXAMPLE
./Remove-RoutingManager-ApiManagement.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -serviceName "apim-aimmsgbussvc-dev" -apiName "aimroutingmanager"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $serviceName,
    [parameter(Mandatory = $true)]
    [string] $apiName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $apiName --namespace "Microsoft.ApiManagement" --parent "service/$serviceName" --resource-type "apis"

if ($resourceExists) {
    Write-Host "Removing the API resource for service $serviceName : $apiName"

    az resource delete --resource-group $resourceGroupName --name $apiName --namespace "Microsoft.ApiManagement" --parent "service/$serviceName" --resource-type "apis"

    Write-Host "Removed the API resource for service $serviceName : $apiName"
}
else {
    Write-Host "The API resource $apiName for service $serviceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\routingmanager\Remove-RoutingManager-Function.ps1
<#
.SYNOPSIS
Tears down the Function resource.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
./Remove-RoutingManager-Function.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -resourceName "func-aimroutemgr-dev-001"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az functionapp show --name $resourceName --resource-group $resourceGroupName

if ($resourceExists) {
    Write-Host "Removing the routing manager function resource: $resourceName"

    az functionapp delete --name $resourceName --resource-group $resourceGroupName

    Write-Host "Removed the routing manager function resource: $resourceName"
}
else {
    Write-Host "The routing manager function resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\routingmanager\routingmanager.apim.dev.parameters.json.liquid
 
tools\templates\messagebus\routingmanager\routingmanager.apim.json.liquid
 
tools\templates\messagebus\routingmanager\routingmanager.apim.prod.parameters.json.liquid
 
tools\templates\messagebus\routingmanager\routingmanager.func.dev.parameters.json.liquid
 
tools\templates\messagebus\routingmanager\routingmanager.func.json
{
    "$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "functionAppName": {
            "type": "string",
            "minLength": 2,
            "maxLength": 60
        },
        "functionAppLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "storageAccountName": {
            "type": "string",
            "minLength": 3,
            "maxLength": 24
        },
        "appInsightsName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 260
        },
        "appServicePlanName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 40
        },
        "apiManagementServiceName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 50
        },
        "enableOAuthForApim": {
            "type": "bool",
            "defaultValue": false
        },
        "enableOAuthForLogicApps": {
            "type": "bool",
            "defaultValue": false
        },
        "enableOAuthForManagementAPI": {
            "type": "bool",
            "defaultValue": false
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "storageAccountId": "[resourceId(resourceGroup().name, 'Microsoft.Storage/storageAccounts', parameters('storageAccountName'))]"
    },
    "resources": [
        {
            "apiVersion": "2019-08-01",
            "type": "Microsoft.Web/sites",
            "name": "[parameters('functionAppName')]",
            "location": "[parameters('functionAppLocation')]",
            "tags": "[parameters('tags')]",
            "kind": "functionapp",
            "properties": {
                "serverFarmId": "[concat(resourceId(resourceGroup().name, 'Microsoft.Web/serverfarms', parameters('appServicePlanName')))]",
                "siteConfig": {
                    "appSettings": [
                        {
                            "name": "AzureWebJobsStorage",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountId'), '2019-06-01').keys[0].value)]"
                        },
                        {
                            "name": "APPINSIGHTS_INSTRUMENTATIONKEY",
                            "value": "[reference(resourceId(resourceGroup().name, 'Microsoft.Insights/components', parameters('appInsightsName')), '2015-05-01').InstrumentationKey]"
                        },
                        {
                            "name": "WEBSITE_CONTENTAZUREFILECONNECTIONSTRING",
                            "value": "[concat('DefaultEndpointsProtocol=https;AccountName=', parameters('storageAccountName'), ';AccountKey=', listKeys(variables('storageAccountId'), '2019-06-01').keys[0].value)]"
                        },
                        {
                            "name": "WEBSITE_CONTENTSHARE",
                            "value": "[toLower(parameters('functionAppName'))]"
                        },
                        {
                            "name": "FUNCTIONS_WORKER_RUNTIME",
                            "value": "dotnet"
                        },
                        {
                            "name": "FUNCTIONS_EXTENSION_VERSION",
                            "value": "~3"
                        },
                        {
                            "name": "ApimSubscriptionKey",
                            "value": "[reference(resourceId('Microsoft.ApiManagement/service/subscriptions', parameters('apiManagementServiceName'), 'master'), '2019-01-01').primaryKey]"
                        },
                        {
                            "name": "ApimInstanceName",
                            "value": "[parameters('apiManagementServiceName')]"
                        },
                        {
                            "name": "EnableOAuthForApim",
                            "value": "[parameters('enableOAuthForApim')]"
                        },
                        {
                            "name": "EnableOAuthForLogicApps",
                            "value": "[parameters('enableOAuthForLogicApps')]"
                        },
                        {
                            "name": "EnableOAuthForManagementAPI",
                            "value": "[parameters('enableOAuthForManagementAPI')]"
                        }
                    ]
                }
            }
        },
        {
            "apiVersion": "2018-11-01",
            "type": "Microsoft.Web/sites/host/functionKeys",
            "name": "[concat(parameters('functionAppName'), '/default/apiManagement')]",
            "properties": {
                "name": "[parameters('apiManagementServiceName')]"
            },
            "dependsOn": [
                "[resourceId('Microsoft.Web/sites', parameters('functionAppName'))]"
            ]
        }
    ]
}
tools\templates\messagebus\routingmanager\routingmanager.func.prod.parameters.json.liquid
 
tools\templates\messagebus\routingmanager\TearDown-50-RoutingManager-Function.ps1.liquid
 
tools\templates\messagebus\routingmanager\TearDown-60-RoutingManager-ApiManagement.ps1.liquid
 
tools\templates\messagebus\routingstore\Deploy-15-RoutingStore-KeyVault.ps1.liquid
 
tools\templates\messagebus\routingstore\Deploy-20-RoutingStore-AppConfig.ps1.liquid
 
tools\templates\messagebus\routingstore\Deploy-40-RoutingStore-ApiManagement.ps1.liquid
 
tools\templates\messagebus\routingstore\New-RoutingStore-ApiManagement.ps1
<#
.SYNOPSIS
Creates an API resource in API Management for the routing store.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the API Management service is located.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER apimServiceName
The name of the API Management service.

.PARAMETER apiName
The name of the API being deployed.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-RoutingStore-ApiManagement.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -apimServiceName "apim-aimmsgbussvc-dev" -apiName "aimroutingstore" -templateFile ".\routingstore.apim.json" -templateParameterFile ".\routingstore.apim.dev.parameters" -deploymentName "routingstore.apim"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $apimServiceName,
    [parameter(Mandatory = $true)]
    [string] $apiName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

Write-Host "Deploying the API for the routing store`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"

Write-Host "Associating the API Management service $apimServiceName products to the API $apiName"

$products = az rest -m GET -u https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$apimServiceName/products?api-version=2018-01-01 | ConvertFrom-Json | Select-Object -ExpandProperty value

if ($products) {
    Write-Host "Found products for API Management service $apimServiceName"

    ForEach ($product in $products) {
        $productName = $product.name

        Write-Host "Associating product $productName with the routing store API"

        # PowerShell doesn't like variable expansion when a ? follows the variable
        $url = "https://management.azure.com/subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.ApiManagement/service/$apimServiceName/products/$productName/apis/" + $apiName + "?api-version=2018-01-01"
		
        az rest -m PUT -u $url
    }
}
else {
    throw "Failed to get products for API Management service $apimServiceName"
}
tools\templates\messagebus\routingstore\New-RoutingStore-AppConfig.ps1
<#
.SYNOPSIS
Creates a App Config resource for the routing store.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER subscriptionId
The Azure subscription ID where the Key Vault service is located.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER appConfigName
The name of the Azure App Configuration service.

.PARAMETER keyVaultName
The name of the Azure Key Vault service.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-RoutingStore-AppConfig.ps1 -subscriptionId "<azure-subs-id>" -resourceGroupName "rg-aimmsgbus-dev-uksouth" -appConfigName "appcfg-aimrstore-dev" -keyVaultName "kv-aimrstore-dev" -templateFile ".\routingstore.appcfg.json" -templateParameterFile ".\routingstore.appcfg.dev.parameters" -deploymentName "routingstore.appcfg"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [AllowNull()]
    [AllowEmptyString()]
    [string] $subscriptionId,
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $appConfigName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

if ($subscriptionId -eq "") {
    Write-Host "No Azure subscription ID specified, finding from current active subscription"

    $subscriptionId = az account show | ConvertFrom-Json | Select-Object -ExpandProperty id

    if ($subscriptionId) {
        Write-Host "Found subscription ID $subscriptionId"
    }
    else {
        throw "No subscription ID found, an active subscription may not have been set in the Azure CLI"
    }
}

Write-Host "Deploying the routing store`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile --name $deploymentName

Write-Host "Deployment complete"

Write-Host "Getting managed identity principal ID for App Configuration resource $appConfigName"

$principalId = az appconfig show --name $appConfigName --resource-group $resourceGroupName | ConvertFrom-Json | Select-Object -ExpandProperty identity | Select-Object -ExpandProperty principalId

if ($principalId) {
    Write-Host "Principal ID is $principalId"
}
else {
    throw "Unable to get managed identity principal ID for $appConfigName"
}

$role = "Key Vault Secrets User (preview)"

Write-Host "Adding role assignment for $principalId to role $role for Key Vault resource $keyVaultName"

az role assignment create --assignee $principalId --role "$role" --scope /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.KeyVault/vaults/$keyVaultName

Write-Host "Assigned managed identity of App Configuration resource $appConfigName to $keyVaultName"
tools\templates\messagebus\routingstore\New-RoutingStore-KeyVault.ps1
<#
.SYNOPSIS
Creates a Key Vault resource for the routing store.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER name
Name of the Key Vault that will be created.

.PARAMETER location
Location where the resource will be created.

.PARAMETER sku
The sku level for the Key Vault resource.

.PARAMETER tags
The tags to apply to the Key Vault resource.

.EXAMPLE
./New-RoutingStore-KeyVault.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -name "kv-aimrstore-dev" -location "UK South" -sku "Standard"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $name,
    [parameter(Mandatory = $true)]
    [string] $location,
    [parameter(Mandatory = $false)]
    [string] $sku = "Standard",
    [parameter(Mandatory = $false)]
    [string[]] $tags = ""
)

Write-Host "Deploying the routing store Key Vault $name"

az keyvault create --name $name --resource-group $resourceGroupName --location $location --sku $sku --no-self-perms false --enable-soft-delete false --enabled-for-template-deployment true --tags $tags

Write-Host "Deployment complete"
tools\templates\messagebus\routingstore\Remove-RoutingStore-ApiManagement.ps1
<#
.SYNOPSIS
Tears down the API resource in API Management for the routing store.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER serviceName
The name of the API Management service to find the resource.

.PARAMETER apiName
The name of the API resource in API Management to remove.

.EXAMPLE
./Remove-RoutingStore-ApiManagement.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -serviceName "apim-aimmsgbussvc-dev" -apiName "aimroutingstore"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $serviceName,
    [parameter(Mandatory = $true)]
    [string] $apiName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $apiName --namespace "Microsoft.ApiManagement" --parent "service/$serviceName" --resource-type "apis"

if ($resourceExists) {
    Write-Host "Removing the API resource for service $serviceName : $apiName"

    az resource delete --resource-group $resourceGroupName --name $apiName --namespace "Microsoft.ApiManagement" --parent "service/$serviceName" --resource-type "apis"

    Write-Host "Removed the API resource for service $serviceName : $apiName"
}
else {
    Write-Host "The API resource $apiName for service $serviceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\routingstore\Remove-RoutingStore-AppConfig.ps1
<#
.SYNOPSIS
Tears down the App Config resource for the routing store.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
./Remove-RoutingStore-AppConfig.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -resourceName "appcfg-aimrstore-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az appconfig show --name $resourceName --resource-group $resourceGroupName

if ($resourceExists) {
    Write-Host "Removing the app config resource: $resourceName"

    az appconfig delete --name $resourceName --resource-group $resourceGroupName --yes

    Write-Host "Removed the app config resource: $resourceName"
}
else {
    Write-Host "The app config resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\routingstore\Remove-RoutingStore-KeyVault.ps1
<#
.SYNOPSIS
Tears down the Key Vault resource for the routing store.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER resourceName
The name of the resource to remove.

.EXAMPLE
./Remove-RoutingStore-KeyVault.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth" -resourceName "kv-aimrstore-dev"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $resourceName
)

$resourceExists = az keyvault show --name $resourceName --resource-group $resourceGroupName

if ($resourceExists) {
    Write-Host "Removing the key vault resource: $resourceName"

    az keyvault delete --name $resourceName --resource-group $resourceGroupName

    Write-Host "Removed the key vault resource: $resourceName"
}
else {
    Write-Host "The key vault resource $resourceName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\routingstore\routingstore.apim.dev.parameters.json.liquid
 
tools\templates\messagebus\routingstore\routingstore.apim.json.liquid
 
tools\templates\messagebus\routingstore\routingstore.apim.prod.parameters.json.liquid
 
tools\templates\messagebus\routingstore\routingstore.appcfg.dev.parameters.json.liquid
 
tools\templates\messagebus\routingstore\routingstore.appcfg.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "appConfigName": {
            "type": "string",
            "minLength": 5,
            "maxLength": 50
        },
        "appConfigLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]"
        },
        "tags": {
            "type": "object"
        },
        "sku": {
            "type": "string"
        }
    },
    "variables": {
    },
    "functions": [
    ],
    "resources": [
        {
            "name": "[parameters('appConfigName')]",
            "type": "Microsoft.AppConfiguration/configurationStores",
            "apiVersion": "2020-06-01",
            "location": "[parameters('appConfigLocation')]",
            "tags": "[parameters('tags')]",
            "identity": {
                "type": "SystemAssigned"
            },
            "sku": {
                "name": "[parameters('sku')]"
            },
            "resources": [
            ],
            "dependsOn": [
            ]
        }
    ],
    "outputs": {
    }
}
tools\templates\messagebus\routingstore\routingstore.appcfg.prod.parameters.json.liquid
 
tools\templates\messagebus\routingstore\routingstore.kv.dev.psparameters.json.liquid
 
tools\templates\messagebus\routingstore\routingstore.kv.prod.psparameters.json.liquid
 
tools\templates\messagebus\routingstore\TearDown-15-RoutingStore-KeyVault.ps1.liquid
 
tools\templates\messagebus\routingstore\TearDown-20-RoutingStore-AppConfig.ps1.liquid
 
tools\templates\messagebus\routingstore\TearDown-40-RoutingStore-ApiManagement.ps1.liquid
 
tools\templates\messagebus\workflows\routingsliprouter\Deploy-80-RoutingSlipRouter-LogicApp.ps1.liquid
 
tools\templates\messagebus\workflows\routingsliprouter\New-RoutingSlipRouter-LogicApp.ps1
<#
.SYNOPSIS
Creates a Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroupName
Name of the resource group where the resources will be created.

.PARAMETER templateFile
Path to the ARM template that needs to be deployed.

.PARAMETER templateParameterFile
Path to the ARM template parameter file that contains the parameter values related to the template file.

.PARAMETER keyVaultName
The name of the key vault store.

.PARAMETER keyVaultApimSubscriptionSecretName
The name of secret in key vault which stores the apim subscription.

.PARAMETER deploymentName
The name used to identify this instance of the deployment.

.EXAMPLE
./New-RoutingSlipRouter-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -templateFile ".\routingsliprouter.logicapp.json" -templateParameterFile ".\routingsliprouter.logicapp.dev.parameters" -keyVaultName "kv-aimrstore-dev-xxxxx" -keyVaultApimSubscriptionSecretName "aim-apim-subscriptionkey-unlimited" -deploymentName "routingsliprouter.logicapp.uksouth.xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]    
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]    
    [string] $templateFile,
    [parameter(Mandatory = $true)]
    [string] $templateParameterFile,
    [string] $keyVaultName,
    [parameter(Mandatory = $true)]
    [string] $keyVaultApimSubscriptionSecretName,
    [parameter(Mandatory = $true)]
    [string] $deploymentName
)

Write-Host "Getting the subscription key from Key Vault for APIM"

$apimSubscriptionKey = az keyvault secret show --name $keyVaultApimSubscriptionSecretName --vault-name $keyVaultName --query value
if (!$apimSubscriptionKey) {
    throw "Unable to get a secret from the vault $keyVaultName with the name $keyVaultApimSubscriptionSecretName"
}

Write-Host "Deploying the routing slip router Logic App`r`n Template File: $templateFile`r`n Parameter File: $templateParameterFile`r`n Deployment Name: $deploymentName`r`n"

az deployment group create --resource-group $resourceGroupName --template-file $templateFile --parameters $templateParameterFile "apimSubscriptionKey=$apimSubscriptionKey" --name $deploymentName

Write-Host "Deployment complete"
tools\templates\messagebus\workflows\routingsliprouter\Remove-RoutingSlipRouter-LogicApp.ps1
<#
.SYNOPSIS
Tears down the Logic App.

.DESCRIPTION
Prior to running this script ensure you are authenticated against Azure and have the desired subscription set.

.PARAMETER resourceGroup
The name of the resource group containing the resources to remove.

.PARAMETER workflowName
The name of the Logic App to find the resource.

.EXAMPLE
./Remove-RoutingSlipRouter-LogicApp.ps1 -resourceGroupName "rg-aimmsgbus-dev-uksouth-xxxxx" -workflowName "AimRoutingSlipRouter-xxxxx"
#>

[CmdletBinding()]
Param(
    [parameter(Mandatory = $true)]
    [string] $resourceGroupName,
    [parameter(Mandatory = $true)]
    [string] $workflowName
)

$resourceExists = az resource show --resource-group $resourceGroupName  --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

if ($resourceExists) {
    Write-Host "Removing the Logic App $workflowName"

    az resource delete --resource-group $resourceGroupName --name $workflowName --namespace "Microsoft.Logic" --resource-type "workflows"

    Write-Host "Removed the Logic App $workflowName"
}
else {
    Write-Host "The Logic App $workflowName does not exist in resource group $resourceGroupName"
}
tools\templates\messagebus\workflows\routingsliprouter\routingsliprouter.logicapp.dev.parameters.json.liquid
 
tools\templates\messagebus\workflows\routingsliprouter\routingsliprouter.logicapp.json
{
    "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
    "contentVersion": "1.0.0.0",
    "parameters": {
        "logicAppName": {
            "type": "string",
            "minLength": 1,
            "maxLength": 80,
            "metadata": {
                "description": "Name of this LogicApp."
            }
        },
        "logicAppLocation": {
            "type": "string",
            "defaultValue": "[resourceGroup().location]",
            "metadata": {
                "description": "Location (region) or ISE that this LogicApp is to be deployed to. Defaults to the ResourceGroup location."
            }
        },
        "logicAppStartupState": {
            "type": "string",
            "defaultValue": "Enabled",
            "allowedValues": [ "Enabled", "Disabled" ],
            "metadata": {
                "description": "Initial state of the LogicApp after it is deployed."
            }
        },
        "messageBusResourceGroupName": {
            "type": "String",
            "defaultValue": "[resourceGroup().name]",
            "metadata": {
                "description": "Name of the ResourceGroup that APIM is deployed to (if different from the ResourceGroup that this LogicApp is deployed to)."
            }
        },
        "apimServiceName": {
            "type": "string",
            "metadata": {
                "description": "Name of the APIM Service used for MessageBus operations."
            }
        },
        "apimSubscriptionKey": {
            "type": "securestring",
            "metadata": {
                "description": "Subscription Key used to access APIM."
            }
        },
        "apimRetryPolicy": {
            "type": "object",
            "defaultValue": {
                "count": 3,
                "interval": "PT5S",
                "type": "fixed"
            },
            "metadata": {
                "description": "Retry Policy to use when calling APIM."
            }
        },
        "scenarioStep": {
            "defaultValue": "routingSlipRouter",
            "type": "string",
            "metadata": {
                "description": "The step within a Scenario that this LogicApp is running under e.g. routingSlipRouter."
            }
        },
        "tags": {
            "type": "object"
        }
    },
    "variables": {
        "apimServiceResourceId": "[resourceId(parameters('messageBusResourceGroupName'), 'Microsoft.ApiManagement/service', parameters('apimServiceName'))]",
        "routingManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimroutingmanager')]",
        "configurationManagerApiResourceId": "[concat(variables('apimServiceResourceId'), '/apis/aimconfigurationmanager')]"
    },
    "resources": [
        {
            "type": "Microsoft.Logic/workflows",
            "apiVersion": "2017-07-01",
            "name": "[parameters('logicAppName')]",
            "location": "[parameters('logicAppLocation')]",
            "tags": "[parameters('tags')]",
            "properties": {
                "state": "[parameters('logicAppStartupState')]",
                "definition": {
                    "$schema": "https://schema.management.azure.com/providers/Microsoft.Logic/schemas/2016-06-01/workflowdefinition.json#",
                    "contentVersion": "1.0.0.0",
                    "parameters": {
                        "scenarioStep": {
                            "type": "String",
                            "description": "The step within a Scenario that this LogicApp is running under e.g. routingSlipRouter."
                        },
                        "apimSubscriptionKey": {
                            "type": "SecureString",
                            "description": "Subscription Key used to access APIM."
                        }
                    },
                    "triggers": {
                        "manual": {
                            "correlation": {
                                "clientTrackingId": "@coalesce(triggerBody()?['header']?['properties']?['trackingId'], guid())"
                            },
                            "type": "Request",
                            "kind": "Http",
                            "inputs": {
                                "schema": {}
                            }
                        }
                    },
                    "actions": {
                        "Initialize_StatusCode_variable": {
                            "runAfter": {},
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "StatusCode",
                                        "type": "integer",
                                        "value": 500
                                    }
                                ]
                            }
                        },
                        "Initialize_FaultMessage_variable": {
                            "runAfter": {
                                "Initialize_StatusCode_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "FaultMessage",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_ErrorMessage_variable": {
                            "runAfter": {
                                "Initialize_FaultMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ErrorMessage",
                                        "type": "string",
                                        "value": "An error occurred in the @{workflow()?['name']} (@{workflow()?['run']?['name']}) LogicApp"
                                    }
                                ]
                            }
                        },
                        "Initialize_ResponseMessage_variable": {
                            "runAfter": {
                                "Initialize_ErrorMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ResponseMessage",
                                        "type": "object",
                                        "value": null
                                    }
                                ]
                            }
                        },
                        "Initialize_Checkpoint_variable": {
                            "runAfter": {
                                "Initialize_ResponseMessage_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Checkpoint",
                                        "type": "string"
                                    }
                                ]
                            }
                        },
                        "Initialize_Envelope_variable": {
                            "runAfter": {
                                "Initialize_Checkpoint_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Envelope",
                                        "type": "object",
                                        "value": "@triggerBody()"
                                    }
                                ]
                            }
                        },
                        "Initialize_Configuration_variable": {
                            "runAfter": {
                                "Initialize_Envelope_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Configuration",
                                        "type": "object"
                                    }
                                ]
                            }
                        },
                        "Initialize_RouteIndex_variable": {
                            "runAfter": {
                                "Initialize_Configuration_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "RouteIndex",
                                        "type": "integer",
                                        "value": -1
                                    }
                                ]
                            }
                        },
                        "Set_RouteIndex_variable": {
                            "runAfter": {
                                "Initialize_RouteIndex_variable": [
                                    "Succeeded"
                                ]
                            },
                            "type": "SetVariable",
                            "inputs": {
                                "name": "RouteIndex",
                                "value": "@int(coalesce(triggerBody()?['header']?['routingSlip']?['nextRoute'], '-1'))"
                            }
                        },
                        "Initialize_Route_variable": {
                            "runAfter": {
                                "Set_RouteIndex_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "Route",
                                        "type": "object",
                                        "value": "@triggerBody()?['header']?['routingSlip']?['routes']?[variables('RouteIndex')]"
                                    }
                                ]
                            }
                        },
                        "Initialize_ChannelType_variable": {
                            "runAfter": {
                                "Initialize_Route_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "type": "InitializeVariable",
                            "inputs": {
                                "variables": [
                                    {
                                        "name": "ChannelType",
                                        "type": "string",
                                        "value": "@variables('Route')?['routingSteps']?['channelType']"
                                    }
                                ]
                            }
                        },
                        "MessageSender:_Were_we_successful": {
                            "actions": {
                                "Success:_Send_ACK_response": {
                                    "runAfter": {},
                                    "type": "Response",
                                    "kind": "Http",
                                    "inputs": {
                                        "body": "@variables('ResponseMessage')",
                                        "headers": {
                                            "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                            "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                            "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                            "Content-Type": "application/json"
                                        },
                                        "statusCode": 200
                                    }
                                }
                            },
                            "runAfter": {
                                "Step:_Process_Channel": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "else": {
                                "actions": {
                                    "Failure:_Build_NACK_message": {
                                        "runAfter": {},
                                        "type": "Compose",
                                        "inputs": {
                                            "body": [
                                                {
                                                    "$content": {
                                                        "code": "500",
                                                        "message": "@variables('ErrorMessage')",
                                                        "lastCheckpoint": "@variables('Checkpoint')",
                                                        "fault": "@variables('FaultMessage')"
                                                    },
                                                    "$contentType": "application/json",
                                                    "$part": 1,
                                                    "$partType": "http://schemas.microsoft.com/aim#nack"
                                                }
                                            ],
                                            "header": {
                                                "properties": {
                                                    "createDate": "@utcNow()",
                                                    "envelopeType": "nack",
                                                    "messageId": "@guid()",
                                                    "rootPart": 1,
                                                    "trackingId": "@triggerBody()?['header']?['properties']?['trackingId']"
                                                },
                                                "routing": {
                                                    "MessageType": "http://schemas.microsoft.com/aim#nack"
                                                },
                                                "routingSlip": {},
                                                "state": {}
                                            }
                                        }
                                    },
                                    "Failure:_Send_NACK_response": {
                                        "runAfter": {
                                            "Failure:_Build_NACK_message": [
                                                "Succeeded"
                                            ]
                                        },
                                        "type": "Response",
                                        "kind": "Http",
                                        "inputs": {
                                            "body": "@outputs('Failure:_Build_NACK_message')",
                                            "headers": {
                                                "Aim-Clear-Cache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                "Aim-Enable-Trace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)",
                                                "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                "Content-Type": "application/json"
                                            },
                                            "statusCode": 200
                                        }
                                    }
                                }
                            },
                            "expression": {
                                "or": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "NoMoreRoutes"
                                        ]
                                    },
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "ProcessChannel"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Get_Configuration": {
                            "actions": {
                                "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": {
                                    "runAfter": {},
                                    "type": "ApiManagement",
                                    "inputs": {
                                        "api": {
                                            "id": "[variables('configurationManagerApiResourceId')]"
                                        },
                                        "method": "get",
                                        "pathTemplate": {
                                            "parameters": {
                                                "scenario": "@{encodeURIComponent(triggerBody()?['header']?['properties']?['scenario'])}",
                                                "step": "@{encodeURIComponent(parameters('scenarioStep'))}"
                                            },
                                            "template": "/aimconfigurationmanager/configuration/{scenario}/{step}"
                                        },
                                        "queries": {
                                            "clearCache": "@{coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], 'false')}"
                                        },
                                        "retryPolicy": "[parameters('apimRetryPolicy')]",
                                        "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                    }
                                },
                                "GetConfiguration:_Check_Status_Code": {
                                    "runAfter": {
                                        "GetConfiguration:_Set_StatusCode_variable": [
                                            "Succeeded"
                                        ]
                                    },
                                    "cases": {
                                        "Success": {
                                            "case": 200,
                                            "actions": {
                                                "GetConfiguration:Success:_Set_Checkpoint_variable": {
                                                    "runAfter": {
                                                        "GetConfiguration:Success:_Set_Configuration_variable": [
                                                            "Succeeded"
                                                        ]
                                                    },
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Checkpoint",
                                                        "value": "GetConfiguration"
                                                    }
                                                },
                                                "GetConfiguration:Success:_Set_Configuration_variable": {
                                                    "runAfter": {},
                                                    "type": "SetVariable",
                                                    "inputs": {
                                                        "name": "Configuration",
                                                        "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                    }
                                                }
                                            }
                                        }
                                    },
                                    "default": {
                                        "actions": {
                                            "GetConfiguration:Failure:_Do_we_have_a_Fault_Message": {
                                                "actions": {
                                                    "GetConfiguration:Fault:_Set_ErrorMessage_variable": {
                                                        "runAfter": {
                                                            "GetConfiguration:Fault:_Set_FaultMessage_variable": [
                                                                "Succeeded"
                                                            ]
                                                        },
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                        }
                                                    },
                                                    "GetConfiguration:Fault:_Set_FaultMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "FaultMessage",
                                                            "value": "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')"
                                                        }
                                                    }
                                                },
                                                "runAfter": {},
                                                "else": {
                                                    "actions": {
                                                        "GetConfiguration:NoFault:_Create_Fault_Message": {
                                                            "runAfter": {},
                                                            "type": "Compose",
                                                            "inputs": {
                                                                "fault": {
                                                                    "faultActor": "@concat(workflow()?['name'], '.', actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                    "faultCategory": "Error",
                                                                    "faultCode": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['statusCode'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['code'])}",
                                                                    "faultMessage": "@{coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'], outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['body']?['message'], actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['error']?['message'])}",
                                                                    "faultReason": "@{actions('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['status']}"
                                                                }
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_ErrorMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Set_FaultMessage_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "ErrorMessage",
                                                                "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the ConfigurationManager GetConfigurationForStep operation"
                                                            }
                                                        },
                                                        "GetConfiguration:NoFault:_Set_FaultMessage_variable": {
                                                            "runAfter": {
                                                                "GetConfiguration:NoFault:_Create_Fault_Message": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "FaultMessage",
                                                                "value": "@outputs('GetConfiguration:NoFault:_Create_Fault_Message')"
                                                            }
                                                        }
                                                    }
                                                },
                                                "expression": {
                                                    "and": [
                                                        {
                                                            "not": {
                                                                "equals": [
                                                                    "@body('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['fault']",
                                                                    null
                                                                ]
                                                            }
                                                        }
                                                    ]
                                                },
                                                "type": "If"
                                            }
                                        }
                                    },
                                    "expression": "@variables('StatusCode')",
                                    "type": "Switch"
                                },
                                "GetConfiguration:_Set_StatusCode_variable": {
                                    "runAfter": {
                                        "GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep": [
                                            "Succeeded",
                                            "Failed",
                                            "Skipped",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "StatusCode",
                                        "value": "@coalesce(outputs('GetConfiguration:_Call_APIM_ConfigurationManager.GetConfigurationForStep')?['statusCode'], 500)"
                                    }
                                }
                            },
                            "runAfter": {
                                "Initialize_ChannelType_variable": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            ""
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Check_if_have_processed_all_routes": {
                            "actions": {
                                "Have_we_processed_all_routes": {
                                    "actions": {
                                        "NoMoreRoutes:_Build_ACK": {
                                            "runAfter": {},
                                            "type": "Compose",
                                            "inputs": {
                                                "body": [
                                                    {
                                                        "$content": "No more routes to process",
                                                        "$contentType": "text/plain",
                                                        "$part": 1,
                                                        "$partType": "http://schemas.microsoft.com/aim#ack"
                                                    }
                                                ],
                                                "header": {
                                                    "properties": {
                                                        "createDate": "@{utcNow()}",
                                                        "envelopeType": "ack",
                                                        "messageId": "@{guid()}",
                                                        "rootPart": 1,
                                                        "trackingId": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                        "correlationId": "@{triggerBody()?['header']?['properties']?['messageId']}"
                                                    },
                                                    "routing": {
                                                        "MessageType": "http://schemas.microsoft.com/aim#ack"
                                                    },
                                                    "routingSlip": {},
                                                    "state": {}
                                                }
                                            }
                                        },
                                        "NoMoreRoutes:_Set_ResponseMessage": {
                                            "runAfter": {
                                                "NoMoreRoutes:_Build_ACK": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "ResponseMessage",
                                                "value": "@outputs('NoMoreRoutes:_Build_ACK')"
                                            }
                                        },
                                        "NoMoreRoutes:_Set_Checkpoint_variable": {
                                            "runAfter": {
                                                "NoMoreRoutes:_Set_ResponseMessage": [
                                                    "Succeeded"
                                                ]
                                            },
                                            "type": "SetVariable",
                                            "inputs": {
                                                "name": "Checkpoint",
                                                "value": "NoMoreRoutes"
                                            }
                                        }
                                    },
                                    "runAfter": {},
                                    "else": {
                                        "actions": {
                                            "RoutesToProcess:_Set_Checkpoint_variable": {
                                                "runAfter": {},
                                                "type": "SetVariable",
                                                "inputs": {
                                                    "name": "Checkpoint",
                                                    "value": "RoutesToProcess"
                                                }
                                            }
                                        }
                                    },
                                    "expression": {
                                        "or": [
                                            {
                                                "greaterOrEquals": [
                                                    "@variables('RouteIndex')",
                                                    "@length(triggerBody()?['header']?['routingSlip']?['routes'])"
                                                ]
                                            },
                                            {
                                                "less": [
                                                    "@variables('RouteIndex')",
                                                    0
                                                ]
                                            }
                                        ]
                                    },
                                    "type": "If"
                                }
                            },
                            "runAfter": {
                                "Step:_Get_Configuration": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "GetConfiguration"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        },
                        "Step:_Process_Channel": {
                            "actions": {
                                "ProcessChannel:Failure:_Get_Failed_Items": {
                                    "runAfter": {
                                        "ProcessChannel:_Exception_Scope": [
                                            "Failed",
                                            "TimedOut"
                                        ]
                                    },
                                    "type": "Query",
                                    "inputs": {
                                        "from": "@result('ProcessChannel:_Exception_Scope')",
                                        "where": "@or(equals(item()['status'], 'Failed'), equals(item()['status'], 'TimedOut'))"
                                    }
                                },
                                "ProcessChannel:Failure:_Set_ErrorMessage_variable": {
                                    "runAfter": {
                                        "ProcessChannel:Failure:_Get_Failed_Items": [
                                            "Succeeded"
                                        ]
                                    },
                                    "type": "SetVariable",
                                    "inputs": {
                                        "name": "ErrorMessage",
                                        "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) in an ExceptionScope. Error: Action: @{body('ProcessChannel:Failure:_Get_Failed_Items')?[0]?['name']}, StatusCode: @{body('ProcessChannel:Failure:_Get_Failed_Items')?[0]?['outputs']?['statusCode']}, Message: @{concat(body('ProcessChannel:Failure:_Get_Failed_Items')?[0]?['error']?['message'], body('ProcessChannel:Failure:_Get_Failed_Items')?[0]?['outputs']?['body']?['message'])}"
                                    }
                                },
                                "ProcessChannel:_Exception_Scope": {
                                    "actions": {
                                        "ProcessChannel:_Switch_on_ChannelType": {
                                            "runAfter": {},
                                            "cases": {
                                                "APIM": {
                                                    "case": "microsoft.channels.trigger.azure-apim",
                                                    "actions": {
                                                        "APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute": {
                                                            "runAfter": {},
                                                            "type": "ApiManagement",
                                                            "inputs": {
                                                                "api": {
                                                                    "id": "[variables('routingManagerApiResourceId')]"
                                                                },
                                                                "body": "@triggerBody()",
                                                                "headers": {
                                                                    "Aim-Tracking-Id": "@{triggerBody()?['header']?['properties']?['trackingId']}",
                                                                    "Content-Transfer-Encoding": "none",
                                                                    "Content-Type": "application/json"
                                                                },
                                                                "method": "post",
                                                                "pathTemplate": {
                                                                    "parameters": {},
                                                                    "template": "/aimroutingmanager/sendtonextroute"
                                                                },
                                                                "queries": {
                                                                    "clearCache": "@coalesce(triggerOutputs()?['headers']?['Aim-Clear-Cache'], false)",
                                                                    "enableTrace": "@coalesce(triggerOutputs()?['headers']?['Aim-Enable-Trace'], false)"
                                                                },
                                                                "retryPolicy": "[parameters('apimRetryPolicy')]",
                                                                "subscriptionKey": "@{parameters('apimSubscriptionKey')}"
                                                            }
                                                        },
                                                        "APIMRouting:_Check_StatusCode": {
                                                            "runAfter": {
                                                                "APIMRouting:_Set_StatusCode_variable": [
                                                                    "Succeeded"
                                                                ]
                                                            },
                                                            "cases": {
                                                                "Success": {
                                                                    "case": 200,
                                                                    "actions": {
                                                                        "APIMRouting:Success:_Set_Checkpoint_variable": {
                                                                            "runAfter": {
                                                                                "APIMRouting:Success:_Set_ResponseMessage_variable": [
                                                                                    "Succeeded"
                                                                                ]
                                                                            },
                                                                            "type": "SetVariable",
                                                                            "inputs": {
                                                                                "name": "Checkpoint",
                                                                                "value": "ProcessChannel"
                                                                            }
                                                                        },
                                                                        "APIMRouting:Success:_Set_ResponseMessage_variable": {
                                                                            "runAfter": {},
                                                                            "type": "SetVariable",
                                                                            "inputs": {
                                                                                "name": "ResponseMessage",
                                                                                "value": "@body('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')"
                                                                            }
                                                                        }
                                                                    }
                                                                }
                                                            },
                                                            "default": {
                                                                "actions": {
                                                                    "APIMRouting:Failure:_Do_we_have_a_Fault_Message": {
                                                                        "actions": {
                                                                            "APIMRouting:Fault:_Set_ErrorMessage_variable": {
                                                                                "runAfter": {
                                                                                    "APIMRouting:Fault:_Set_FaultMessage_variable": [
                                                                                        "Succeeded"
                                                                                    ]
                                                                                },
                                                                                "type": "SetVariable",
                                                                                "inputs": {
                                                                                    "name": "ErrorMessage",
                                                                                    "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager SendToNextRoute operation"
                                                                                }
                                                                            },
                                                                            "APIMRouting:Fault:_Set_FaultMessage_variable": {
                                                                                "runAfter": {},
                                                                                "type": "SetVariable",
                                                                                "inputs": {
                                                                                    "name": "FaultMessage",
                                                                                    "value": "@body('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')"
                                                                                }
                                                                            }
                                                                        },
                                                                        "runAfter": {},
                                                                        "else": {
                                                                            "actions": {
                                                                                "APIMRouting:NoFault:_Create_Fault_Message": {
                                                                                    "runAfter": {},
                                                                                    "type": "Compose",
                                                                                    "inputs": {
                                                                                        "fault": {
                                                                                            "faultActor": "@concat(workflow()?['name'], '.', actions('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['name'], ' (', workflow()?['run']?['name'], ')')",
                                                                                            "faultCategory": "Error",
                                                                                            "faultCode": "@{coalesce(outputs('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['statusCode'], outputs('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['body']?['statusCode'], actions('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['error']?['code'])}",
                                                                                            "faultMessage": "@{coalesce(outputs('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['error']?['message'], outputs('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['body']?['message'], actions('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['error']?['message'])}",
                                                                                            "faultReason": "@{actions('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['status']}"
                                                                                        }
                                                                                    }
                                                                                },
                                                                                "APIMRouting:NoFault:_Set_ErrorMessage_variable": {
                                                                                    "runAfter": {
                                                                                        "APIMRouting:NoFault:_Set_FaultMessage_variable": [
                                                                                            "Succeeded"
                                                                                        ]
                                                                                    },
                                                                                    "type": "SetVariable",
                                                                                    "inputs": {
                                                                                        "name": "ErrorMessage",
                                                                                        "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}) trying to call the MessageManager SendToNextRoute operation"
                                                                                    }
                                                                                },
                                                                                "APIMRouting:NoFault:_Set_FaultMessage_variable": {
                                                                                    "runAfter": {
                                                                                        "APIMRouting:NoFault:_Create_Fault_Message": [
                                                                                            "Succeeded"
                                                                                        ]
                                                                                    },
                                                                                    "type": "SetVariable",
                                                                                    "inputs": {
                                                                                        "name": "FaultMessage",
                                                                                        "value": "@outputs('APIMRouting:NoFault:_Create_Fault_Message')"
                                                                                    }
                                                                                }
                                                                            }
                                                                        },
                                                                        "expression": {
                                                                            "and": [
                                                                                {
                                                                                    "not": {
                                                                                        "equals": [
                                                                                            "@body('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')?['fault']",
                                                                                            null
                                                                                        ]
                                                                                    }
                                                                                }
                                                                            ]
                                                                        },
                                                                        "type": "If"
                                                                    }
                                                                }
                                                            },
                                                            "expression": "@variables('StatusCode')",
                                                            "type": "Switch"
                                                        },
                                                        "APIMRouting:_Set_StatusCode_variable": {
                                                            "runAfter": {
                                                                "APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute": [
                                                                    "Succeeded",
                                                                    "Failed",
                                                                    "TimedOut",
                                                                    "Skipped"
                                                                ]
                                                            },
                                                            "type": "SetVariable",
                                                            "inputs": {
                                                                "name": "StatusCode",
                                                                "value": "@coalesce(outputs('APIMRouting:_Call_APIM_RoutingManager.SendToNextRoute')['statusCode'], 500)"
                                                            }
                                                        }
                                                    }
                                                }
                                            },
                                            "default": {
                                                "actions": {
                                                    "Unsupported_ChannelType:_Set_ErrorMessage_variable": {
                                                        "runAfter": {},
                                                        "type": "SetVariable",
                                                        "inputs": {
                                                            "name": "ErrorMessage",
                                                            "value": "An error occurred in @{workflow()?['name']} (@{workflow()?['run']?['name']}): Have an unsupported ChannelType value of @{coalesce(variables('ChannelType'), '(not supplied)')}"
                                                        }
                                                    }
                                                }
                                            },
                                            "expression": "@variables('ChannelType')",
                                            "type": "Switch"
                                        }
                                    },
                                    "runAfter": {},
                                    "type": "Scope"
                                }
                            },
                            "runAfter": {
                                "Step:_Check_if_have_processed_all_routes": [
                                    "Succeeded",
                                    "Failed",
                                    "Skipped",
                                    "TimedOut"
                                ]
                            },
                            "expression": {
                                "and": [
                                    {
                                        "equals": [
                                            "@variables('Checkpoint')",
                                            "RoutesToProcess"
                                        ]
                                    }
                                ]
                            },
                            "type": "If"
                        }
                    },
                    "outputs": {}
                },
                "parameters": {
                    "scenarioStep": {
                        "value": "[parameters('scenarioStep')]"
                    },
                    "apimSubscriptionKey": {
                        "value": "[parameters('apimSubscriptionKey')]"
                    }
                }
            }
        }
    ]
}
tools\templates\messagebus\workflows\routingsliprouter\routingsliprouter.logicapp.prod.parameters.json.liquid
 
tools\templates\messagebus\workflows\routingsliprouter\TearDown-80-RoutingSlipRouter-LogicApp.ps1.liquid
 
tools\templates\messages\schemas\Deploy-100-Schema.ps1.liquid
 
tools\templates\messages\schemas\New-Schema.ps1.liquid
 
tools\templates\messages\schemas\Remove-Schema.ps1.liquid
 
tools\templates\messages\schemas\requestbody.dev.json.liquid
 
tools\templates\messages\schemas\requestbody.prod.json.liquid
 
tools\templates\messages\schemas\TearDown-100-Schema.ps1.liquid
 
tools\templates\messages\transforms\Deploy-120-Map.ps1.liquid
 
tools\templates\messages\transforms\New-Map.ps1.liquid
 
tools\templates\messages\transforms\Remove-Map.ps1.liquid
 
tools\templates\messages\transforms\requestbody.dev.json.liquid
 
tools\templates\messages\transforms\requestbody.prod.json.liquid
 
tools\templates\messages\transforms\TearDown-120-Map.ps1.liquid
 
tools\templates\TearDown-All.ps1.liquid
 

Log in or click on link to see number of positives.

In cases where actual malware is found, the packages are subject to removal. Software sometimes has false positives. Moderators do not necessarily validate the safety of the underlying software, only that a package retrieves software from the official distribution point and/or validate embedded software against official distribution point (where distribution rights allow redistribution).

Chocolatey Pro provides runtime protection from possible malware.

Add to Builder Version Downloads Last Updated Status
BizTalk Migrator Dependency - Azure Templates 0.5.1-beta-2020102943006 248 Thursday, October 29, 2020 Exempted
BizTalk Migrator Dependency - Azure Templates 0.5.1-beta-2020102860442 99 Wednesday, October 28, 2020 Exempted
BizTalk to Azure Integration Services Migration - Azure templates 0.5.1-beta-2020102776889 58 Tuesday, October 27, 2020 Exempted
BizTalk to Azure Integration Services Migration - Azure templates 0.5.1-beta-2020102752953 67 Tuesday, October 27, 2020 Exempted
BizTalk to Azure Integration Services Migration - Azure templates 0.5.0-beta-2020102741772 73 Tuesday, October 27, 2020 Exempted
BizTalk to Azure Integration Services Migration - Azure templates 0.5.0-beta-2020102659679 70 Monday, October 26, 2020 Exempted
BizTalk to Azure Integration Services Migration - Azure templates 0.5.0-beta-2020102624119 80 Monday, October 26, 2020 Exempted

This package has no dependencies.

Discussion for the BizTalk Migrator Dependency - Azure Templates Package

Ground Rules:

  • This discussion is only about BizTalk Migrator Dependency - Azure Templates and the BizTalk Migrator Dependency - Azure Templates package. If you have feedback for Chocolatey, please contact the Google Group.
  • This discussion will carry over multiple versions. If you have a comment about a particular version, please note that in your comments.
  • The maintainers of this Chocolatey Package will be notified about new comments that are posted to this Disqus thread, however, it is NOT a guarantee that you will get a response. If you do not hear back from the maintainers after posting a message below, please follow up by using the link on the left side of this page or follow this link to contact maintainers. If you still hear nothing back, please follow the package triage process.
  • Tell us what you love about the package or BizTalk Migrator Dependency - Azure Templates, or tell us what needs improvement.
  • Share your experiences with the package, or extra configuration or gotchas that you've found.
  • If you use a url, the comment will be flagged for moderation until you've been whitelisted. Disqus moderated comments are approved on a weekly schedule if not sooner. It could take between 1-5 days for your comment to show up.
comments powered by Disqus