This guide helps you resolve common issues when working with the Azure API Management samples.
- Setup Issues
- Deployment Errors
- Authentication Issues
- Notebook and Development Environment Issues
- Azure CLI Issues
- Resource Management Issues
- Getting Additional Help
If you encounter import errors (e.g., ModuleNotFoundError: No module named 'requests' or cannot import shared modules), try these steps:
-
Fix Python path configuration:
python setup/local_setup.py --generate-env
-
Verify setup:
python setup/verify_local_setup.py
-
Restart VS Code after running the above commands.
-
Check Python interpreter: Use
Ctrl+Shift+P→ "Python: Select Interpreter" and choose your.venvinterpreter.
Error Message:
ERROR: The content for this response was already consumed
Root Cause: This misleading error message often indicates a Bicep template validation error, typically caused by parameter mismatches between the notebook and the Bicep template.
Solution:
-
Run the Azure CLI command with
--debugto see the actual error:az deployment group validate --resource-group <rg-name> --template-file "main.bicep" --parameters "params.json" --debug
-
Look for the real error in the debug output, often something like:
The following parameters were supplied, but do not correspond to any parameters defined in the template: 'parameterName' -
Check that all parameters in your notebook's
bicep_parametersdictionary match the parameters defined in themain.bicepfile.
Example Fix:
If the error mentions apimSku parameter not found:
# ❌ Incorrect - includes undefined/unexpected apimSku parameter
bicep_parameters = {
'apis': { 'value': [api.to_dict() for api in apis] },
'apimSku': { 'value': 'Developer' } # This parameter doesn't exist
}
# ✅ Correct - only includes defined parameters
bicep_parameters = {
'apis': { 'value': [api.to_dict() for api in apis] }
}Error Message:
The resource already exists and conflicts with...
Solution:
-
Use unique deployment names with timestamps:
az deployment group create --name "sample-$(date +%Y%m%d-%H%M%S)" ... -
Or delete existing conflicting resources:
az resource delete --ids /subscriptions/.../resourceGroups/.../providers/...
Error Message:
Unable to download the module...
Solution:
- Ensure you're running deployments from the correct directory (sample directory, not project root)
- Verify relative paths to shared modules are correct
- The utility function
create_bicep_deployment_group_for_sample()handles this automatically
Error Message:
Please run 'az login' to setup account
Solution:
az login
az account set --subscription "your-subscription-name-or-id"You may also need to log into specific tenants:
az login --tenant "your-tenant-name-or-id"
az account set --subscription "your-subscription-name-or-id"Error Message:
The client does not have authorization to perform action...
Solution:
-
Ensure you have the necessary role assignments:
- Contributor or Owner on the resource group/subscription
- API Management Service Contributor for APIM-specific operations
-
Check your current permissions:
az role assignment list --assignee $(az account show --query user.name -o tsv)
These can be a bit nebulous. When making changes to imported modules, they are not automatically picked up.
Error Message:
AttributeError: module 'utils' has no attribute 'function_name'
Solution:
Reload the utils module in your notebook by pressing Restart in the notebook to load updated files. You will need to re-run all cells from the beginning then as any variable assignments will have been lost.
Anti-pattern:
Avoid introducing a programmatic reload.
import importlib
importlib.reload(utils)Error Message:
ModuleNotFoundError: No module named 'utils'
Solution: Use the provided setup script:
python setup/local_setup.py --generate-envError Message:
FileNotFoundError: [Errno 2] No such file or directory: 'main.bicep'
Solution: Use the utility function that handles working directory management:
# ✅ Use this instead of manual directory management
output = utils.create_bicep_deployment_group_for_sample('sample-name', rg_name, rg_location, bicep_parameters)Error Message:
Rate limit exceeded
Solution:
- Wait a few minutes before retrying
- Reduce the frequency of API calls
- Use
--verboseto see retry information
Error Message:
The api-version '...' is invalid
Solution:
-
Update Azure CLI to the latest version:
az upgrade
-
Check for newer API versions in the Bicep templates
This is a bit cryptic. It's helpful to execute the az command from the error separately in the terminal and supply the --debug flag. You might then see errors such as this one:
Error Message:
cli.azure.cli.core.azclierror: [WinError 193] %1 is not a valid Win32 application
az_command_data_logger: [WinError 193] %1 is not a valid Win32 application
Scroll up to see what is executed.
Solution:
In one case, %USERPROFILE%\.azure\bin contained a bicep.exe file but with a zero-length. The CLI would recognize that the file is there but fail on execution.
- Verify that bicep is indeed failing:
az bicep version - Delete
%USERPROFILE%\.azure\bin\bicep.exe. - (Re)install bicep:
az bicep install. - Verify bicep:
az bicep version
When you delete Azure API Management services or Key Vaults, they are soft-deleted and remain recoverable for a period of time (typically 48 days for APIM, 90 days for Key Vault). These soft-deleted resources continue to reserve their names and can cause deployment conflicts.
Common Issues:
- Deployment fails with "Name already exists" even though resource appears deleted
- Cannot reuse the same name for a new APIM service or Key Vault
- Key Vault creation fails during infrastructure deployment
- Subscription quotas are affected by soft-deleted resources
Error During Infrastructure Deployment:
Creating Key Vault: kv-sbfc4encghfag
❌ Failed to create Key Vault: kv-sbfc4encghfag
This may be caused by a soft-deleted Key Vault with the same name.
Check for soft-deleted resources: python shared/python/show_soft_deleted_resources.py
Check for Soft-Deleted Resources:
# Using Python script (recommended)
python shared/python/show_soft_deleted_resources.py
# Manual check
az apim deletedservice list
az keyvault list-deletedPurge Soft-Deleted Resources:
# Purge all soft-deleted resources with confirmation
python shared/python/show_soft_deleted_resources.py --purge
# Purge without confirmation (use with caution!)
python shared/python/show_soft_deleted_resources.py --purge --yes
# Manual purge
az apim deletedservice purge --service-name <name> --location <location>
az keyvault purge --name <name> --location <location> --no-waitBest Practices:
- Check for soft-deleted resources before deploying with the same name
- Use unique names for resources to avoid conflicts
- Purge soft-deleted resources if you need to reuse the name immediately
- Consider using timestamps or random suffixes in resource names during development
Key Vaults can have purge protection enabled, which prevents them from being manually purged before their scheduled purge date. This is a security feature that cannot be disabled once enabled.
Error When Purging Protected Key Vaults:
(MethodNotAllowed) Operation 'DeletedVaultPurge' is not allowed.
Code: MethodNotAllowed
Message: Operation 'DeletedVaultPurge' is not allowed.
Identifying Purge Protection:
The show_soft_deleted_resources.py script automatically detects and displays purge protection status:
python shared/python/show_soft_deleted_resources.pySample output:
1/2:
Vault Name : kv-glgoiqn66pbnu
Location : eastus2
Deletion Date : 2025-12-13 10:30:00 UTC
Purge Date : 2026-03-12 10:30:00 UTC
Purge Protection : 🔒 ENABLED
Vault ID : /subscriptions/.../vaults/kv-glgoiqn66pbnu
⚠️ 1 vault(s) have PURGE PROTECTION enabled and cannot be manually purged.
These vaults will be automatically purged on their scheduled purge date.
Handling Purge-Protected Key Vaults:
- ✅ Recoverable: You can still recover the vault before the scheduled purge date
- ❌ Cannot purge manually: The vault cannot be purged until its scheduled purge date
- 💡 Use different names: Deploy new Key Vaults with different names
- 🔒 Security feature: This is by design to prevent accidental data loss
Recovery Option:
# Recover a soft-deleted Key Vault (even with purge protection)
az keyvault recover --name <vault-name>Error Message:
Resource group 'name' could not be found
Solution:
- Create the infrastructure first by running the appropriate infrastructure deployment from the
/infrastructure/folder - Verify the resource group name matches the expected pattern:
rg_name = get_infra_rg_name(deployment, index)
Error Message:
API Management service 'name' not found
Solution:
-
Ensure the infrastructure deployment completed successfully
-
Check that the APIM service exists:
az apim list --resource-group <rg-name>
-
Verify the naming pattern matches:
az resource list --resource-group <rg-name> --resource-type Microsoft.ApiManagement/service
Error Message:
403 Forbidden / Access denied errors when accessing storage
Solution:
- Azure role assignments can take 5-10 minutes to propagate
- Use the built-in permission verification utility:
permissions_ready = utils.wait_for_apim_blob_permissions( apim_name=apim_name, storage_account_name=storage_account_name, resource_group_name=rg_name, max_wait_minutes=5 )
For more detailed error information:
-
Azure CLI:
az deployment group create ... --verbose --debug
-
Python/Notebook:
import logging logging.basicConfig(level=logging.DEBUG)
- In the Azure Portal, navigate to your resource group
- Go to Activity log to see recent operations and any failures
- Look for failed deployments and click for detailed error messages
az deployment group validate --resource-group <rg-name> --template-file "main.bicep" --parameters "params.json"# Check Azure CLI version and authentication
az version
az account show
# List available resource groups
az group list --output table
# Check resource group contents
az resource list --resource-group <rg-name> --output table
# Validate Bicep template
az deployment group validate --resource-group <rg-name> --template-file main.bicep --parameters params.jsonIf you encounter issues not covered in this guide:
- Check existing issues: GitHub Issues
- Create a new issue with:
- Full error message
- Steps to reproduce
- Azure CLI version (
az version) - Python version
- Operating system