Generated banner for Azure Mgmt Apimanagement Dotnet
Generated logo for Azure Mgmt Apimanagement Dotnet

Azure Mgmt Apimanagement Dotnet

MicrosoftOfficialCreated by Microsoft

  • Skill
  • Tool integration
  • Cloud and DevOps
  • MIT
  • No issues found

From the author

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", "create APIM", "manage APIs", "ApiManagementServiceResource", "API policies", "APIM products", "APIM subscriptions".
— the description by Microsoft

AutoGineer summary

Written by AutoGineer from the skill’s own files, not by the author

The Azure.ResourceManager.ApiManagement SDK provides a .NET interface for interacting with the Azure API Management (APIM) management plane. It enables developers to automate the lifecycle of APIM resources, including service provisioning, API definition, product management, subscription handling, and policy configuration. This SDK is intended for infrastructure-as-code and automation scenarios rather than direct data-plane traffic management.

What it does

  • Provision and configure Azure API Management service instances.
  • Define and manage APIs, including importing from OpenAPI specifications.
  • Create and manage products, subscriptions, and access control groups.
  • Apply and update XML-based policies at service or API levels.
  • Handle API versioning, revisions, and backup/restore operations.
  • Manage user accounts and group memberships within the APIM environment.

When to use it

  • When automating the deployment of API Management infrastructure.
  • When integrating APIM resource management into CI/CD pipelines.
  • When programmatically managing API subscriptions or product access.
  • When applying consistent policy configurations across multiple API environments.

Advantages

  • Strongly-typed .NET interface for Azure Resource Manager operations.
  • Supports idempotent resource creation via CreateOrUpdate patterns.
  • Native integration with Azure Identity for secure authentication.
  • Comprehensive coverage of the APIM management plane hierarchy.

Usage examples

“How do I create a new API Management service using the .NET SDK?”
The agent provides a code snippet demonstrating the instantiation of ApiManagementServiceData and the use of the service collection's CreateOrUpdateAsync method.
“Show me how to add a rate-limit policy to an API.”
The agent provides a C# example showing the creation of a PolicyContractData object containing the XML policy and applying it to an ApiResource.
“How can I import an OpenAPI specification into my APIM service?”
The agent provides a code example using ApiCreateOrUpdateContent with the ContentFormat.OpenApiJson property to import an API definition.
“How do I list all subscriptions for an APIM service?”
The agent provides a code snippet using an asynchronous foreach loop to iterate through the service's GetApiManagementSubscriptions collection.

Install

  1. Download the skill as a ZIP:

    https://mp-staging.autogineer.com/agent-skills/microsoft/azure-mgmt-apimanagement-dotnet/download
  2. Unzip it into the cross-client skills folder of your project:

    mkdir -p .agents/skills && unzip azure-mgmt-apimanagement-dotnet.zip -d .agents/skills

Documentation by Microsoft

Azure.ResourceManager.ApiManagement (.NET)

Management plane SDK for provisioning and managing Azure API Management resources via Azure Resource Manager.

⚠️ Management vs Data Plane

  • This SDK (Azure.ResourceManager.ApiManagement): Create services, APIs, products, subscriptions, policies, users, groups

  • Data Plane: Direct API calls to your APIM gateway endpoints

Installation

dotnet add package Azure.ResourceManager.ApiManagement
dotnet add package Azure.Identity

Current Version: v1.3.0

Environment Variables

AZURE_SUBSCRIPTION_ID=<your-subscription-id> # Required: Azure subscription ID
AZURE_TOKEN_CREDENTIALS=prod  # Required only if DefaultAzureCredential is used in production
AZURE_TENANT_ID=<tenant-id> # For service principal auth (optional)
AZURE_CLIENT_ID=<client-id> # For service principal auth (optional)
AZURE_CLIENT_SECRET=<client-secret> # For service principal auth (optional)

Authentication

using Azure.Identity;
using Azure.ResourceManager;
using Azure.ResourceManager.ApiManagement;

// Local dev: DefaultAzureCredential. Production: set AZURE_TOKEN_CREDENTIALS=prod or AZURE_TOKEN_CREDENTIALS=<specific_credential>
var credential = new DefaultAzureCredential(
    DefaultAzureCredential.DefaultEnvironmentVariableName
);
// Or use a specific credential directly in production:
// See https://learn.microsoft.com/dotnet/api/overview/azure/identity-readme?view=azure-dotnet#credential-classes
// var credential = new ManagedIdentityCredential();
var armClient = new ArmClient(credential);

