|
Add this skill
npx mdskills install sickn33/azure-mgmt-apimanagement-pyComprehensive Azure APIM SDK reference with clear examples but lacks agent-specific instructions
1---2name: azure-mgmt-apimanagement-py3description: |4 Azure API Management SDK for Python. Use for managing APIM services, APIs, products, subscriptions, and policies.5 Triggers: "azure-mgmt-apimanagement", "ApiManagementClient", "APIM", "API gateway", "API Management".6package: azure-mgmt-apimanagement7---89# Azure API Management SDK for Python1011Manage Azure API Management services, APIs, products, and policies.1213## Installation1415```bash16pip install azure-mgmt-apimanagement17pip install azure-identity18```1920## Environment Variables2122```bash23AZURE_SUBSCRIPTION_ID=your-subscription-id24```2526## Authentication2728```python29from azure.identity import DefaultAzureCredential30from azure.mgmt.apimanagement import ApiManagementClient31import os3233client = ApiManagementClient(34 credential=DefaultAzureCredential(),35 subscription_id=os.environ["AZURE_SUBSCRIPTION_ID"]36)37```3839## Create APIM Service4041```python42from azure.mgmt.apimanagement.models import (43 ApiManagementServiceResource,44 ApiManagementServiceSkuProperties,45 SkuType46)4748service = client.api_management_service.begin_create_or_update(49 resource_group_name="my-resource-group",50 service_name="my-apim",51 parameters=ApiManagementServiceResource(52 location="eastus",53 publisher_email="admin@example.com",54 publisher_name="My Organization",55 sku=ApiManagementServiceSkuProperties(56 name=SkuType.DEVELOPER,57 capacity=158 )59 )60).result()6162print(f"Created APIM: {service.name}")63```6465## Import API from OpenAPI6667```python68from azure.mgmt.apimanagement.models import (69 ApiCreateOrUpdateParameter,70 ContentFormat,71 Protocol72)7374api = client.api.begin_create_or_update(75 resource_group_name="my-resource-group",76 service_name="my-apim",77 api_id="my-api",78 parameters=ApiCreateOrUpdateParameter(79 display_name="My API",80 path="myapi",81 protocols=[Protocol.HTTPS],82 format=ContentFormat.OPENAPI_JSON,83 value='{"openapi": "3.0.0", "info": {"title": "My API", "version": "1.0"}, "paths": {"/health": {"get": {"responses": {"200": {"description": "OK"}}}}}}'84 )85).result()8687print(f"Imported API: {api.display_name}")88```8990## Import API from URL9192```python93api = client.api.begin_create_or_update(94 resource_group_name="my-resource-group",95 service_name="my-apim",96 api_id="petstore",97 parameters=ApiCreateOrUpdateParameter(98 display_name="Petstore API",99 path="petstore",100 protocols=[Protocol.HTTPS],101 format=ContentFormat.OPENAPI_LINK,102 value="https://petstore.swagger.io/v2/swagger.json"103 )104).result()105```106107## List APIs108109```python110apis = client.api.list_by_service(111 resource_group_name="my-resource-group",112 service_name="my-apim"113)114115for api in apis:116 print(f"{api.name}: {api.display_name} - {api.path}")117```118119## Create Product120121```python122from azure.mgmt.apimanagement.models import ProductContract123124product = client.product.create_or_update(125 resource_group_name="my-resource-group",126 service_name="my-apim",127 product_id="premium",128 parameters=ProductContract(129 display_name="Premium",130 description="Premium tier with unlimited access",131 subscription_required=True,132 approval_required=False,133 state="published"134 )135)136137print(f"Created product: {product.display_name}")138```139140## Add API to Product141142```python143client.product_api.create_or_update(144 resource_group_name="my-resource-group",145 service_name="my-apim",146 product_id="premium",147 api_id="my-api"148)149```150151## Create Subscription152153```python154from azure.mgmt.apimanagement.models import SubscriptionCreateParameters155156subscription = client.subscription.create_or_update(157 resource_group_name="my-resource-group",158 service_name="my-apim",159 sid="my-subscription",160 parameters=SubscriptionCreateParameters(161 display_name="My Subscription",162 scope=f"/products/premium",163 state="active"164 )165)166167print(f"Subscription key: {subscription.primary_key}")168```169170## Set API Policy171172```python173from azure.mgmt.apimanagement.models import PolicyContract174175policy_xml = """176<policies>177 <inbound>178 <rate-limit calls="100" renewal-period="60" />179 <set-header name="X-Custom-Header" exists-action="override">180 <value>CustomValue</value>181 </set-header>182 </inbound>183 <backend>184 <forward-request />185 </backend>186 <outbound />187 <on-error />188</policies>189"""190191client.api_policy.create_or_update(192 resource_group_name="my-resource-group",193 service_name="my-apim",194 api_id="my-api",195 policy_id="policy",196 parameters=PolicyContract(197 value=policy_xml,198 format="xml"199 )200)201```202203## Create Named Value (Secret)204205```python206from azure.mgmt.apimanagement.models import NamedValueCreateContract207208named_value = client.named_value.begin_create_or_update(209 resource_group_name="my-resource-group",210 service_name="my-apim",211 named_value_id="backend-api-key",212 parameters=NamedValueCreateContract(213 display_name="Backend API Key",214 value="secret-key-value",215 secret=True216 )217).result()218```219220## Create Backend221222```python223from azure.mgmt.apimanagement.models import BackendContract224225backend = client.backend.create_or_update(226 resource_group_name="my-resource-group",227 service_name="my-apim",228 backend_id="my-backend",229 parameters=BackendContract(230 url="https://api.backend.example.com",231 protocol="http",232 description="My backend service"233 )234)235```236237## Create User238239```python240from azure.mgmt.apimanagement.models import UserCreateParameters241242user = client.user.create_or_update(243 resource_group_name="my-resource-group",244 service_name="my-apim",245 user_id="newuser",246 parameters=UserCreateParameters(247 email="user@example.com",248 first_name="John",249 last_name="Doe"250 )251)252```253254## Operation Groups255256| Group | Purpose |257|-------|---------|258| `api_management_service` | APIM instance management |259| `api` | API operations |260| `api_operation` | API operation details |261| `api_policy` | API-level policies |262| `product` | Product management |263| `product_api` | Product-API associations |264| `subscription` | Subscription management |265| `user` | User management |266| `named_value` | Named values/secrets |267| `backend` | Backend services |268| `certificate` | Certificates |269| `gateway` | Self-hosted gateways |270271## Best Practices2722731. **Use named values** for secrets and configuration2742. **Apply policies** at appropriate scopes (global, product, API, operation)2753. **Use products** to bundle APIs and manage access2764. **Enable Application Insights** for monitoring2775. **Use backends** to abstract backend services2786. **Version your APIs** using APIM's versioning features279
Full transparency — inspect the skill content before installing.