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"