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
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
16
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:
18
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).
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.
23
20
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.
@@ -31,7 +34,7 @@ After adding an API from API Management, you can add metadata and documentation
31
34
32
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).
33
36
34
-
* 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 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).
35
38
36
39
* One or more APIs managed in your API Management instance that you want to add to your API center.
37
40
@@ -44,12 +47,95 @@ After adding an API from API Management, you can add metadata and documentation
44
47
> [!NOTE]
45
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.
46
49
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 \
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 \
### 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).
## 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
49
135
50
136
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.
51
137
52
-
### Add a system-assigned identity
138
+
####Add a system-assigned identity
53
139
54
140
#### [Portal](#tab/portal)
55
141
@@ -67,7 +153,7 @@ az apic service update --name <api-center-name> --resource-group <resource-group
67
153
```
68
154
---
69
155
70
-
### Add a user-assigned identity
156
+
####Add a user-assigned identity
71
157
72
158
To add a user-assigned identity, you need to create a user-assigned identity resource, and then add it to your API center.
73
159
@@ -115,7 +201,7 @@ To add a user-assigned identity, you need to create a user-assigned identity res
115
201
```
116
202
---
117
203
118
-
## Assign the managed identity the API Management Service Reader role
204
+
### Assign the managed identity the API Management Service Reader role
119
205
120
206
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.
121
207
@@ -195,7 +281,7 @@ To allow import of APIs, assign your API center's managed identity the **API Man
195
281
--scope $scope
196
282
---
197
283
198
-
## Import APIs from your API Management instance
284
+
### Import APIs directly from your API Management instance
199
285
200
286
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.
201
287
@@ -204,7 +290,7 @@ Use the [az apic service import-from-apim](/cli/azure/apic/service#az-apic-servi
204
290
>
205
291
> * 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.
206
292
207
-
### Import all APIs from an API Management instance
293
+
#### Import all APIs from an API Management instance
208
294
209
295
Use a wildcard (`*`) to specify all APIs from the API Management instance.
210
296
@@ -223,23 +309,13 @@ Use a wildcard (`*`) to specify all APIs from the API Management instance.
223
309
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.
224
310
225
311
```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/*
237
313
```
238
314
239
315
> [!NOTE]
240
316
> If your API Management instance has a large number of APIs, import to your API center might take some time.
241
317
242
-
### Import a specific API from an API Management instance
318
+
#### Import a specific API from an API Management instance
243
319
244
320
Specify an API to import using its name from the API Management instance.
245
321
@@ -258,19 +334,9 @@ Specify an API to import using its name from the API Management instance.
258
334
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.
259
335
260
336
```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>
265
338
```
266
339
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
-
274
340
> [!NOTE]
275
341
> Specify `<api-name>` using the API resource name in the API Management instance, not the display name. Example: `petstore-api` instead of `Petstore API`.
276
342
@@ -279,6 +345,7 @@ After importing APIs from API Management, you can view and manage the imported A
279
345
## Related content
280
346
281
347
* [Azure CLI reference for API Center](/cli/azure/apic)
348
+
* [Azure CLI reference for API Management](/cli/azure/apim)
282
349
* [Manage API inventory with Azure CLI commands](manage-apis-azure-cli.md)
283
350
* [Assign Azure roles to a managed identity](../role-based-access-control/role-assignments-portal-managed-identity.md)
284
351
* [Azure API Management documentation](../api-management/index.yml)
Copy file name to clipboardExpand all lines: articles/api-center/register-apis.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -120,7 +120,7 @@ To add an API definition to your version:
120
120
|**Description**| Optionally enter a description. | Description of the API definition. |
121
121
|**Specification name**| For the Demo Conference API, select **OpenAPI**. | Specification format for the API.|
122
122
|**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. |
124
124
125
125
:::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" :::
0 commit comments