If you are using API Management you Might have noticed that there is no Azure Portal Access to view the Backends that are created automatically when you import you API from wherever. You might have also noticed it takes a ridiculously long time to provision and API Management resource. Therefore, destroying it completely and re-creating is less desirable than just cleaning up after yourself.

I ran into this issue because I’ve been experimenting with Azure Functions and have been importing them and deleting them and re-importing but this has been leaving some uncleanliness behind in the name of backends and named values that are orphaned once I remove the APIs and API operations referencing said backend.

Because backends are not easily accessible from the Azure Portal, I had to drop into PowerShell to do the clean up work. Below are the PowerShell commands to remove unused backends.

Here is the link to the Microsoft documentation on the API Management PowerShell module.

Make sure you have Azure PowerShell module installed…

Install-Module -Name Az -AllowClobber -Scope CurrentUser

Connect to your account…

Connect-AzAccount

Get API Management resources in a given resource group

Get-AzApiManagement -ResourceGroupName <String> -Name <String>

In order to do anything meaningful you need to get a context object that you can pass in to access sub-entities within the API Management resource

New-AzApiManagementContext -ResourceGroupName <String> -ServiceName <String>

Then you can retrieve a list of backends

Get-AzApiManagementBackend -Context <PsApiManagementContext>

And from here you can delete them

Remove-AzApiManagementBackend -Context <PsApiManagementContext> -BackendId <String>

As long as they aren’t being used…