Automating API Connection Key Update in Azure Logic App

Bansal, Ankit Kumar 25 Reputation points
2024-06-10T13:48:11.14+00:00

I'm currently working on a Logic App project where I'm utilizing an API connection for Azure Blob Storage. The authentication method for this API connection is via account key.

I'm aiming to automate the process of updating the account key for this API connection. However, despite my efforts to find the exposed API for this task, I've been unable to locate it.

Could you please assist me in automating this process or guide me to the exposed API for updating the account key?

Azure Logic Apps
Azure Logic Apps
An Azure service that automates the access and use of data across clouds without writing code.
2,951 questions
Azure Data Factory
Azure Data Factory
An Azure service for ingesting, preparing, and transforming data at scale.
9,939 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Amira Bedhiafi 18,261 Reputation points
    2024-06-10T19:09:03.65+00:00

    I think you can use Azure REST APIs or Azure CLI commands

    If you go gor Azure REST API, first you need to retrieve the current API connection details. You can use the following API endpoint :

    GET https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName}?api-version=2016-06-01
    

    Once you have the current API connection details, you can update the account key using the following API endpoint:

    PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName}?api-version=2016-06-01
    

    The request body should include the updated account key. Here's an example of the request body:

    {
      "properties": {
        "displayName": "AzureBlob",
        "parameterValues": {
          "accountKey": "{newAccountKey}"
        },
        "api": {
          "id": "/subscriptions/{subscriptionId}/providers/Microsoft.Web/locations/{location}/managedApis/azureblob"
        }
      }
    }
    

    If you want to use Azure CLI, after login try to retrieve the current API connect

    az resource show --id /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName} --api-version 2016-06-01
    

    Update the API connection :

    az resource update --id /subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Web/connections/{connectionName} --api-version 2016-06-01 --set properties.parameterValues.accountKey="{newAccountKey}"
    

    You can create a script or an Azure Function to automate this process. Here's an example script using Azure CLI:

    #!/bin/bash
    subscriptionId="<your-subscription-id>"
    resourceGroupName="<your-resource-group-name>"
    connectionName="<your-connection-name>"
    newAccountKey="<your-new-account-key>"
    # Login to Azure
    az login
    # Update the API connection
    az resource update --id /subscriptions/$subscriptionId/resourceGroups/$resourceGroupName/providers/Microsoft.Web/connections/$connectionName --api-version 2016-06-01 --set properties.parameterValues.accountKey="$newAccountKey"
    
    0 comments No comments