Skip to content

Commit 77fd2e9

Browse files
committed
powershell
1 parent 744e373 commit 77fd2e9

File tree

1 file changed

+79
-32
lines changed

1 file changed

+79
-32
lines changed

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

Lines changed: 79 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,13 @@ After adding an API from API Management, you can add metadata and documentation
3939
> [!NOTE]
4040
> `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).
4141
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.
4444
4545

4646
## Add a managed identity in your API center
4747

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

5050
### Add a system-assigned identity
5151

@@ -61,9 +61,7 @@ For this scenario, your API center uses a [managed identity](/entra/identity/man
6161
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:
6262

6363
```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"}'
6765
```
6866
---
6967

@@ -111,9 +109,7 @@ To add a user-assigned identity, you need to create a user-assigned identity res
111109
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`.
112110
113111
```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"
117113
```
118114
---
119115
@@ -138,35 +134,63 @@ To allow import of APIs, assign your API center's managed identity the **API Man
138134
139135
**System-assigned identity**
140136
```azurecli
141-
# Get the principal ID of the system-assigned identity in your API center
137+
#! /bin/bash
142138
apicObjID=$(az apic service show --name <api-center-name> \
143139
--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)
145148
```
146149
147150
**User-assigned identity**
148151
```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> \
151-
--resource-group <resource-group-name> \
152-
--query principalId --output tsv)
152+
#! /bin/bash
153+
apicObjID=$(az identity show --name <identity-name> --resource-group <resource-group-name> --query "principalId" --output tsv)
153154
```
154155
156+
```azurecli
157+
# PowerShell syntax
158+
apicObjID=$(az identity show --name <identity-name> --resource-group <resource-group-name> --query "principalId" --output tsv)
159+
```
155160
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
161+
1.
156162
```azurecli
157-
apimID=$(az apim show --name <apim-name> \
158-
--resource-group <resource-group-name> \
159-
--query id --output tsv)
163+
#! /bin/bash
164+
apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query "id" --output tsv)
165+
```
166+
167+
```azurecli
168+
# PowerShell syntax
169+
$apimID=$(az apim show --name <apim-name> --resource-group <resource-group-name> --query "id" --output tsv)
160170
```
161171
162172
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+
163174
```azurecli
175+
#! /bin/bash
176+
scope="${apimID:1}"
177+
164178
az role assignment create \
165-
--role "API Management Service Reader Role"\
179+
--role "API Management Service Reader Role" \
166180
--assignee-object-id $apicObjID \
167181
--assignee-principal-type ServicePrincipal \
168-
--scope "${apimID:1}"
182+
--scope $scope
169183
```
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
170194
---
171195
172196
## Import APIs from your API Management instance
@@ -185,17 +209,30 @@ Use a wildcard (`*`) to specify all APIs from the API Management instance.
185209
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
186210
187211
```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)
191219
```
192220
193221
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.
194222
195223
```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
199236
```
200237
201238
> [!NOTE]
@@ -208,17 +245,27 @@ Specify an API to import using its name from the API Management instance.
208245
1. Get the resource ID of your API Management instance using the [az apim show](/cli/azure/apim#az-apim-show) command.
209246
210247
```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)
214255
```
215256
216257
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.
217258
218259
```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
222269
```
223270
224271
> [!NOTE]

0 commit comments

Comments
 (0)