{"slug":"azure-mgmt-apimanagement-dotnet","title":"azure-mgmt-apimanagement-dotnet","summary":"Azure Resource Manager SDK for API Management in .NET. Use for MANAGEMENT PLANE operations: creating/managing APIM services, APIs, products, subscriptions, policies, users, groups, gateways, and backends via Azure Resource Manager. Triggers: \"API Management\", \"APIM service\", \"cre","platform":"GitHub Copilot","tags":[],"authorName":"Ciza","authorSlug":"ciza","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-08-12T21:05:12.89919Z","repo":{"url":"https://github.com/microsoft/skills","stars":3052,"forks":351,"license":"MIT","updatedAt":"2026-09-24T16:38:17Z"},"bodyHtml":"<hr>\n<h2>name: azure-mgmt-apimanagement-dotnet\ndescription: |\nAzure Resource Manager SDK for API Management in .NET. Use for MANAGEMENT PLANE operations: creating/managing APIM services, APIs, products, subscriptions, policies, users, groups, gateways, and backends via Azure Resource Manager. Triggers: \"API Management\", \"APIM service\", \"create APIM\", \"manage APIs\", \"ApiManagementServiceResource\", \"API policies\", \"APIM products\", \"APIM subscriptions\".\nlicense: MIT\nmetadata:\nauthor: Microsoft\nversion: \"1.0.0\"\npackage: Azure.ResourceManager.ApiManagement</h2>\n<h1>Azure.ResourceManager.ApiManagement (.NET)</h1>\n<p>Management plane SDK for provisioning and managing Azure API Management resources via Azure Resource Manager.</p>\n<blockquote>\n<p><strong>⚠️ Management vs Data Plane</strong></p>\n<ul>\n<li><strong>This SDK (Azure.ResourceManager.ApiManagement)</strong>: Create services, APIs, products, subscriptions, policies, users, groups</li>\n<li><strong>Data Plane</strong>: Direct API calls to your APIM gateway endpoints</li>\n</ul>\n</blockquote>\n<h2>Installation</h2>\n<pre><code>dotnet add package Azure.ResourceManager.ApiManagement\ndotnet add package Azure.Identity\n</code></pre>\n<p><strong>Current Version</strong>: v1.3.0</p>\n<h2>Environment Variables</h2>\n<pre><code>AZURE_SUBSCRIPTION_ID=&lt;your-subscription-id&gt; # Required: Azure subscription ID\nAZURE_TOKEN_CREDENTIALS=prod  # Required only if DefaultAzureCredential is used in production\nAZURE_TENANT_ID=&lt;tenant-id&gt; # For service principal auth (optional)\nAZURE_CLIENT_ID=&lt;client-id&gt; # For service principal auth (optional)\nAZURE_CLIENT_SECRET=&lt;client-secret&gt; # For service principal auth (optional)\n</code></pre>\n<h2>Authentication</h2>\n<pre><code>using Azure.Identity;\nusing Azure.ResourceManager;\nusing Azure.ResourceManager.ApiManagement;\n\n// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=&lt;specific_credential&gt;\nvar credential = new DefaultAzureCredential(\n    DefaultAzureCredential.DefaultEnvironmentVariableName\n);\n// Or use a specific credential directly in production:\n// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes\n// var credential = new ManagedIdentityCredential();\nvar armClient = new ArmClient(credential);\n\n// Get subscription\nvar subscriptionId = Environment.GetEnvironmentVariable(\"AZURE_SUBSCRIPTION_ID\");\nvar subscription = armClient.GetSubscriptionResource(\n    new ResourceIdentifier($\"/subscriptions/{subscriptionId}\"));\n</code></pre>\n<h2>Resource Hierarchy</h2>\n<pre><code>ArmClient\n└── SubscriptionResource\n    └── ResourceGroupResource\n        └── ApiManagementServiceResource\n            ├── ApiResource\n            │   ├── ApiOperationResource\n            │   │   └── ApiOperationPolicyResource\n            │   ├── ApiPolicyResource\n            │   ├── ApiSchemaResource\n            │   └── ApiDiagnosticResource\n            ├── ApiManagementProductResource\n            │   ├── ProductApiResource\n            │   ├── ProductGroupResource\n            │   └── ProductPolicyResource\n            ├── ApiManagementSubscriptionResource\n            ├── ApiManagementPolicyResource\n            ├── ApiManagementUserResource\n            ├── ApiManagementGroupResource\n            ├── ApiManagementBackendResource\n            ├── ApiManagementGatewayResource\n            ├── ApiManagementCertificateResource\n            ├── ApiManagementNamedValueResource\n            └── ApiManagementLoggerResource\n</code></pre>\n<h2>Core Workflow</h2>\n<h3>1. Create API Management Service</h3>\n<pre><code>using Azure.ResourceManager.ApiManagement;\nusing Azure.ResourceManager.ApiManagement.Models;\n\n// Get resource group\nvar resourceGroup = await subscription\n    .GetResourceGroupAsync(\"my-resource-group\");\n\n// Define service\nvar serviceData = new ApiManagementServiceData(\n    location: AzureLocation.EastUS,\n    sku: new ApiManagementServiceSkuProperties(\n        ApiManagementServiceSkuType.Developer, \n        capacity: 1),\n    publisherEmail: \"admin@contoso.com\",\n    publisherName: \"Contoso\");\n\n// Create service (long-running operation - can take 30+ minutes)\nvar serviceCollection = resourceGroup.Value.GetApiManagementServices();\nvar operation = await serviceCollection.CreateOrUpdateAsync(\n    WaitUntil.Completed,\n    \"my-apim-service\",\n    serviceData);\n\nApiManagementServiceResource service = operation.Value;\n</code></pre>\n<h3>2. Create an API</h3>\n<pre><code>var apiData = new ApiCreateOrUpdateContent\n{\n    DisplayName = \"My API\",\n    Path = \"myapi\",\n    Protocols = { ApiOperationInvokableProtocol.Https },\n    ServiceUri = new Uri(\"https://backend.contoso.com/api\")\n};\n\nvar apiCollection = service.GetApis();\nvar apiOperation = await apiCollection.CreateOrUpdateAsync(\n    WaitUntil.Completed,\n    \"my-api\",\n    apiData);\n\nApiResource api = apiOperation.Value;\n</code></pre>\n<h3>3. Create a Product</h3>\n<pre><code>var productData = new ApiManagementProductData\n{\n    DisplayName = \"Starter\",\n    Description = \"Starter tier with limited access\",\n    IsSubscriptionRequired = true,\n    IsApprovalRequired = false,\n    SubscriptionsLimit = 1,\n    State = ApiManagementProductState.Published\n};\n\nvar productCollection = service.GetApiManagementProducts();\nvar productOperation = await productCollection.CreateOrUpdateAsync(\n    WaitUntil.Completed,\n    \"starter\",\n    productData);\n\nApiManagementProductResource product = productOperation.Value;\n\n// Add API to product\nawait product.GetProductApis().CreateOrUpdateAsync(\n    WaitUntil.Completed,\n    \"my-api\");\n</code></pre>\n<h3>4. Create a Subscription</h3>\n<pre><code>var subscriptionData = new ApiManagementSubscriptionCreateOrUpdateContent\n{\n    DisplayName = \"My Subscription\",\n    Scope = $\"/products/{product.Data.Name}\",\n    State = ApiManagementSubscriptionState.Active\n};\n\nvar subscriptionCollection = service.GetApiManagementSubscriptions();\nvar subOperation = await subscriptionCollection.CreateOrUpdateAsync(\n    WaitUntil.Completed,\n    \"my-subscription\",\n    subscriptionData);\n\nApiManagementSubscriptionResource subscription = subOperation.Value;\n\n// Get subscription keys\nvar keys = await subscription.GetSecretsAsync();\nConsole.WriteLine($\"Primary Key: {keys.Value.PrimaryKey}\");\n</code></pre>\n<h3>5. Set API Policy</h3>\n<pre><code>var policyXml = @\"\n&lt;policies&gt;\n    &lt;inbound&gt;\n        &lt;rate-limit calls=\"\"100\"\" renewal-period=\"\"60\"\" /&gt;\n        &lt;set-header name=\"\"X-Custom-Header\"\" exists-action=\"\"override\"\"&gt;\n            &lt;value&gt;CustomValue&lt;/value&gt;\n        &lt;/set-header&gt;\n        &lt;base /&gt;\n    &lt;/inbound&gt;\n    &lt;backend&gt;\n        &lt;base /&gt;\n    &lt;/backend&gt;\n    &lt;outbound&gt;\n        &lt;base /&gt;\n    &lt;/outbound&gt;\n    &lt;on-error&gt;\n        &lt;base /&gt;\n    &lt;/on-error&gt;\n&lt;/policies&gt;\";\n\nvar policyData = new PolicyContractData\n{\n    Value = policyXml,\n    Format = PolicyContentFormat.Xml\n};\n\nawait api.GetApiPolicy().CreateOrUpdateAsync(\n    WaitUntil.Completed,\n    policyData);\n</code></pre>\n<h3>6. Backup and Restore</h3>\n<pre><code>// Backup\nvar backupParams = new ApiManagementServiceBackupRestoreContent(\n    storageAccount: \"mystorageaccount\",\n    containerName: \"apim-backups\",\n    backupName: \"backup-2024-01-15\")\n{\n    AccessType = StorageAccountAccessType.SystemAssignedManagedIdentity\n};\n\nawait service.BackupAsync(WaitUntil.Completed, backupParams);\n\n// Restore\nawait service.RestoreAsync(WaitUntil.Completed, backupParams);\n</code></pre>\n<h2>Key Types Reference</h2>\n<table>\n<thead>\n<tr>\n<th>Type</th>\n<th>Purpose</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>ArmClient</code></td>\n<td>Entry point for all ARM operations</td>\n</tr>\n<tr>\n<td><code>ApiManagementServiceResource</code></td>\n<td>Represents an APIM service instance</td>\n</tr>\n<tr>\n<td><code>ApiManagementServiceCollection</code></td>\n<td>Collection for service CRUD</td>\n</tr>\n<tr>\n<td><code>ApiResource</code></td>\n<td>Represents an API</td>\n</tr>\n<tr>\n<td><code>ApiManagementProductResource</code></td>\n<td>Represents a product</td>\n</tr>\n<tr>\n<td><code>ApiManagementSubscriptionResource</code></td>\n<td>Represents a subscription</td>\n</tr>\n<tr>\n<td><code>ApiManagementPolicyResource</code></td>\n<td>Service-level policy</td>\n</tr>\n<tr>\n<td><code>ApiPolicyResource</code></td>\n<td>API-level policy</td>\n</tr>\n<tr>\n<td><code>ApiManagementUserResource</code></td>\n<td>Represents a user</td>\n</tr>\n<tr>\n<td><code>ApiManagementGroupResource</code></td>\n<td>Represents a group</td>\n</tr>\n<tr>\n<td><code>ApiManagementBackendResource</code></td>\n<td>Represents a backend service</td>\n</tr>\n<tr>\n<td><code>ApiManagementGatewayResource</code></td>\n<td>Represents a self-hosted gateway</td>\n</tr>\n</tbody>\n</table>\n<h2>SKU Types</h2>\n<table>\n<thead>\n<tr>\n<th>SKU</th>\n<th>Purpose</th>\n<th>Capacity</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><code>Developer</code></td>\n<td>Development/testing (no SLA)</td>\n<td>1</td>\n</tr>\n<tr>\n<td><code>Basic</code></td>\n<td>Entry-level production</td>\n<td>1-2</td>\n</tr>\n<tr>\n<td><code>Standard</code></td>\n<td>Medium workloads</td>\n<td>1-4</td>\n</tr>\n<tr>\n<td><code>Premium</code></td>\n<td>High availability, multi-region</td>\n<td>1-12 per region</td>\n</tr>\n<tr>\n<td><code>Consumption</code></td>\n<td>Serverless, pay-per-call</td>\n<td>N/A</td>\n</tr>\n</tbody>\n</table>\n<h2>Best Practices</h2>\n<ol>\n<li><strong>Use <code>WaitUntil.Completed</code></strong> for operations that must finish before proceeding</li>\n<li><strong>Use <code>WaitUntil.Started</code></strong> for long operations like service creation (30+ min)</li>\n<li><strong>Always use <code>DefaultAzureCredential</code></strong> — never hardcode keys</li>\n<li><strong>Handle <code>RequestFailedException</code></strong> for ARM API errors</li>\n<li><strong>Use <code>CreateOrUpdateAsync</code></strong> for idempotent operations</li>\n<li><strong>Navigate hierarchy</strong> via <code>Get*</code> methods (e.g., <code>service.GetApis()</code>)</li>\n<li><strong>Policy format</strong> — Use XML format for policies; JSON is also supported</li>\n<li><strong>Service creation</strong> — Developer SKU is fastest for testing (~15-30 min)</li>\n</ol>\n<h2>Error Handling</h2>\n<pre><code>using Azure;\n\ntry\n{\n    var operation = await serviceCollection.CreateOrUpdateAsync(\n        WaitUntil.Completed, serviceName, serviceData);\n}\ncatch (RequestFailedException ex) when (ex.Status == 409)\n{\n    Console.WriteLine(\"Service already exists\");\n}\ncatch (RequestFailedException ex) when (ex.Status == 400)\n{\n    Console.WriteLine($\"Bad request: {ex.Message}\");\n}\ncatch (RequestFailedException ex)\n{\n    Console.WriteLine($\"ARM Error: {ex.Status} - {ex.ErrorCode}: {ex.Message}\");\n}\n</code></pre>\n<h2>Reference Files</h2>\n<table>\n<thead>\n<tr>\n<th>File</th>\n<th>When to Read</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"references/service-management.md\">references/service-management.md</a></td>\n<td>Service CRUD, SKUs, networking, backup/restore</td>\n</tr>\n<tr>\n<td><a href=\"references/apis-operations.md\">references/apis-operations.md</a></td>\n<td>APIs, operations, schemas, versioning</td>\n</tr>\n<tr>\n<td><a href=\"references/products-subscriptions.md\">references/products-subscriptions.md</a></td>\n<td>Products, subscriptions, access control</td>\n</tr>\n<tr>\n<td><a href=\"references/policies.md\">references/policies.md</a></td>\n<td>Policy XML patterns, scopes, common policies</td>\n</tr>\n</tbody>\n</table>\n<h2>Related Resources</h2>\n<table>\n<thead>\n<tr>\n<th>Resource</th>\n<th>Purpose</th>\n</tr>\n</thead>\n<tbody>\n<tr>\n<td><a href=\"https://learn.microsoft.com/en-us/azure/api-management/\">API Management Documentation</a></td>\n<td>Official Azure docs</td>\n</tr>\n<tr>\n<td><a href=\"https://learn.microsoft.com/en-us/azure/api-management/api-management-policies\">Policy Reference</a></td>\n<td>Complete policy reference</td>\n</tr>\n<tr>\n<td><a href=\"https://learn.microsoft.com/en-us/dotnet/api/azure.resourcemanager.apimanagement\">SDK Reference</a></td>\n<td>.NET API reference</td>\n</tr>\n</tbody>\n</table>\n","files":[{"path":"references/apis-operations.md","sizeBytes":3940,"isText":true},{"path":"references/products-subscriptions.md","sizeBytes":4116,"isText":true},{"path":"references/service-management.md","sizeBytes":4031,"isText":true},{"path":"SKILL.md","sizeBytes":10443,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-08-12T21:50:45.59623Z","sha256":"6BF41849BD3D4A9DD5FB75F9D1549385237330E63667A822EAF63507177D241E","sizeBytes":7206},"review":null,"source":{"repositoryUrl":"https://github.com/microsoft/skills","path":".github/plugins/azure-sdk-dotnet/skills/azure-mgmt-apimanagement-dotnet","license":"MIT","commit":"23d0dac5f83f268166a17f0bc7dc6c73dc348a33","subtreeSha":"0243318611C8173C8BA0E19C2E3430FFE8636CB516EB7FEA54803D200E79242F","lastSyncedAt":"2026-09-25T06:48:53.330584Z"},"reviewedAt":"2026-08-12T21:54:42.042776Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/microsoft/skills/tree/main/.github/plugins/azure-sdk-dotnet/skills/azure-mgmt-apimanagement-dotnet"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install microsoft-skills@llmmart"},{"target":"git","command":"git clone https://github.com/microsoft/skills.git"}]}