Imposible to delete Azure API Management - Standard V1
I can't delete APIM Standard V1 instances. The stv1 instances are no longer supported by Microsoft. I have upgraded all the APIM instances to stv2 but can't get rid of old stv1 instances. It always in "Deletefailed" state.
I have tried following api call to delete the soft deleted instance
But get following error:
{
"error": {
"code": "ServiceNotFound",
"message": "Api service does not exist: apim-ali-arhs-dv-eus2-01",
"details": null,
"innerError": null
}
}
Azure API Management
-
Khadeer Ali • 2,945 Reputation points • Microsoft Vendor
2025-01-30T17:32:39.62+00:00 @Wayne Yuan ,
Welcome to Microsoft Q&A Platform!Thanks for reaching out.I understand the frustration of dealing with stuck soft-deleted APIM instances, especially since Standard V1 is no longer supported. Since you've already upgraded your instances to STV2, but the old STV1 instances are failing to delete, let’s go through a step-by-step approach to resolve this.
- Verify if the Instance is Soft-Deleted
Before attempting deletion, let's check whether the instance is still in a soft-deleted state. Run the following API call:
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/deletedservices?api-version=2024-05-01
This will return a list of all soft-deleted APIM instances in your subscription.
- If your instance is listed, note the
deletionDate
andscheduledPurgeDate
. If it's past the 48-hour retention period, Azure should have automatically purged it—if not, you’ll need to manually force a purge. - Try Manually Purging the Instance
If the instance is still listed in the soft-deleted state, try running this purge API call:
DELETE https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/locations/{location}/deletedservices/{serviceName}?api-version=2024-05-01
This will permanently remove the APIM instance. Ensure you have the required RBAC permissions:
-
Microsoft.ApiManagement/locations/deletedservices/delete
-
Microsoft.ApiManagement/deletedservices/read
If you don’t have these permissions, you may need an Azure admin to grant them at the subscription level.
- Check if the Instance is Already Purged
If the purge request fails with "ServiceNotFound", it’s possible the instance was already permanently deleted by Azure. You can confirm this by running:
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/locations/{location}/deletedservices/{serviceName}?api-version=2024-05-01
If this also returns "ServiceNotFound", then the instance no longer exists, and you should be able to reuse the name after some time.
- Alternative: Recover and Delete Again
If the instance is stuck and won’t purge, you can try recovering it and then deleting it again. Run:
PUT https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroup}/providers/Microsoft.ApiManagement/service/{serviceName}?api-version=2024-05-01
With this body (Example):
{ "properties": { "publisherEmail": "******@contoso.com", "publisherName": "Contoso", "restore": true }, "sku": { "name": "Developer", "capacity": 1 }, "location": "South Central US" }
Once restored, you can attempt deletion again via the portal or API.
The same is mentioned in the below reference document: API Management soft-delete (preview)
After trying these steps, if the issue still persists, please let us know so that we can check for any alternative methods to delete Azure API Management - Standard V1.
Let me know if you need any further assistance!
-
Khadeer Ali • 2,945 Reputation points • Microsoft Vendor
2025-01-31T15:42:48.57+00:00 I wanted to check in and see if my earlier response addressed your question. If you still need assistance or have additional questions, feel free to share more details.
-
Wayne Yuan • 0 Reputation points
2025-01-31T21:11:13.3166667+00:00 Thank you for your suggestions. I have tried to verify if the instance is soft-deleted. I got following response: It is empty. But the soft-deleted instance appears in the azure portal. Here are the screenshots.
Thanks for your help!
{ "value": [] }
GET https://management.azure.com/subscriptions/{subscriptionId}/providers/Microsoft.ApiManagement/deletedservices?api-version=2024-05-01
-
Khadeer Ali • 2,945 Reputation points • Microsoft Vendor
2025-02-04T14:08:59.0566667+00:00 Thanks for your response! Before proceeding further, could you please check the following:
Is the APIM instance linked to a Virtual Network (VNet)?
- If yes, try removing the VNet association first and then attempt deletion.
Are there any locks on the APIM resource?
- Go to Azure Portal > APIM Instance > Locks and check if any Read-Only or Delete-Protected locks are attached.
- If locks exist, remove them and then try deleting the instance again.
Let me know what you find, and we can troubleshoot further if needed.
-
Wayne Yuan • 0 Reputation points
2025-02-04T16:58:02.2+00:00 Yes, the APIM had been set as internal, it has linked to a VNET. But I could not remove the VNET association. it throws following error:
There is no lock for the APIM instance
Thanks,
Wayne
-
Wayne Yuan • 0 Reputation points
2025-02-04T17:02:25.9466667+00:00 Thanks for your suggestions!
Yes, the APIM instance does have a VNET association, but I could not remove it. It throws following errors:
No, there is no lock for this APIM instance.
Thanks!
-
Khadeer Ali • 2,945 Reputation points • Microsoft Vendor
2025-02-05T12:07:21.06+00:00 @Wayne Yuan,You're encountering an "Invalid state transition" error while attempting to remove the VNet link from your APIM instance. Let's troubleshoot this systematically.
- Manual VNet Disassociation:
Azure Portal: Navigate to your APIM instance in the portal, then to the "Virtual Network" section. Attempt to change the connectivity type to "None" and save the changes.
- Azure CLI (if portal method fails): Execute the following command, substituting
<serviceName>
and<resourceGroupName>
with your actual values:az apim update --name <serviceName> --resource-group <resourceGroupName> --virtual-network ``""``
- Provisioning State Check:
- Azure Portal: On the overview page of your APIM instance, examine the provisioning state for any errors (e.g., "Failed" or "Updating").
- APIM Service Restart (if necessary): If the provisioning state appears stuck, try restarting the APIM service using the following CLI command:
az resource invoke-action --action restart --resource-type Microsoft.ApiManagement/service --name <serviceName> --resource-group <resourceGroupName>
- Activity Log Review:
- Azure Portal: Go to "Monitor" > "Activity Log." Filter the logs by your APIM instance to identify any failed operations related to the VNet removal.
If these steps do not resolve the issue, please provide further details, and we will explore alternative solutions.
-
Wayne Yuan • 0 Reputation points
2025-02-05T17:35:42.8333333+00:00 I just ran this command az apim update --name apim-ali-arhs-dv-eus2-01 --resource-group rg-ali-arhs-apim-dv-eus2-01 --virtual-network 'None'
I got following error
(InvalidParameters) Invalid parameter: 'virtualNetworkType' cannot be 'none' when 'virtualNetworkConfiguration' is not null
Code: InvalidParameters
Message: Invalid parameter: 'virtualNetworkType' cannot be 'none' when 'virtualNetworkConfiguration' is not null
I don't know to set 'virtualNetworkConfiguration' to null in CLI, please advise.
Thanks
Wayne
-
Wayne Yuan • 0 Reputation points
2025-02-05T17:39:41.7633333+00:00 I also try this command and got following error
PS C:\Users\A1055126\OneDrive - Alight Solutions\Azure\PaaS> az apim update --name apim-ali-arhs-dv-eus2-01 --resource-group rg-ali-arhs-apim-dv-eus2-01 --set virtualNetworkConfiguration=null
(InvalidOperation) Invalid state transition from TerminationFailed to Updating
Code: InvalidOperation
Message: Invalid state transition from TerminationFailed to Updating
-
Khadeer Ali • 2,945 Reputation points • Microsoft Vendor
2025-02-10T14:01:31.13+00:00 Thanks for the Patience. Did you get a chance to delete the virtual network using the cmd as mentioned in the below url:
https://learn.microsoft.com/en-us/cli/azure/network/vnet?view=azure-cli-latest#az-network-vnet-deleteOnce check if you could delete and later try deleting the APIM.
-
Wayne Yuan • 0 Reputation points
2025-02-10T14:18:49.0266667+00:00 We can't delete the VNET since it contains other production resources.
Can we delete subnet instead?
-
Khadeer Ali • 2,945 Reputation points • Microsoft Vendor
2025-02-10T14:47:21.95+00:00 This issue requires one-on-one live troubleshooting and may necessitate involving the engineering team for more in-depth investigation. I recommend raising a support case to proceed with further troubleshooting.
Sign in to comment