Skip to content

Commit dfda9ea

Browse files
committed
[APIC] Add API import scenario
1 parent a327f86 commit dfda9ea

File tree

1 file changed

+78
-59
lines changed

1 file changed

+78
-59
lines changed

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

Lines changed: 78 additions & 59 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: 03/07/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.
@@ -16,18 +16,15 @@ This article shows how to import (add) APIs from an Azure API Management instanc
1616

1717
This article shows two options for using the Azure CLI to add APIs to your API center from API Management:
1818

19-
* Export an API from API Management to an API definition using the [az apim api export](/cli/azure/apim/api#az-apim-api-export) command. Then, run [az apic api register](/cli/azure/apic/api#az-apic-api-register) to register the API in your API center, using the API definition.
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.
2020

21-
* Bulk-import APIs 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.
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.
2224

23-
When you add an API from an API Management instance to your API center using the bulk-import option, the following happens automatically:
24-
25-
* 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.
26-
* The API receives a system-generated API name in your API center. It retains its display name (title) from API Management.
27-
* The **Lifecycle stage** of the API is set to *Design*.
28-
* Azure API Management is added as an [environment](key-concepts.md#environment).
29-
30-
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+
* **Option 2** - Bulk-import APIs 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.
3128

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

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

40-
* 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 use the bulk-import option, 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).
4138

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

@@ -50,67 +47,89 @@ After adding an API from API Management, you can add metadata and documentation
5047
> [!NOTE]
5148
> 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.
5249
53-
## Option 1: Export an API from API Management and register it in your API center
54-
55-
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. For example:
50+
## Option 1: Export an API definition from API Management and import it to your API center
5651

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.
5753

5854
### Export API to a local API definition file
5955

60-
The following example 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*.
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*.
6157

62-
```azurecli-interactive
58+
```azurecli
6359
#! /bin/bash
6460
az apim api export --api-id my-api --resource-group myResourceGroup \
6561
--service-name myAPIManagement --export-format OpenApiJsonFile \
6662
--file-path /path/to/folder
6763
```
6864

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+
```
6971
### Export API to a URL
7072

71-
The following example exports the API with identifier *my-api* in the *myAPIManagement* instance of API. The API is exported in OpenApiJson format to a URL in Azure storage. The URL is available for approximately 5 minutes.
73+
The following example exports the API with identifier *my-api* in the *myAPIManagement* instance of API. The API is exported in OpenApiJson format to a URL in Azure storage. The URL is available for approximately 5 minutes. The value of the URL is stored in the *$link* variable.
7274

73-
```azurecli-interactive
75+
```azurecli
76+
#! /bin/bash
7477
link=$(az apim api export --api-id my-api --resource-group myResourceGroup \
75-
--service-name myAPIManagement --export-format OpenApiJsonUrl --query properties.value.link --output tsv)
78+
--service-name myAPIManagement --export-format OpenApiJsonUrl --query properties.value.link \
79+
--output tsv)
7680
```
7781

78-
The URL appears in the command output. You can use the link to download the API definition file.
79-
80-
```output
81-
[...]
82-
"name": "my-api",
83-
"properties": {
84-
"format": "openapi+json-link",
85-
"value": {
86-
"link": "https://xxxxxxxxxxxxxxxxx.blob.core.windows.net/api-export/My API......."
87-
[...]
88-
}
89-
}
90-
82+
```azurecli
83+
# PowerShell syntax
84+
$link=$(az apim api export --api-id my-api --resource-group myResourceGroup `
85+
--service-name myAPIManagement --export-format OpenApiJsonUrl --query properties.value.link `
86+
--output tsv)
9187
```
88+
### Register API in your API center from exported API definition
9289

93-
### Import local API definition to your API center
94-
95-
Then, use the [az apic api register](/cli/azure/apic/api#az-apic-api-register) command to register the API in your API center, using the API definition.
90+
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.
9691

9792
The following example registers an API in the *myAPICenter* API center from a local OpenAPI definition file named *definitionFile.json*.
9893

99-
```azurecli-interactive
100-
az apic api register --resource-group myResourceGroup \
101-
--service myAPICenter --api-location "/Path/to/definitionFile.json
94+
```azurecli
95+
az apic api register --resource-group myResourceGroup --service myAPICenter --api-location "/path/to/definitionFile.json
10296
```
10397

104-
### Import API definition from a URL to your API center
98+
### Import API definition to an existing API in your API center
10599

106-
The following example registers an API in the *myAPICenter* API center from an OpenAPI definition file at a URL whose value is stored in the *$link* variable.
100+
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.
107101

108-
```azurecli-interactive
102+
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).
103+
104+
```azurecli
105+
#! /bin/bash
106+
az apic api definition import-specification \
107+
--resource-group myResourceGroup --service myAPICenter \
108+
--api-name my-api --version-name v1-0-0 \
109+
--definition-name openapi --format "link" --value '$link' \
110+
--specification '{"name":"openapi","version":"3.0.2"}'
111+
```
109112

