|
| 1 | +--- |
| 2 | +title: Import APIs from Azure API Management - Azure API Center |
| 3 | +description: Add APIs to your Azure API center inventory from your API Management instance. |
| 4 | +author: dlepow |
| 5 | +ms.service: api-center |
| 6 | +ms.topic: how-to |
| 7 | +ms.date: 01/25/2024 |
| 8 | +ms.author: danlep |
| 9 | +ms.custom: |
| 10 | +# Customer intent: As an API program manager, I want to add APIs that are managed in my Azure API Management instance to my API center. |
| 11 | +--- |
| 12 | + |
| 13 | +# Import APIs to your API center from Azure API Management |
| 14 | + |
| 15 | +This article shows how to import (add) APIs from an Azure API Management instance to your [API center](overview.md) using the Azure CLI. Adding APIs from API Management to your API inventory helps make them discoverable and accessible to developers, API program managers, and other stakeholders in your organization. |
| 16 | + |
| 17 | +When you add an API from an API Management instance to your API center: |
| 18 | + |
| 19 | +* The API's [versions](key-concepts.md#api-version), [definitions](key-concepts.md#api-definition), and [deployment](key-concepts.md#deployment) information are copied to your API center. |
| 20 | +* The API receives a system-generated API name in your API center. It retains its display name (title) from API Management. |
| 21 | +* The **Lifecycle stage** of the API is set to *Design*. |
| 22 | +* Azure API Management is added as an [environment](key-concepts.md#environment). |
| 23 | + |
| 24 | +After adding an API from API Management, you can add metadata and documentation in your API center to help stakeholders discover, understand, and consume the API. |
| 25 | + |
| 26 | +[!INCLUDE [api-center-preview-feedback](includes/api-center-preview-feedback.md)] |
| 27 | + |
| 28 | +## Prerequisites |
| 29 | + |
| 30 | +* An API center in your Azure subscription. If you haven't created one, see [Quickstart: Create your API center](set-up-api-center.md). |
| 31 | + |
| 32 | +* One or more instances of Azure API Management, in the same or a different subscription in your directory. If you haven't created one, see [Create an Azure API Management instance](../api-management/get-started-create-service-instance.md). |
| 33 | + |
| 34 | +* One or more APIs managed in your API Management instance that you want to add to your API center. |
| 35 | + |
| 36 | +* For Azure CLI: |
| 37 | + [!INCLUDE [include](~/articles/reusable-content/azure-cli/azure-cli-prepare-your-environment-no-header.md)] |
| 38 | + |
| 39 | + > [!NOTE] |
| 40 | + > `az apic` commands require the `apic-extension` Azure CLI extension. If you haven't used `az apic` commands, the extension is installed dynamically when you run your first `az apic` command. Learn more about [Azure CLI extensions](/cli/azure/azure-cli-extensions-overview). |
| 41 | +
|
| 42 | + > [!NOTE] |
| 43 | + > Azure CLI command examples in this article can run in PowerShell or a bash shell. Where needed because of different variable syntax, separate command examples are provided for the two shells. |
| 44 | +
|
| 45 | + |
| 46 | +## Add a managed identity in your API center |
| 47 | + |
| 48 | +For this scenario, your API center uses a [managed identity](/entra/identity/managed-identities-azure-resources/overview) to access APIs in your API Management instance. You can use either a system-assigned or user-assigned managed identity. If you haven't added a managed identity in your API center, you can add it in the Azure portal or by using the Azure CLI. |
| 49 | + |
| 50 | +### Add a system-assigned identity |
| 51 | + |
| 52 | +#### [Portal](#tab/portal) |
| 53 | + |
| 54 | +1. In the [portal](https://azure.microsoft.com), navigate to your API center. |
| 55 | +1. In the left menu, select **Managed identities**. |
| 56 | +1. Select **System assigned**, and set the status to **On**. |
| 57 | +1. Select **Save**. |
| 58 | + |
| 59 | +#### [Azure CLI](#tab/cli) |
| 60 | + |
| 61 | +Set the system-assigned identity in your API center using the following [az apic service update](/cli/azure/apic/service#az-apic-service-update) command. Substitute the names of your API center and resource group: |
| 62 | + |
| 63 | +```azurecli |
| 64 | +az apic service update --name <api-center-name> --resource-group <resource-group-name> --identity '{"type": "SystemAssigned"}' |
| 65 | +``` |
| 66 | +--- |
| 67 | + |
| 68 | +### Add a user-assigned identity |
| 69 | + |
| 70 | +To add a user-assigned identity, you need to create a user-assigned identity resource, and then add it to your API center. |
| 71 | + |
| 72 | +#### [Portal](#tab/portal) |
| 73 | + |
| 74 | +1. Create a user-assigned identity according to [these instructions](/entra/identity/managed-identities-azure-resources/how-manage-user-assigned-managed-identities#create-a-user-assigned-managed-identity). |
| 75 | +1. In the [portal](https://azure.microsoft.com), navigate to your API center. |
| 76 | +1. In the left menu, select **Managed identities**. |
| 77 | +1. Select **User assigned** > **+ Add**. |
| 78 | +1. Search for the identity you created earlier, select it, and select **Add**. |
| 79 | + |
| 80 | +#### [Azure CLI](#tab/cli) |
| 81 | + |
| 82 | +1. Create a user-assigned identity. |
| 83 | + |
| 84 | + ```azurecli |
| 85 | + az identity create --resource-group <resource-group-name> --name <identity-name> |
| 86 | + ``` |
| 87 | +
|
| 88 | + In the command output, note the value of the identity's `id` property. The `id` property should look something like this: |
| 89 | +
|
| 90 | + ```json |
| 91 | + { |
| 92 | + [...] |
| 93 | + "id": "/subscriptions/<subscription-id>/resourcegroups/<resource-group-name>/providers/Microsoft.ManagedIdentity/userAssignedIdentities/<identity-name>" |
| 94 | + [...] |
| 95 | + } |
| 96 | + ``` |
| 97 | +
|
| 98 | +1. Create a JSON file with the following content, substituting the value of the `id` property from the previous step. |
| 99 | +
|
| 100 | + ```json |
| 101 | + { |
| 102 | + "type": "UserAssigned", |
| 103 | + "userAssignedIdentities": { |
| 104 | + "<identity-id>": {} |
| 105 | + } |
| 106 | + } |
| 107 | + ``` |
| 108 | +
|
| 109 | +1. Add the user-assigned identity to your API center using the following [az apic service update](/cli/azure/apic/service#az-apic-service-update) command. Substitute the names of your API center and resource group, and pass the JSON file as the value of the `--identity` parameter. Here, the JSON file is named `identity.json`. |
| 110 | +
|
| 111 | + ```azurecli |
| 112 | + az apic service update --name <api-center-name> --resource-group <resource-group-name> --identity "@identity.json" |
| 113 | + ``` |
| 114 | +--- |
| 115 | +
|
| 116 | +## Assign the managed identity the API Management Service Reader role |
| 117 | +
|
| 118 | +To allow import of APIs, assign your API center's managed identity the **API Management Service Reader** role in your API Management instance. You can use the [portal](../role-based-access-control/role-assignments-portal-managed-identity.md) or the Azure CLI. |
| 119 | +
|
| 120 | +#### [Portal](#tab/portal) |
| 121 | +
|
| 122 | +1. In the [portal](https://azure.microsoft.com), navigate to your API Management instance. |
| 123 | +1. In the left menu, select **Access control (IAM)**. |
| 124 | +1. Select **+ Add role assignment**. |
| 125 | +1. On the **Add role assignment** page, set the values as follows: |
| 126 | + 1. On the **Role** tab - Select **API Management Service Reader**. |
| 127 | + 1. On the **Members** tab, in **Assign access to** - Select **Managed identity** > **+ Select members**. |
| 128 | + 1. On the **Select managed identities** page - Select the system-assigned or user-assigned managed identity of your API center that you added in the previous section. Click **Select**. |
| 129 | + 1. Select **Review + assign**. |
| 130 | +
|
| 131 | +#### [Azure CLI](#tab/cli) |
| 132 | +
|
| 133 | +1. Get the principal ID of the identity. If you're configuring a system-assigned identity, use the [az apic service show](/cli/azure/apic/service#az-apic-service-show) command. For a user-assigned identity, use [az identity show](/cli/azure/identity#az-identity-show). |
| 134 | +
|
| 135 | + **System-assigned identity** |
| 136 | + ```azurecli |
| 137 | + #! /bin/bash |
| 138 | + apicObjID=$(az apic service show --name <api-center-name> \ |
| 139 | + --resource-group <resource-group-name> \ |
| 140 | + --query "identity.principalId" --output tsv) |
| 141 | + ``` |
| 142 | +
|
| 143 | + ```azurecli |
| 144 | + # PowerShell syntax |
| 145 | + $apicObjID=$(az apic service show --name <api-center-name> ` |
| 146 | + --resource-group <resource-group-name> ` |
| 147 | + --query "identity.principalId" --output tsv) |
| 148 | + ``` |
| 149 | +
|
| 150 | + **User-assigned identity** |
| 151 | + ```azurecli |
| 152 | + #! /bin/bash |
| 153 | + apicObjID=$(az identity show --name <identity-name> --resource-group <resource-group-name> --query "principalId" --output tsv) |
| 154 | + ``` |
| 155 | + |
| 156 | + ```azurecli |
| 157 | + # PowerShell syntax |
| 158 | + $apicObjID=$(az identity show --name <identity-name> --resource-group <resource-group-name> --query "principalId" --output tsv) |
| 159 | + ``` |
| 160 | +1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command. |
| 161 | + |
| 162 | + ```azurecli |
| 163 | + #! /bin/bash |
| 164 | + apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query "id" --output tsv) |
| 165 | + ``` |
| 166 | +
|
| 167 | + ```azurecli |
| 168 | + # PowerShell syntax |
| 169 | + $apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query "id" --output tsv) |
| 170 | + ``` |
| 171 | +
|
| 172 | +1. Assign the managed identity the **API Management Service Reader** role in your API Management instance using the [az role assignment create](/cli/azure/role/assignment#az-role-assignment-create) command. |
| 173 | +
|
| 174 | + ```azurecli |
| 175 | + #! /bin/bash |
| 176 | + scope="${apimID:1}" |
| 177 | +
|
| 178 | + az role assignment create \ |
| 179 | + --role "API Management Service Reader Role" \ |
| 180 | + --assignee-object-id $apicObjID \ |
| 181 | + --assignee-principal-type ServicePrincipal \ |
| 182 | + --scope $scope |
| 183 | + ``` |
| 184 | + |
| 185 | + ```azurecli |
| 186 | + #! PowerShell syntax |
| 187 | + $scope=$apimID.substring(1) |
| 188 | +
|
| 189 | + az role assignment create ` |
| 190 | + --role "API Management Service Reader Role" ` |
| 191 | + --assignee-object-id $apicObjID ` |
| 192 | + --assignee-principal-type ServicePrincipal ` |
| 193 | + --scope $scope |
| 194 | +--- |
| 195 | +
|
| 196 | +## Import APIs from your API Management instance |
| 197 | +
|
| 198 | +Use the [az apic service import-from-apim](/cli/azure/apic/service#az-apic-service-import-from-apim) command to import one or more APIs from your API Management instance to your API center. |
| 199 | +
|
| 200 | +> [!NOTE] |
| 201 | +> * This command depends on a managed identity configured in your API center that has read permissions to the API Management instance. If you haven't added or configured a managed identity, see [Add a managed identity in your API center](#add-a-managed-identity-in-your-api-center) earlier in this article. |
| 202 | +> |
| 203 | +> * If your API center has multiple managed identities, the command searches first for a system-assigned identity. If none is found, it picks the first user-assigned identity in the list. |
| 204 | +
|
| 205 | +### Import all APIs from an API Management instance |
| 206 | +
|
| 207 | +Use a wildcard (`*`) to specify all APIs from the API Management instance. |
| 208 | +
|
| 209 | +1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command. |
| 210 | +
|
| 211 | + ```azurecli |
| 212 | + #! /bin/bash |
| 213 | + apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv) |
| 214 | + ``` |
| 215 | +
|
| 216 | + ```azurecli |
| 217 | + # PowerShell syntax |
| 218 | + $apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv) |
| 219 | + ``` |
| 220 | + |
| 221 | +1. Use the `az apic service import-from-apim` command to import the APIs. Substitute the names of your API center and resource group, and use `*` to specify all APIs from the API Management instance. |
| 222 | +
|
| 223 | + ```azurecli |
| 224 | +
|
| 225 | + #! /bin/bash |
| 226 | + apiIDs="$apimID/apis/*" |
| 227 | +
|
| 228 | + az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs |
| 229 | + ``` |
| 230 | + |
| 231 | + ```azurecli |
| 232 | + # PowerShell syntax |
| 233 | + $apiIDs=$apimID + "/apis/*" |
| 234 | +
|
| 235 | + az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs |
| 236 | + ``` |
| 237 | +
|
| 238 | + > [!NOTE] |
| 239 | + > If your API Management instance has a large number of APIs, import to your API center might take some time. |
| 240 | + |
| 241 | +### Import a specific API from an API Management instance |
| 242 | +
|
| 243 | +Specify an API to import using its name from the API Management instance. |
| 244 | +
|
| 245 | +1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command. |
| 246 | +
|
| 247 | + ```azurecli |
| 248 | + #! /bin/bash |
| 249 | + apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv) |
| 250 | + ``` |
| 251 | +
|
| 252 | + ```azurecli |
| 253 | + # PowerShell syntax |
| 254 | + $apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv) |
| 255 | + ``` |
| 256 | + |
| 257 | +1. Use the `az apic service import-from-apim` command to import the API. Substitute the names of your API center and resource group, and specify an API name from the API Management instance. |
| 258 | +
|
| 259 | + ```azurecli |
| 260 | + #! /bin/bash |
| 261 | + apiIDs="$apimID/apis/<api-name>" |
| 262 | +
|
| 263 | + az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs |
| 264 | + ``` |
| 265 | + |
| 266 | + ```azurecli |
| 267 | + # PowerShell syntax |
| 268 | + $apiIDs=$apimID + "/apis/<api-name>" |
| 269 | +
|
| 270 | + az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs |
| 271 | + ``` |
| 272 | +
|
| 273 | + > [!NOTE] |
| 274 | + > Specify `<api-name>` using the API resource name in the API Management instance, not the display name. Example: `petstore-api` instead of `Petstore API`. |
| 275 | + |
| 276 | +After importing APIs from API Management, you can view and manage the imported APIs in your API center. |
| 277 | +
|
| 278 | +## Related content |
| 279 | +
|
| 280 | +* [Azure CLI reference for API Center](/cli/azure/apic) |
| 281 | +* [Manage API inventory with Azure CLI commands](manage-apis-azure-cli.md) |
| 282 | +* [Assign Azure roles to a managed identity](../role-based-access-control/role-assignments-portal-managed-identity.md) |
| 283 | +* [Azure API Management documentation](../api-management/index.yml) |
0 commit comments