Skip to content

Commit 482e737

Browse files
authored
Merge pull request #264880 from dlepow/patch-245
[APIC] Update import-api-management-apis.md
2 parents 856ba3d + 8211aab commit 482e737

File tree

2 files changed

+105
-38
lines changed

2 files changed

+105
-38
lines changed

articles/api-center/import-api-management-apis.md

Lines changed: 104 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ description: Add APIs to your Azure API center inventory from your API Managemen
44
author: dlepow
55
ms.service: api-center
66
ms.topic: how-to
7-
ms.date: 01/25/2024
7+
ms.date: 03/08/2024
88
ms.author: danlep
99
ms.custom: devx-track-azurecli
1010
# 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.
@@ -14,14 +14,17 @@ ms.custom: devx-track-azurecli
1414

1515
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.
1616

17-
When you add an API from an API Management instance to your API center:
17+
This article shows two options for using the Azure CLI to add APIs to your API center from API Management:
1818

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).
19+
* **Option 1** - Export an API definition from an API Management instance using the [az apim api export](/cli/azure/apim/api#az-apim-api-export) command. Then, import the definition to your API center.
2320

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.
21+
Possible ways to import an API definition exported from API Management include:
22+
* Run [az apic api register](/cli/azure/apic/api#az-apic-api-register) to register a new API in your API center.
23+
* Run [az apic api definition import-specification](/cli/azure/apic/api/definition#az-apic-api-definition-import-specification) to import the API definition to an existing API.
24+
25+
* **Option 2** - Import APIs directly from API Management to your API center using the [az apic service import-from-apim](/cli/azure/apic/service#az-apic-service-import-from-apim) command.
26+
27+
After importing API definitions or APIs from API Management, you can add metadata and documentation in your API center to help stakeholders discover, understand, and consume the API.
2528

2629
> [!VIDEO https://www.youtube.com/embed/SuGkhuBUV5k]
2730
@@ -31,7 +34,7 @@ After adding an API from API Management, you can add metadata and documentation
3134

3235
* An API center in your Azure subscription. If you haven't created one, see [Quickstart: Create your API center](set-up-api-center.md).
3336

34-
* 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).
37+
* One or more instances of Azure API Management, in the same or a different subscription. When you import APIs directly from API Management, the API Management instance and API center must be in the same directory. If you haven't created one, see [Create an Azure API Management instance](../api-management/get-started-create-service-instance.md).
3538

3639
* One or more APIs managed in your API Management instance that you want to add to your API center.
3740

@@ -44,12 +47,95 @@ After adding an API from API Management, you can add metadata and documentation
4447
> [!NOTE]
4548
> 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.
4649
50+
## Option 1: Export an API definition from API Management and import it to your API center
51+
52+
First, export an API from your API Management instance to an API definition using the [az apim api export](/cli/azure/apim/api#az-apim-api-export) command. Depending on your scenario, you can export the API definition to a local file or a URL.
53+
54+
### Export API to a local API definition file
55+
56+
The following example command exports the API with identifier *my-api* in the *myAPIManagement* instance of API. The API is exported in OpenApiJson format to a local OpenAPI definition file named *specificationFile.json*.
57+
58+
```azurecli
59+
#! /bin/bash
60+
az apim api export --api-id my-api --resource-group myResourceGroup \
61+
--service-name myAPIManagement --export-format OpenApiJsonFile \
62+
--file-path /path/to/folder
63+
```
64+
65+
```azurecli
66+
#! PowerShell syntax
67+
az apim api export --api-id my-api --resource-group myResourceGroup `
68+
--service-name myAPIManagement --export-format OpenApiJsonFile `
69+
--file-path /path/to/folder
70+
```
71+
### Export API to a URL
72+
73+
In the following example, [az apim api export](/cli/azure/apim/api#az-apim-api-export) exports the API with identifier *my-api* in OpenApiJson format to a URL in Azure storage. The URL is available for approximately 5 minutes. Here, the value of the URL is stored in the *$link* variable.
74+
75+
76+
```azurecli
77+
#! /bin/bash
78+
link=$(az apim api export --api-id my-api --resource-group myResourceGroup \
79+
--service-name myAPIManagement --export-format OpenApiJsonUrl --query properties.value.link \
80+
--output tsv)
81+
```
82+
83+
```azurecli
84+
# PowerShell syntax
85+
$link=$(az apim api export --api-id my-api --resource-group myResourceGroup `
86+
--service-name myAPIManagement --export-format OpenApiJsonUrl --query properties.value.link `
87+
--output tsv)
88+
```
89+
### Register API in your API center from exported API definition
90+
91+
You can register a new API in your API center from the exported definition by using the [az apic api register](/cli/azure/apic/api#az-apic-api-register) command.
92+
93+
The following example registers an API in the *myAPICenter* API center from a local OpenAPI definition file named *definitionFile.json*.
94+
95+
```azurecli
96+
az apic api register --resource-group myResourceGroup --service myAPICenter --api-location "/path/to/definitionFile.json
97+
```
98+
99+
### Import API definition to an existing API in your API center
100+
101+
The following example uses the [az apic api definition import-specification](/cli/azure/apic/api/definition#az-apic-api-definition-import-specification) command to import an API definition to an existing API in the *myAPICenter* API center. Here, the API definition is imported from a URL stored in the *$link* variable.
102+
103+
This example assumes you have an API named *my-api* and an associated API version *v1-0-0* and definition entity *openapi* in your API center. If you don't, see [Add APIs to your API center](manage-apis-azure-cli.md#register-api-api-version-and-definition).
47104

48-
## Add a managed identity in your API center
105+
```azurecli
106+
#! /bin/bash
107+
az apic api definition import-specification \
108+
--resource-group myResourceGroup --service myAPICenter \
109+
--api-name my-api --version-name v1-0-0 \
110+
--definition-name openapi --format "link" --value '$link' \
111+
--specification '{"name":"openapi","version":"3.0.2"}'
112+
```
113+
114+
```azurecli
115+
# PowerShell syntax
116+
az apic api definition import-specification `
117+
--resource-group myResourceGroup --service myAPICenter `
118+
--api-name my-api --version-name v1-0-0 `
119+
--definition-name openapi --format "link" --value '$link' `
120+
--specification '{"name":"openapi","version":"3.0.2"}'
121+
```
122+
123+
## Option 2: Import APIs directly from your API Management instance
124+
125+
The following are steps to import APIs from your API Management instance to your API center using the [az apic service import-from-apim](/cli/azure/apic/service#az-apic-service-import-from-apim) command. This command is useful when you want to import multiple APIs from API Management to your API center, but you can also use it to import a single API.
126+
127+
When you add APIs from an API Management instance to your API center using `az apic service import-from-apim`, the following happens automatically:
128+
129+
* Each 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.
130+
* The API receives a system-generated API name in your API center. It retains its display name (title) from API Management.
131+
* The **Lifecycle stage** of the API is set to *Design*.
132+
* Azure API Management is added as an [environment](key-concepts.md#environment).
133+
134+
### Add a managed identity in your API center
49135

50136
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.
51137

52-
### Add a system-assigned identity
138+
#### Add a system-assigned identity
53139

54140
#### [Portal](#tab/portal)
55141

@@ -67,7 +153,7 @@ az apic service update --name <api-center-name> --resource-group <resource-group
67153
```
68154
---
69155

70-
### Add a user-assigned identity
156+
#### Add a user-assigned identity
71157

72158
To add a user-assigned identity, you need to create a user-assigned identity resource, and then add it to your API center.
73159

@@ -115,7 +201,7 @@ To add a user-assigned identity, you need to create a user-assigned identity res
115201
```
116202
---
117203
118-
## Assign the managed identity the API Management Service Reader role
204+
### Assign the managed identity the API Management Service Reader role
119205
120206
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.
121207
@@ -195,7 +281,7 @@ To allow import of APIs, assign your API center's managed identity the **API Man
195281
--scope $scope
196282
---
197283
198-
## Import APIs from your API Management instance
284+
### Import APIs directly from your API Management instance
199285
200286
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.
201287
@@ -204,7 +290,7 @@ Use the [az apic service import-from-apim](/cli/azure/apic/service#az-apic-servi
204290
>
205291
> * 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.
206292
207-
### Import all APIs from an API Management instance
293+
#### Import all APIs from an API Management instance
208294
209295
Use a wildcard (`*`) to specify all APIs from the API Management instance.
210296
@@ -223,23 +309,13 @@ Use a wildcard (`*`) to specify all APIs from the API Management instance.
223309
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.
224310
225311
```azurecli
226-
#! /bin/bash
227-
apiIDs="$apimID/apis/*"
228-
229-
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs
230-
```
231-
232-
```azurecli
233-
# PowerShell syntax
234-
$apiIDs=$apimID + "/apis/*"
235-
236-
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs
312+
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apimID/apis/*
237313
```
238314
239315
> [!NOTE]
240316
> If your API Management instance has a large number of APIs, import to your API center might take some time.
241317
242-
### Import a specific API from an API Management instance
318+
#### Import a specific API from an API Management instance
243319
244320
Specify an API to import using its name from the API Management instance.
245321
@@ -258,19 +334,9 @@ Specify an API to import using its name from the API Management instance.
258334
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.
259335
260336
```azurecli
261-
#! /bin/bash
262-
apiIDs="$apimID/apis/<api-name>"
263-
264-
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs
337+
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apimID/apis/<api-name>
265338
```
266339
267-
```azurecli
268-
# PowerShell syntax
269-
$apiIDs=$apimID + "/apis/<api-name>"
270-
271-
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs
272-
```
273-
274340
> [!NOTE]
275341
> Specify `<api-name>` using the API resource name in the API Management instance, not the display name. Example: `petstore-api` instead of `Petstore API`.
276342
@@ -279,6 +345,7 @@ After importing APIs from API Management, you can view and manage the imported A
279345
## Related content
280346
281347
* [Azure CLI reference for API Center](/cli/azure/apic)
348+
* [Azure CLI reference for API Management](/cli/azure/apim)
282349
* [Manage API inventory with Azure CLI commands](manage-apis-azure-cli.md)
283350
* [Assign Azure roles to a managed identity](../role-based-access-control/role-assignments-portal-managed-identity.md)
284351
* [Azure API Management documentation](../api-management/index.yml)

articles/api-center/register-apis.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ To add an API definition to your version:
120120
| **Description** | Optionally enter a description. | Description of the API definition. |
121121
| **Specification name** | For the Demo Conference API, select **OpenAPI**. | Specification format for the API.|
122122
| **Specification version** | Enter a version identifier of your choice, such as *2.0*. | Specification version. |
123-
|**Document** | Browse to a definition file for the Demo Conference API. | API definition file. |
123+
|**Document** | Browse to a definition file for the Demo Conference API, or enter a URL. | API definition file. |
124124

125125
:::image type="content" source="media/register-apis/add-definition.png" alt-text="Screenshot of adding an API definition in the portal." lightbox="media/register-apis/add-definition.png" :::
126126

0 commit comments

Comments
 (0)