You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/api-center/import-api-management-apis.md
+78-59Lines changed: 78 additions & 59 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,7 +4,7 @@ description: Add APIs to your Azure API center inventory from your API Managemen
4
4
author: dlepow
5
5
ms.service: api-center
6
6
ms.topic: how-to
7
-
ms.date: 03/07/2024
7
+
ms.date: 03/08/2024
8
8
ms.author: danlep
9
9
ms.custom: devx-track-azurecli
10
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.
@@ -16,18 +16,15 @@ This article shows how to import (add) APIs from an Azure API Management instanc
16
16
17
17
This article shows two options for using the Azure CLI to add APIs to your API center from API Management:
18
18
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.
20
20
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.
22
24
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.
@@ -37,7 +34,7 @@ After adding an API from API Management, you can add metadata and documentation
37
34
38
35
* An API center in your Azure subscription. If you haven't created one, see [Quickstart: Create your API center](set-up-api-center.md).
39
36
40
-
* One or more instances of Azure API Management, in the same or a different subscriptionin 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).
41
38
42
39
* One or more APIs managed in your API Management instance that you want to add to your API center.
43
40
@@ -50,67 +47,89 @@ After adding an API from API Management, you can add metadata and documentation
50
47
> [!NOTE]
51
48
> 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.
52
49
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
56
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.
57
53
58
54
### Export API to a local API definition file
59
55
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*.
61
57
62
-
```azurecli-interactive
58
+
```azurecli
63
59
#! /bin/bash
64
60
az apim api export --api-id my-api --resource-group myResourceGroup \
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.
72
74
73
-
```azurecli-interactive
75
+
```azurecli
76
+
#! /bin/bash
74
77
link=$(az apim api export --api-id my-api --resource-group myResourceGroup \
### Register API in your API center from exported API definition
92
89
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.
96
91
97
92
The following example registers an API in the *myAPICenter* API center from a local OpenAPI definition file named *definitionFile.json*.
98
93
99
-
```azurecli-interactive
100
-
az apic api register --resource-group myResourceGroup \
az apic api register --resource-group myResourceGroup --service myAPICenter --api-location "/path/to/definitionFile.json
102
96
```
103
97
104
-
### Import API definition from a URL to your API center
98
+
### Import API definition to an existing API in your API center
105
99
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.
107
101
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).
## Option 2: Bulk-import APIs from your API Management instance
113
123
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
+
114
133
### Add a managed identity in your API center
115
134
116
135
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
128
147
129
148
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:
130
149
131
-
```azurecli-interactive
150
+
```azurecli
132
151
az apic service update --name <api-center-name> --resource-group <resource-group-name> --identity '{"type": "SystemAssigned"}'
133
152
```
134
153
---
@@ -149,7 +168,7 @@ To add a user-assigned identity, you need to create a user-assigned identity res
149
168
150
169
1. Create a user-assigned identity.
151
170
152
-
```azurecli-interactive
171
+
```azurecli
153
172
az identity create --resource-group <resource-group-name> --name <identity-name>
154
173
```
155
174
@@ -176,7 +195,7 @@ To add a user-assigned identity, you need to create a user-assigned identity res
176
195
177
196
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`.
178
197
179
-
```azurecli-interactive
198
+
```azurecli
180
199
az apic service update --name <api-center-name> --resource-group <resource-group-name> --identity "@identity.json"
181
200
```
182
201
---
@@ -201,45 +220,45 @@ To allow import of APIs, assign your API center's managed identity the **API Man
201
220
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).
202
221
203
222
**System-assigned identity**
204
-
```azurecli-interactive
223
+
```azurecli
205
224
#! /bin/bash
206
225
apicObjID=$(az apic service show --name <api-center-name> \
207
226
--resource-group <resource-group-name> \
208
227
--query "identity.principalId" --output tsv)
209
228
```
210
229
211
-
```azurecli-interactive
230
+
```azurecli
212
231
# PowerShell syntax
213
232
$apicObjID=$(az apic service show --name <api-center-name> `
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.
241
260
242
-
```azurecli-interactive
261
+
```azurecli
243
262
#! /bin/bash
244
263
scope="${apimID:1}"
245
264
@@ -250,7 +269,7 @@ To allow import of APIs, assign your API center's managed identity the **API Man
250
269
--scope $scope
251
270
```
252
271
253
-
```azurecli-interactive
272
+
```azurecli
254
273
#! PowerShell syntax
255
274
$scope=$apimID.substring(1)
256
275
@@ -276,19 +295,19 @@ Use a wildcard (`*`) to specify all APIs from the API Management instance.
276
295
277
296
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
278
297
279
-
```azurecli-interactive
298
+
```azurecli
280
299
#! /bin/bash
281
300
apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv)
282
301
```
283
302
284
-
```azurecli-interactive
303
+
```azurecli
285
304
# PowerShell syntax
286
305
$apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv)
287
306
```
288
307
289
308
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.
290
309
291
-
```azurecli-interactive
310
+
```azurecli
292
311
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apimID/apis/*
293
312
```
294
313
@@ -301,19 +320,19 @@ Specify an API to import using its name from the API Management instance.
301
320
302
321
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
303
322
304
-
```azurecli-interactive
323
+
```azurecli
305
324
#! /bin/bash
306
325
apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv)
307
326
```
308
327
309
-
```azurecli-interactive
328
+
```azurecli
310
329
# PowerShell syntax
311
330
$apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query id --output tsv)
312
331
```
313
332
314
333
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.
315
334
316
-
```azurecli-interactive
335
+
```azurecli
317
336
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apimID/apis/<api-name>
0 commit comments