// Get subscription
var subscriptionId = Environment.GetEnvironmentVariable("AZURE_SUBSCRIPTION_ID");
var subscription = armClient.GetSubscriptionResource(
    new ResourceIdentifier($"/subscriptions/{subscriptionId}"));

Resource Hierarchy

ArmClient
└── SubscriptionResource
    └── ResourceGroupResource
        └── ApiManagementServiceResource
            ├── ApiResource
            │   ├── ApiOperationResource
            │   │   └── ApiOperationPolicyResource
            │   ├── ApiPolicyResource
            │   ├── ApiSchemaResource
            │   └── ApiDiagnosticResource
            ├── ApiManagementProductResource
            │   ├── ProductApiResource
            │   ├── ProductGroupResource
            │   └── ProductPolicyResource
            ├── ApiManagementSubscriptionResource
            ├── ApiManagementPolicyResource
            ├── ApiManagementUserResource
            ├── ApiManagementGroupResource
            ├── ApiManagementBackendResource
            ├── ApiManagementGatewayResource
            ├── ApiManagementCertificateResource
            ├── ApiManagementNamedValueResource
            └── ApiManagementLoggerResource

Core Workflow

1. Create API Management Service
using Azure.ResourceManager.ApiManagement;
using Azure.ResourceManager.ApiManagement.Models;

// Get resource group
var resourceGroup = await subscription
    .GetResourceGroupAsync("my-resource-group");

// Define service
var serviceData = new ApiManagementServiceData(
    location: AzureLocation.EastUS,
    sku: new ApiManagementServiceSkuProperties(
        ApiManagementServiceSkuType.Developer, 
        capacity: 1),
    publisherEmail: "[email protected]",
    publisherName: "Contoso");

// Create service (long-running operation - can take 30+ minutes)
var serviceCollection = resourceGroup.Value.GetApiManagementServices();
var operation = await serviceCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-apim-service",
    serviceData);

ApiManagementServiceResource service = operation.Value;
2. Create an API
var apiData = new ApiCreateOrUpdateContent
{
    DisplayName = "My API",
    Path = "myapi",
    Protocols = { ApiOperationInvokableProtocol.Https },
    ServiceUri = new Uri("https://backend.contoso.com/api")
};

var apiCollection = service.GetApis();
var apiOperation = await apiCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-api",
    apiData);

ApiResource api = apiOperation.Value;
3. Create a Product
var productData = new ApiManagementProductData
{
    DisplayName = "Starter",
    Description = "Starter tier with limited access",
    IsSubscriptionRequired = true,
    IsApprovalRequired = false,
    SubscriptionsLimit = 1,
    State = ApiManagementProductState.Published
};

var productCollection = service.GetApiManagementProducts();
var productOperation = await productCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "starter",
    productData);

ApiManagementProductResource product = productOperation.Value;

// Add API to product
await product.GetProductApis().CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-api");
4. Create a Subscription
var subscriptionData = new ApiManagementSubscriptionCreateOrUpdateContent
{
    DisplayName = "My Subscription",
    Scope = $"/products/{product.Data.Name}",
    State = ApiManagementSubscriptionState.Active
};

var subscriptionCollection = service.GetApiManagementSubscriptions();
var subOperation = await subscriptionCollection.CreateOrUpdateAsync(
    WaitUntil.Completed,
    "my-subscription",
    subscriptionData);

ApiManagementSubscriptionResource subscription = subOperation.Value;

// Get subscription keys
var keys = await subscription.GetSecretsAsync();
Console.WriteLine($"Primary Key: {keys.Value.PrimaryKey}");
5. Set API Policy
var policyXml = @"
<policies>
    <inbound>
        <rate-limit calls=""100"" renewal-period=""60"" />
        <set-header name=""X-Custom-Header"" exists-action=""override"">
            <value>CustomValue</value>
        </set-header>
        <base />
    </inbound>
    <backend>
        <base />
    </backend>
    <outbound>
        <base />
    </outbound>
    <on-error>
        <base />
    </on-error>
