Tutorial: Manage Azure API Management using the REST API

This tutorial demonstrates how to interact with Azure API Management (APIM) using its comprehensive REST API. You'll learn how to perform common management tasks such as creating APIs, operations, products, and policies programmatically.

Prerequisites

  • An active Azure subscription.
  • An Azure API Management instance deployed.
  • Tools to make HTTP requests (e.g., Postman, curl, or a programming language SDK).
  • Obtain your APIM gateway URL and subscription key.

Getting Started: Authentication

To interact with the APIM REST API, you need to authenticate. The most common method is using your APIM subscription key. This key is typically found in the Azure portal under your APIM instance's "Subscription keys" blade.

All requests to the APIM management plane must include the Ocp-Apim-Subscription-Key header with your primary or secondary subscription key.

Common Operations

1. Listing APIs

You can retrieve a list of all APIs configured in your APIM instance.

GET
https://{your-apim-service-name}.azure-api.net/api/apis?api-version=2021-04-01-preview

Headers:

Ocp-Apim-Subscription-Key: YOUR_APIM_SUBSCRIPTION_KEY

Accept: application/json

The response will be a JSON array of API objects.

2. Creating a New API

To create a new API, you'll make a PUT request with the API definition in the request body.

PUT
https://{your-apim-service-name}.azure-api.net/api/apis/{api-id}?api-version=2021-04-01-preview

Headers:

Ocp-Apim-Subscription-Key: YOUR_APIM_SUBSCRIPTION_KEY

Content-Type: application/json

Body:

{
  "properties": {
    "displayName": "My New API",
    "description": "API managed by REST API",
    "path": "mynewapi",
    "protocols": ["https"]
  }
}

Replace {api-id} with a unique identifier for your API (e.g., "mynewapi").

3. Creating an Operation

Once an API exists, you can add operations to it.

PUT
https://{your-apim-service-name}.azure-api.net/api/apis/{api-id}/operations/{operation-id}?api-version=2021-04-01-preview

Headers:

Ocp-Apim-Subscription-Key: YOUR_APIM_SUBSCRIPTION_KEY

Content-Type: application/json

Body:

{
  "properties": {
    "displayName": "Get Items",
    "method": "GET",
    "urlTemplate": "/items",
    "description": "Retrieves a list of items"
  }
}

Replace {api-id} with the ID of the API and {operation-id} with a unique identifier for the operation.

Managing Products

Products are bundles of APIs that you can expose to developers. You can also manage these via the REST API.

Creating a Product

PUT
https://{your-apim-service-name}.azure-api.net/products/{product-id}?api-version=2021-04-01-preview

Headers:

Ocp-Apim-Subscription-Key: YOUR_APIM_SUBSCRIPTION_KEY

Content-Type: application/json

Body:

{
  "properties": {
    "displayName": "Basic Product",
    "description": "A basic product with limited access.",
    "termsOfServiceUrl": "http://example.com/terms",
    "subscriptionRequired": true,
    "approvalRequired": false
  }
}

Next Steps

Explore the full Azure API Management REST API documentation to discover more capabilities, including managing policies, named values, subscriptions, and more.