Scripts/Import-AzApiManagementApiPolicy.ps1

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
param(
   [string][parameter(Mandatory = $true)] $ResourceGroupName,
   [string][parameter(Mandatory = $true)] $ServiceName,
   [string][parameter(Mandatory = $true)] $ApiId,
   [string][parameter(Mandatory = $true)] $policyFilePath
)

# Retrieve the context of APIM
$apimContext = New-AzApiManagementContext -ResourceGroupName $ResourceGroupName -ServiceName $ServiceName

# Check if an operationId has been specified, it not - import the base policy
Write-Host "Updating policy of API '$ApiId'"
$result = Set-AzApiManagementPolicy -Context $apimContext -ApiId $ApiId -PolicyFilePath $policyFilePath
if ($result) {
    Write-Host "Successfully updated API policy"
} else {
    Write-Error "Failed to update API policy, please check parameters"
}