</policies>";

var policyData = new PolicyContractData
{
    Value = policyXml,
    Format = PolicyContentFormat.Xml
};

await api.GetApiPolicy().CreateOrUpdateAsync(
    WaitUntil.Completed,
    policyData);
6. Backup and Restore
// Backup
var backupParams = new ApiManagementServiceBackupRestoreContent(
    storageAccount: "mystorageaccount",
    containerName: "apim-backups",
    backupName: "backup-2024-01-15")
{
    AccessType = StorageAccountAccessType.SystemAssignedManagedIdentity
};

await service.BackupAsync(WaitUntil.Completed, backupParams);

// Restore
await service.RestoreAsync(WaitUntil.Completed, backupParams);

Key Types Reference

TypePurpose
ArmClientEntry point for all ARM operations
ApiManagementServiceResourceRepresents an APIM service instance
ApiManagementServiceCollectionCollection for service CRUD
ApiResourceRepresents an API
ApiManagementProductResourceRepresents a product
ApiManagementSubscriptionResourceRepresents a subscription
ApiManagementPolicyResourceService-level policy
ApiPolicyResourceAPI-level policy
ApiManagementUserResourceRepresents a user
ApiManagementGroupResourceRepresents a group
ApiManagementBackendResourceRepresents a backend service
ApiManagementGatewayResourceRepresents a self-hosted gateway

SKU Types

SKUPurposeCapacity
DeveloperDevelopment/testing (no SLA)1
BasicEntry-level production1-2
StandardMedium workloads1-4
PremiumHigh availability, multi-region1-12 per region
ConsumptionServerless, pay-per-callN/A

Best Practices

  1. Use WaitUntil.Completed for operations that must finish before proceeding

  2. Use WaitUntil.Started for long operations like service creation (30+ min)

  3. Always use DefaultAzureCredential — never hardcode keys

  4. Handle RequestFailedException for ARM API errors

  5. Use CreateOrUpdateAsync for idempotent operations

  6. Navigate hierarchy via Get* methods (e.g., service.GetApis())

  7. Policy format — Use XML format for policies; JSON is also supported

  8. Service creation — Developer SKU is fastest for testing (~15-30 min)

Error Handling

using Azure;

try
{
    var operation = await serviceCollection.CreateOrUpdateAsync(
        WaitUntil.Completed, serviceName, serviceData);
}
catch (RequestFailedException ex) when (ex.Status == 409)
{
    Console.WriteLine("Service already exists");
}
catch (RequestFailedException ex) when (ex.Status == 400)
{
    Console.WriteLine($"Bad request: {ex.Message}");
}
catch (RequestFailedException ex)
{
    Console.WriteLine($"ARM Error: {ex.Status} - {ex.ErrorCode}: {ex.Message}");
}

Reference Files

FileWhen to Read
references/service-management.mdService CRUD, SKUs, networking, backup/restore
references/apis-operations.mdAPIs, operations, schemas, versioning
references/products-subscriptions.mdProducts, subscriptions, access control
references/policies.mdPolicy XML patterns, scopes, common policies
ResourcePurpose
API Management DocumentationOfficial Azure docs
Policy ReferenceComplete policy reference
SDK Reference.NET API reference

Files

references/apis-operations.md

APIs and Operations

Patterns for managing APIs, operations, and schemas.

Create API from OpenAPI

var apiData = new ApiCreateOrUpdateContent
{
    DisplayName = "Pet Store API",
    Path = "petstore",
    Protocols = { ApiOperationInvokableProtocol.Https },
    // Import from OpenAPI spec
    Format = ContentFormat.OpenApiJson,
    Value = File.ReadAllText("petstore-openapi.json"),
    // Or from URL
    // Format = ContentFormat.OpenApiJsonLink,
    // Value = "https://petstore.swagger.io/v2/swagger.json"
};

var api = await service.GetApis()
    .CreateOrUpdateAsync(WaitUntil.Completed, "petstore-api", apiData);

Create API Manually

var apiData = new ApiCreateOrUpdateContent
{
    DisplayName = "Custom API",
    Path = "custom",
    Protocols = { ApiOperationInvokableProtocol.Https },
    ServiceUri = new Uri("https://backend.contoso.com"),
    SubscriptionKeyParameterNames = new SubscriptionKeyParameterNamesContract
    {
        Header = "X-API-Key",
        Query = "api-key"
    }
};

