Find out which On-premises Data Gateways are used by which API connection resources
Published Apr 14 2021 08:48 PM 3,541 Views
Microsoft

API connections resources work as the bridges for Logic App to communicate with other services. While most of them are used to connect to cloud resources, a few of them leverage On-premises Data Gateways to connect local data sources to Azure. However, we may find that it is not easy to check which On-premises Data Gateway (OPDG) is used by which API connection resource.

 

Objective:

Find out which On-premises Data Gateways are used by which API connection resources.

 

Workaround:

The most known way to check OPDG used by a connector is by inspecting the Logic App designer.

  • When creating API connections with OPDG, we can find the OPDG used from the connection list in the Logic App designer.

Haozhou_1-1618390176942.png

 

However, this method seems unhandy as we need to go every Logic App’s designer mode and may cause unwanted change. My preferred way is to check the sourced OPDG from the JSON definition of an API connection resource.

  • From a Logic App, open the API connection blade, and choose the API connection which is using the OPDG.

Haozhou_2-1618390264236.png

 

  • From the API connection resource main page, click on “JSON View” on the far right.

Haozhou_3-1618390273643.png

 

  • In the JSON definition of the API connection, you will find the OPDG’s name, resource ID in the “properties” > “parameterValues” > “gateway”.

Haozhou_5-1618390350930.png

 

 

 

One more step:

As we have found out that OPDG information can be extracted from the JSON definition of an API connection resource. We can use a PowerShell script to find out all API connections which is using an OPDG.

 

Prerequisites:

 

Run the script:

  • After downloading the script into your machine, put in the name of your Azure subscription for the subscriptionName variable.

Haozhou_6-1618390630374.png

 

  • Then run the script and log into your Azure account in the pop-up window.

Haozhou_7-1618390690742.png

 

 

  • A CSV file named “output.csv” will be created in the same folder where the script resides.

Haozhou_8-1618390730600.png

 

  • The CSV file will contain all API connection resources along with the OPDGs they are using.

Haozhou_0-1618393681910.png

Columns:

connectionName: name of the API connection resource

connectionId: resource ID of the API connection

gatewayName: name of the On-premises Data Gateway resource

gatewatyId: resource ID of the On-premises Data Gateway

 

 

Notes:

  • If you encountered the "script not signed" error, you might try the below PowerShell command to bypass the security policy in the current session.
    Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass​

 

  • Alternative to run the script locally, you may choose to run this through Azure cloud shell. However, please remember the first command "Connect-AzAccount" as it will no longer be required.

 

Raw script:

 

# If you encountered "script is not signed error", please use below comand in the PowerShell first.
# Set-ExecutionPolicy -Scope Process -ExecutionPolicy Bypass

# Login to your Azure Account:
Connect-AzAccount

# Put in your own subscription name:
$subsctionName = ''

Set-AzContext -SubscriptionName $subsctionName

# Get all API connection resources 
$connectionList = Get-AzResource -ResourceType 'Microsoft.Web/connections'


# Loop through connection list
Write-Host '---------------------------------------'
Write-Host '  Start loop connections - Processing'
Write-Host '---------------------------------------'
$result = @()
foreach ($connection in $connectionList){
    $currentConnectionObj = Get-AzResource -ResourceId $connection.ResourceId
    $connectionName = $currentConnectionObj.Name
    $connectionId = $connection.ResourceId 
    Write-Host 'Processing connection:' $connectionName
    # Extract gateway information
    $opdgName = $currentConnectionObj.Properties.parameterValues.gateway.name
    $opdgId = $currentConnectionObj.Properties.parameterValues.gateway.id
    if (!($opdgId -eq $null)){
        Write-Host '------------------------------------------------'
        Write-Host 'OPDG found:'
        Write-Host 'Connection' $connectionName 'is using gateway' $opdgName
        Write-Host '------------------------------------------------'

        $new = [PSCustomObject]@{
            connectionName = $connectionName
            connectionId = $connectionId
            gatewayName = $opdgName
            gatewayId = $opdgId
        }

        $result += $new
    }
}

# Write collected information to output.csv file
$result | Export-Csv -Path .\output.csv -NoTypeInformation

 

 

 

 

1 Comment
Co-Authors
Version history
Last update:
‎Apr 14 2021 02:54 AM
Updated by: