title | description | ms.topic | ms.date | ms.custom | ms.service | author | ms.author | ms.devlang | zone_pivot_groups |
---|---|---|---|---|---|---|---|---|---|
Tutorial - Create and publish a product in Azure API Management | In this tutorial, you create and publish a product in Azure API Management. Once it's published, developers can begin to use the product's APIs. | tutorial | 10/22/2024 | devdivchpfy22, devx-track-azurecli | azure-api-management | dlepow | danlep | azurecli | api-management-howto-add-products |
[!INCLUDE api-management-availability-all-tiers]
In Azure API Management, a product contains one or more APIs, a usage quota, and the terms of use. After a product is published, developers can subscribe to the product and begin to use the product's APIs.
[!INCLUDE api-management-workspace-try-it]
:::zone pivot="interactive"
In this tutorial, you learn how to:
[!div class="checklist"]
- Create and publish a product
- Add an API to the product
- Access product APIs
:::image type="content" source="media/api-management-howto-add-products/added-product-1.png" alt-text="API Management products in portal":::
- Learn the Azure API Management terminology.
- Complete the following quickstart: Create an Azure API Management instance.
- Also, complete the following tutorial: Import and publish your first API.
Sign in to the Azure portal, and navigate to your API Management instance.
In the left navigation pane, select Products > + Add.
:::image type="content" source="media/api-management-howto-add-products/add-product-portal.png" alt-text="Add product in Azure portal":::
In the Add product window, enter values described in the following table to create your product.
:::image type="content" source="media/api-management-howto-add-products/add-product.png" alt-text="Add product window":::
Name Description Display name The name as you want it to be shown in the developer portal. Description Provide information about the product such as its purpose, the APIs it provides access to, and other details. State Select Published if you want to publish the product to the developer portal. Before the APIs in a product can be discovered by developers, the product must be published. By default, new products are unpublished. Requires subscription Select if a user is required to subscribe to use the product (the product is protected) and a subscription key must be used to access the product's APIs. If a subscription isn't required (the product is open), a subscription key isn't required to access the product's APIs. See Access to product APIs later in this article. Requires approval Select if you want an administrator to review and accept or reject subscription attempts to this product. If not selected, subscription attempts are auto-approved. Subscription count limit Optionally limit the count of multiple simultaneous subscriptions. Minimum value: 1 Legal terms You can include the terms of use for the product which subscribers must accept in order to use the product. APIs Select one or more APIs. You can also add APIs after creating the product. For more information, see Add APIs to a product later in this article.
If the product is open (doesn't require a subscription), you can only add an API that isn't associated with another open product.Select Create to create your new product.
Caution
Use care when configuring a product that doesn't require a subscription. This configuration may be overly permissive and may make the product's APIs more vulnerable to certain API security threats.
To begin using Azure CLI:
[!INCLUDE azure-cli-prepare-your-environment-no-header.md]
To create a product, run the az apim product create command:
az apim product create --resource-group apim-hello-word-resource-group \ --product-name "Contoso product" --product-id contoso-product \ --service-name apim-hello-world --subscription-required true \ --state published --description "This is a test."
You can specify various values for your product:
Parameter | Description |
---|---|
--product-name | The name as you want it to be shown in the developer portal. |
--description | Provide information about the product such as its purpose, the APIs it provides access to, and other details. |
--state | Select published if you want to publish the product to the developer portal. Before the APIs in a product can be discovered by developers, the product must be published. By default, new products are unpublished. |
--subscription-required | Select if a user is required to subscribe to use the product (the product is protected) or a subscription isn't required (the product is open). See Access to product APIs later in this article. |
--approval-required | Select if you want an administrator to review and accept or reject subscription attempts to this product. If not selected, subscription attempts are auto-approved. |
--subscriptions-limit | Optionally, limit the count of multiple simultaneous subscriptions. |
--legal-terms | You can include the terms of use for the product, which subscribers must accept to use the product. |
Caution
Use care when configuring a product that doesn't require a subscription. This configuration may be overly permissive and may make the product's APIs more vulnerable to certain API security threats.
To see your current products, use the az apim product list command:
az apim product list --resource-group apim-hello-word-resource-group \ --service-name apim-hello-world --output table
You can delete a product by using the az apim product delete command:
az apim product delete --product-id contoso-product \ --resource-group apim-hello-word-resource-group \ --service-name apim-hello-world --delete-subscriptions true
Continue configuring the product after saving it. In your API Management instance, select the product from the Products window. Add or update:
Item | Description |
---|---|
Settings | Product metadata and state |
APIs | APIs associated with the product |
Policies | Policies applied to product APIs |
Access control | Product visibility for developers or guests |
Subscriptions | Product subscribers |
Products are associations of one or more APIs. You can include many APIs and offer them to developers through the developer portal. During the product creation, you can add one or more existing APIs. You can also add APIs to the product later, either from the Products Settings page or while creating an API.
- In the left navigation of your API Management instance, select Products.
- Select a product, and then select APIs.
- Select + Add API.
- Select one or more APIs, and then Select.
:::image type="content" source="media/api-management-howto-add-products/add-api.png" alt-text="Add an API to an existing product":::
To see your managed APIs, use the az apim api list command:
az apim api list --resource-group apim-hello-word-resource-group \ --service-name apim-hello-world --output table
To add an API to your product, run the az apim product api add command:
az apim product api add --resource-group apim-hello-word-resource-group \ --api-id petstore-api --product-id contoso-product \ --service-name apim-hello-world
Verify the addition by using the az apim product api list command:
az apim product api list --resource-group apim-hello-word-resource-group \ --product-id contoso-product --service-name apim-hello-world --output table
You can remove an API from a product by using the az apim product api delete command:
az apim product api delete --resource-group apim-hello-word-resource-group \ --api-id petstore-api --product-id contoso-product \ --service-name apim-hello-world
After you publish a product, developers can access the APIs. Depending on how the product is configured, they may need to subscribe to the product for access.
Protected product - Developers must first subscribe to a protected product to get access to the product's APIs. When they subscribe, they get a subscription key that can access any API in that product. If you created the API Management instance, you are an administrator already, so you are subscribed to every product by default. For more information, see Subscriptions in Azure API Management.
When a client makes an API request with a valid product subscription key, API Management processes the request and permits access in the context of the product. Policies and access control rules configured for the product can be applied.
[!TIP] You can create or update a user's subscription to a product with custom subscription keys through a REST API or PowerShell command.
Open product - Developers can access an open product's APIs without a subscription key. However, you can configure other mechanisms to secure client access to the APIs, including OAuth 2.0, client certificates, and restricting caller IP addresses.
[!NOTE] Open products aren't listed in the developer portal for developers to learn about or subscribe to. They're visible only to the Administrators group. You'll need to use another mechanism to inform developers about APIs that can be accessed without a subscription key.
When a client makes an API request without a subscription key:
API Management checks whether the API is associated with an open product. An API can be associated with at most one open product.
If the open product exists, it then processes the request in the context of that open product. Policies and access control rules configured for the open product can be applied.
For more information, see How API Management handles requests with or without subscription keys.
In this tutorial, you learned how to:
[!div class="checklist"]
- Create and publish a product
- Add an API to the product
- Access product APIs
Advance to the next tutorial:
[!div class="nextstepaction"] Create blank API and mock API responses
:::zone-end
:::zone pivot="terraform"
In this article, you use Terraform to create an Azure API Management instance, an API, a product, a group, and associations between the product and the API, and the product and the group.
[!INCLUDE About Terraform]
[!div class="checklist"]
- Specify the required version of Terraform and the required providers.
- Define variables for the resource group name prefix, resource group location, and the content format and value for the API definition import.
- Create a resource group with a randomized name.
- Create an API Management service with a randomized name.
- Create an API with a randomized name.
- Create a product with a randomized name in the API Management service.
- Create a group with a randomized name.
- Associate the API with the product.
- Associate the group with the product.
- Output the randomized values such as the names of the resource group, API Management service, API, product, and group.
Create an Azure account with an active subscription. You can create an account for free.
Note
The sample code for this article is located in the Azure Terraform GitHub repo. You can view the log file containing the test results from current and previous versions of Terraform.
See more articles and sample code showing how to use Terraform to manage Azure resources.
Create a directory in which to test and run the sample Terraform code and make it the current directory.
Create a file named
main.tf
, and insert the following code: :::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-api-management-create-with-api/main.tf":::Create a file named
outputs.tf
, and insert the following code: :::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-api-management-create-with-api/outputs.tf":::Create a file named
providers.tf
, and insert the following code: :::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-api-management-create-with-api/providers.tf":::Create a file named
variables.tf
, and insert the following code: :::code language="Terraform" source="~/terraform_samples/quickstart/101-azure-api-management-create-with-api/variables.tf":::
[!INCLUDE terraform-init.md]
[!INCLUDE terraform-plan.md]
[!INCLUDE terraform-apply-plan.md]
Run az apim show
to view the Azure API Management:
az apim show --<apim_service_name> --<resource_group_name>
[!INCLUDE terraform-plan-destroy.md]
Troubleshoot common problems when using Terraform on Azure.
[!div class="nextstepaction"] Create blank API and mock API responses.
:::zone-end