var api = await service.GetApis()
    .CreateOrUpdateAsync(WaitUntil.Completed, "custom-api", apiData);

List APIs

await foreach (var api in service.GetApis())
{
    Console.WriteLine($"{api.Data.DisplayName}: {api.Data.Path}");
}

Create Operation

var operationData = new ApiOperationData
{
    DisplayName = "Get Users",
    Method = "GET",
    UrlTemplate = "/users",
    Description = "Retrieves all users",
    Responses =
    {
        new ResponseContract(200)
        {
            Description = "Success",
            Representations =
            {
                new RepresentationContract("application/json")
            }
        }
    }
};

var operation = await api.Value.GetApiOperations()
    .CreateOrUpdateAsync(WaitUntil.Completed, "get-users", operationData);

Operation with Parameters

var operationData = new ApiOperationData
{
    DisplayName = "Get User by ID",
    Method = "GET",
    UrlTemplate = "/users/{userId}",
    TemplateParameters =
    {
        new ParameterContract("userId")
        {
            Description = "User identifier",
            ParameterContractType = "string",
            IsRequired = true
        }
    },
    Request = new RequestContract
    {
        QueryParameters =
        {
            new ParameterContract("include")
            {
                Description = "Related data to include",
                ParameterContractType = "string",
                IsRequired = false
            }
        }
    }
};

API Versioning

// Create version set
var versionSetData = new ApiVersionSetData
{
    DisplayName = "My API Versions",
    VersioningScheme = VersioningScheme.Segment // or Header, Query
};

var versionSet = await service.GetApiVersionSets()
    .CreateOrUpdateAsync(WaitUntil.Completed, "my-api-versions", versionSetData);

// Create versioned API
var apiV1Data = new ApiCreateOrUpdateContent
{
    DisplayName = "My API v1",
    Path = "myapi",
    ApiVersion = "v1",
    ApiVersionSetId = versionSet.Value.Id,
    Protocols = { ApiOperationInvokableProtocol.Https }
};

var apiV2Data = new ApiCreateOrUpdateContent
{
    DisplayName = "My API v2",
    Path = "myapi",
    ApiVersion = "v2",
    ApiVersionSetId = versionSet.Value.Id,
    Protocols = { ApiOperationInvokableProtocol.Https }
};

API Revisions

// Create revision
var revisionData = new ApiCreateOrUpdateContent
{
    SourceApiId = api.Value.Id,
    Path = api.Value.Data.Path,
    ApiRevisionDescription = "Added new endpoint"
};

var revision = await service.GetApis()
    .CreateOrUpdateAsync(WaitUntil.Completed, "my-api;rev=2", revisionData);

// Make revision current
await revision.Value.UpdateAsync(WaitUntil.Completed, 
    new ApiCreateOrUpdateContent { IsCurrent = true });

Delete API

await api.Value.DeleteAsync(WaitUntil.Completed);

Requirements and compatibility

Works with: Claude Code, Claude apps, OpenAI Codex, GitHub Copilot, Cursor, Gemini CLI, Kiro, OpenCode, Goose, Amp, Roo Code, JetBrains Junie, Factory Droid, Devin (ex-Windsurf), Mistral Vibe, OpenHands, Letta

“Works with” means the tool reads the open Agent Skills format; a skill written for one tool may use features others lack.

Security

No issues found by our static scan· No issues found

A static scan is not a guarantee. Skills are third-party content: review a skill before you let an agent use it.

Attribution and licence

Created by
Microsoft
Publisher
Microsoft (Official)
Source
microsoft/skills · .github/plugins/azure-sdk-dotnet/skills/azure-mgmt-apimanagement-dotnet · commit 0696600
Licence
MIT License (redistribution allowed)
  • LICENSE (added by AutoGineer from LICENSE)
  • ATTRIBUTION.md (written by AutoGineer)
Synced

AutoGineer is not affiliated with or endorsed by Microsoft.

Download ZIP

The ZIP holds the skill’s files, its licence files and an ATTRIBUTION.md. Download azure-mgmt-apimanagement-dotnet.zip