Reputation: 9870
I am trying to add the following in bound processing policy to my APIM for an operation:
<policies>
<inbound>
<base />
<rewrite-uri template="/stores/{Location}/slots?StartDate={StartDateTime}&AppointmentType={AppointmentType}" />
<set-header name="ocp-apim-subscription-key" exists-action="override">
<value>12d0bdd57ca84fa9ad35f13f22605dbf</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
I have found this commandlet, however there is no information on what to put in -Policy
.
I have tried using the following
$policyString = '<policies>
<inbound>
<base />
<rewrite-uri template="/stores/{Location}/slots?StartDate={StartDateTime}&AppointmentType={AppointmentType}" />
<set-header name="ocp-apim-subscription-key" exists-action="override">
<value>12d0bdd57ca84fa9ad35f13f22605dbf</value>
</set-header>
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>'
Set-AzureRmApiManagementPolicy -Context $apiMgmtContext -ApiId $apiId -Policy $policyString -OperationId 'GetCalendar'
But it gives me this error:
Operation returned an invalid status code 'BadRequest'
What format is the Policy param expecting?
Upvotes: 1
Views: 506
Reputation: 9870
Thanks to Joy Wang for pointing me in the right direction, here's the solution:
I tried adding the XML directly through the portal, and got this error:
One or more fields contain incorrect values: Error in element 'rewrite-uri' on line 4, column 10: Only parameters specified in the original URL template can be used in the rewrite template
Turns out the parameters I was referring to (StartDateTime
and AppointmentType
) were not part of the template params in the APIM.
Once I added them as template params in APIM, the command worked.
Would be good if the Powershell commandlet returned the same error as the Azure Portal, rather than just 'BadRequest'
Upvotes: 0
Reputation: 42043
I can reproduce your issue, the format of -Policy
parameter seems to be correct, the issue was caused by the rewrite-uri
in your policy.
<rewrite-uri template="/stores/{Location}/slots?StartDate={StartDateTime}&AppointmentType={AppointmentType}" />
I test it with the sample in the official doc, it works fine.
<rewrite-uri template="/put" />
For more details about the usage of rewrite-uri
, you could refer to this link.
Upvotes: 1