113+
```azurecli
114+
# PowerShell syntax
115+
az apic api definition import-specification `
116+
--resource-group myResourceGroup --service myAPICenter `
117+
--api-name my-api --version-name v1-0-0 `
118+
--definition-name openapi --format "link" --value '$link' `
119+
--specification '{"name":"openapi","version":"3.0.2"}'
110120
```
111121

112122
## Option 2: Bulk-import APIs from your API Management instance
113123

124+
The following are steps to bulk-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.
125+
126+
When you add APIs from an API Management instance to your API center using the bulk-import option, the following happens automatically:
127+
128+
* 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.
129+
* The API receives a system-generated API name in your API center. It retains its display name (title) from API Management.
130+
* The **Lifecycle stage** of the API is set to *Design*.
131+
* Azure API Management is added as an [environment](key-concepts.md#environment).
132+
114133
### Add a managed identity in your API center
115134

116135
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.
@@ -128,7 +147,7 @@ For this scenario, your API center uses a [managed identity](/entra/identity/man
128147

129148
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:
130149

131-
```azurecli-interactive
150+
```azurecli
132151
az apic service update --name <api-center-name> --resource-group <resource-group-name> --identity '{"type": "SystemAssigned"}'
133152
```
134153
---
@@ -149,7 +168,7 @@ To add a user-assigned identity, you need to create a user-assigned identity res
149168

150169
1. Create a user-assigned identity.
151170

152-
```azurecli-interactive
171+
```azurecli
153172
az identity create --resource-group <resource-group-name> --name <identity-name>
154173
```
155174
@@ -176,7 +195,7 @@ To add a user-assigned identity, you need to create a user-assigned identity res
176195
177196
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`.
178197
179-
```azurecli-interactive
198+
```azurecli
180199
az apic service update --name <api-center-name> --resource-group <resource-group-name> --identity "@identity.json"
181200
```
182201
---
@@ -201,45 +220,45 @@ To allow import of APIs, assign your API center's managed identity the **API Man
201220
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).
202221
203222
**System-assigned identity**
204-
```azurecli-interactive
223+
```azurecli
205224
#! /bin/bash
206225
apicObjID=$(az apic service show --name <api-center-name> \
207226
--resource-group <resource-group-name> \
208227
--query "identity.principalId" --output tsv)
209228
```
210229
211-
```azurecli-interactive
230+
```azurecli
212231
# PowerShell syntax
213232
$apicObjID=$(az apic service show --name <api-center-name> `
214233
--resource-group <resource-group-name> `
215234
--query "identity.principalId" --output tsv)
216235
```
217236
218237
**User-assigned identity**
219-
```azurecli-interactive
238+
```azurecli
220239
#! /bin/bash
221240
apicObjID=$(az identity show --name <identity-name> --resource-group <resource-group-name> --query "principalId" --output tsv)
222241
```
223242
224-
```azurecli-interactive
243+
```azurecli
225244
# PowerShell syntax
226245
$apicObjID=$(az identity show --name <identity-name> --resource-group <resource-group-name> --query "principalId" --output tsv)
227246
```
228247
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
229248
230-
```azurecli-interactive
249+
```azurecli
231250
#! /bin/bash
232251
apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query "id" --output tsv)
233252
```
234253
235-
```azurecli-interactive
254+
```azurecli
236255
# PowerShell syntax
237256
$apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query "id" --output tsv)
238257
```
239258
240259
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.
241260
242-
```azurecli-interactive
261+
```azurecli
243262
#! /bin/bash
244263
scope="${apimID:1}"
245264
@@ -250,7 +269,7 @@ To allow import of APIs, assign your API center's managed identity the **API Man
250269
--scope $scope
251270
```
252271
253-
```azurecli-interactive
272+
```azurecli
254273
#! PowerShell syntax
255274
$scope=$apimID.substring(1)
256275
@@ -276,19 +295,19 @@ Use a wildcard (`*`) to specify all APIs from the API Management instance.
276295
277296
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
278297
279-
```azurecli-interactive
298+
```azurecli
280299
#! /bin/bash
281300
apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv)
282301
```
283302
284-
```azurecli-interactive
303+
```azurecli
285304
# PowerShell syntax
286305
$apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv)
287306
```
288307
289308
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.
290309
291-
```azurecli-interactive
310+
```azurecli
292311
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apimID/apis/*
293312
```
294313
@@ -301,19 +320,19 @@ Specify an API to import using its name from the API Management instance.
301320
302321
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
303322
304-
```azurecli-interactive
323+
```azurecli
305324
#! /bin/bash
306325
apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv)
307326
```
308327
309-
```azurecli-interactive
328+
```azurecli
310329
# PowerShell syntax
311330
$apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv)
312331
```
313332
314333
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.
315334
316-
```azurecli-interactive
335+
```azurecli
317336
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apimID/apis/<api-name>
318337
```
319338

0 commit comments

Comments
 (0)