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
+79-32Lines changed: 79 additions & 32 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -39,13 +39,13 @@ After adding an API from API Management, you can add metadata and documentation
39
39
> [!NOTE]
40
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
41
42
-
> [!TIP]
43
-
> Azure CLI command examples in this article are formatted for the bash shell. If you're using PowerShell or another shell environment, you might need to adjust line breaks and variable names for your environment.
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
44
45
45
46
46
## Add a managed identity in your API center
47
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. If you haven't added a system-assigned or user-assigned managed identity in your API center, you can add it in the Azure portal or by using the Azure CLI.
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
49
50
50
### Add a system-assigned identity
51
51
@@ -61,9 +61,7 @@ For this scenario, your API center uses a [managed identity](/entra/identity/man
61
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
62
63
63
```azurecli
64
-
az apic service update --name <api-center-name> \
65
-
--resource-group <resource-group-name> \
66
-
--identity '{"type": "SystemAssigned"}'
64
+
az apic service update --name <api-center-name> --resource-group <resource-group-name> --identity '{"type": "SystemAssigned"}'
67
65
```
68
66
---
69
67
@@ -111,9 +109,7 @@ To add a user-assigned identity, you need to create a user-assigned identity res
111
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`.
112
110
113
111
```azurecli
114
-
az apic service update --name <api-center-name> \
115
-
--resource-group <resource-group-name> \
116
-
--identity @identity.json
112
+
az apic service update --name <api-center-name> --resource-group <resource-group-name> --identity "@identity.json"
117
113
```
118
114
---
119
115
@@ -138,35 +134,63 @@ To allow import of APIs, assign your API center's managed identity the **API Man
138
134
139
135
**System-assigned identity**
140
136
```azurecli
141
-
# Get the principal ID of the system-assigned identity in your API center
137
+
#! /bin/bash
142
138
apicObjID=$(az apic service show --name <api-center-name> \
143
139
--resource-group <resource-group-name> \
144
-
--query identity.principalId --output tsv)
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)
145
148
```
146
149
147
150
**User-assigned identity**
148
151
```azurecli
149
-
# Get the principal ID of the managed identity (must be added in the API center)
150
-
apicObjID=$(az identity show --name <identity-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.
173
+
163
174
```azurecli
175
+
#! /bin/bash
176
+
scope="${apimID:1}"
177
+
164
178
az role assignment create \
165
-
--role "API Management Service Reader Role"\
179
+
--role "API Management Service Reader Role"\
166
180
--assignee-object-id $apicObjID \
167
181
--assignee-principal-type ServicePrincipal \
168
-
--scope "${apimID:1}"
182
+
--scope $scope
169
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
170
194
---
171
195
172
196
## Import APIs from your API Management instance
@@ -185,17 +209,30 @@ Use a wildcard (`*`) to specify all APIs from the API Management instance.
185
209
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
186
210
187
211
```azurecli
188
-
apimID=$(az apim show --name <apim-name> \
189
-
--resource-group <resource-group-name> \
190
-
--query id --output tsv)
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)
191
219
```
192
220
193
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.
194
222
195
223
```azurecli
196
-
az apic service import-from-apim --service-name <api-center-name> \
197
-
--resource-group <resource-group-name> \
198
-
--source-resource-ids $apimID/apis/*
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
199
236
```
200
237
201
238
> [!NOTE]
@@ -208,17 +245,27 @@ Specify an API to import using its name from the API Management instance.
208
245
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
209
246
210
247
```azurecli
211
-
apimID=$(az apim show --name <apim-name> \
212
-
--resource-group <resource-group-name> \
213
-
--query id --output tsv)
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)
214
255
```
215
256
216
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.
217
258
218
259
```azurecli
219
-
az apic service import-from-apim --service-name <api-center-name> \
220
-
--resource-group <resource-group-name> \
221
-
--source-resource-ids $apimID/apis/<api-name>
260
+
#! /bin/bash
261
+
apiIDs="$apimID/apis/<api-name>"
262
+
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs
263
+
```
264
+
265
+
```azurecli
266
+
# PowerShell syntax
267
+
$apiIDs=$apimID + "/apis/<api-name>"
268
+
az apic service import-from-apim --service-name <api-center-name> --resource-group <resource-group-name> --source-resource-ids $apiIDs
0 commit comments