K.J.M.O.
K.J.M.O.

Reputation: 227

Not able to retrieve Logic app (standard) Workflow URL from ARM template

I have tried to retrieve the HTTP trigger URL from my singel-tenant logic app, but without success.

using:

listCallbackUrl(resourceId('resource-group-name','Microsoft.Logic/workflows', 'logic-app-name', 'manual'), '2016-06-01').value

Also tried:

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Logic/workflows/{workflowName}/listCallbackUrl?api-version=2016-06-01

This does not find the actual workflow.

and

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/sites/{name}/functions/{functionName}/listsecrets?api-version=2019-08-01

This request returns an URL which seem to be a function URL but not the actual trigger URL. Any ideas why this doesn't work? Are there any work-arounds?

Upvotes: 3

Views: 6403

Answers (2)

Yasser
Yasser

Reputation: 874

To get the callback URL for a standard logic app workflow in ARM template:

[listCallbackUrl(resourceId('Microsoft.Web/sites/hostruntime/webhooks/api/workflows/triggers', parameters('logicAppName'), 'runtime', 'workflow', 'management', parameters('workflowName'), 'manual'),'2021-03-01').value]

To get the callback URL for a consumption logic app in ARM template:

[listCallbackUrl(resourceId('Microsoft.Logic/workflows/triggers', parameters('workflowName'), 'manual'),'2021-03-01').value]

Please check this article for further information:

https://github.com/yasseralissa/standard-logicapp-callbackurl

Upvotes: 3

ibda
ibda

Reputation: 508

I solved the problem by adding the following task (in the yaml file) exactly before the task that need to use this link:

          # getUrl
          - task: AzureCLI@2
            displayName: getLAUrl
            name: getLAUrl
            inputs:
              azureSubscription: "${{ parameters.connectedServiceName }}"
              scriptType: ps
              scriptLocation: inlineScript
              inlineScript: |
                $subscription = az account list --query "[?isDefault].id | [0]"
                $ResourceGroupName = "${{ parameters.LA_rg }}"
                $LogicAppName = "${{ parameters.LA_name }}-${{parameters.environment}}"
                $MyWorkflow = "${{ parameters.LA_workflow }}"
                
                $workflowDetails = az rest --method post --uri https://management.azure.com/subscriptions/$subscription/resourceGroups/$ResourceGroupName/providers/Microsoft.Web/sites/$LogicAppName/hostruntime/runtime/webhooks/workflow/api/management/workflows/$MyWorkflow/triggers/manual/listCallbackUrl?api-version=2018-11-01
                # Write-Host "$workflowDetails"

                echo "##vso[task.setvariable variable=WorkFlowDetails2]$workflowDetails"

This task will return a json object that contains the URL of the workflow (with some other stuff and details about this workflow) using cli commands (this cli command is working according to this issue). After getting this json $workflowDetails, I assigen this parameter to a variable called WorkFlowDetails2. WorkFlowDetails can now be accessed in other tasks inside the SAME job (if you want to use it inside other jobs you need to make it as output parameter). After thatyou can use this parameter normally in other task by calling something like: $(WorkFlowDetails)

So for e.g., if I need the workflow url to add it in namedValues in API management, I can have this task:

    - task: AzureResourceManagerTemplateDeployment@3
            displayName: DeployNamedValue
            inputs:
              deploymentScope: "Resource Group"
              ConnectedServiceName: "${{ parameters.connectedServiceName }}"
              action: "Create Or Update Resource Group"
              resourceGroupName: "${{ parameters.resourceGroup }}"
              location: ${{ parameters.location }} 
              templateLocation: "Linked artifact"
              csmFile: '$(Pipeline.Workspace)/allApiArtifact/namedValues-template.json'
              overrideParameters: '-LA_object_details $(WorkFlowDetails2) -LA_name ${{ parameters.LA_name }} -ApimServiceName ${{parameters.ApimServiceName}} -LA_workflow ${{parameters.LA_workflow}}' 
              deploymentMode: "Incremental"  

My named value template now will looks something like:

    {
       "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
      "contentVersion": "1.0.0.0",
      "parameters": {
        "ApimServiceName": {
          "type": "string",
          "defaultValue": "test"
        },
        "LA_name": {
          "type": "string",
          "defaultValue": "la_name"
        },
        "LA_workflow": {
          "type": "string",
          "defaultValue": "la_workflow" 
        },
        "LA_object_details": {
          "type": "object",
          "defaultValue": {
            "basePath": "",
            "method": "",
            "queries": {
              "api-version": "",
              "sig": "",
              "sp": "",
              "sv": ""
            },
            "value": ""
          }
        }
      },
      "variables":{
        "la_version": "2020-05-01-preview",
        "namedValue_prefix": "[split(parameters('LA_name'),'-')[0]]",
        "namedValue_name": "[concat(variables('namedValue_prefix'), 'Url')]"
      },
      "resources": [
        {
          "properties": {
            "tags": [],
            "secret": true,
            "displayName": "[variables('namedValue_name')]",
            "value": "[concat('/api/', parameters('LA_workflow'), '/triggers/manual/invoke?api-version=', variables('la_version'), '&sp=%2Ftriggers%2Fmanual%2Frun&sv=1.0&sig=', parameters('LA_object_details').queries.sig)]"
          },
          "name": "[concat(parameters('ApimServiceName'), '/', variables('namedValue_name'))]",
          "type": "Microsoft.ApiManagement/service/namedValues",
          "apiVersion": "2021-01-01-preview"
        }
    
      ]
    }

Upvotes: 2

Related Questions