I'm trying to automate an APIM policy deployment via Azure devops. The policy uses a client id & client secret to generate a bearer token for CRM. I've tried a number of ways of deploying the policy, ARM template, Azure Devops plugin from here https://github.com/stephaneey/azure-apim-extension. All of these fail with the same error.
Status Message: One or more fields contain incorrect values: (Code: ValidationError)
- '=' is an unexpected token. The expected token is ';'. Line 11, position 76. (Code:ValidationError)
The policy I'm trying to deploy is this
<policies>
<inbound>
<base />
<send-request mode="new" response-variable-name="bearerToken" timeout="20" ignore-error="true">
<set-url>https://login.microsoftonline.com/{TENANT_ID}/oauth2/token</set-url>
<set-method>POST</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/x-www-form-urlencoded</value>
</set-header>
<set-body>@{
return "client_id={CLIENT_ID_VALUE}&resource=https://{CRMINSTANCE}.dynamics.com/&client_secret={CLIENT_SECRET}grant_type=client_credentials";
}</set-body>
</send-request>
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + (String)((IResponse)context.Variables["bearerToken"]).Body.As<JObject>()["access_token"])</value>
</set-header>
<set-backend-service base-url="https://{CRMINSTANCE}.dynamics.com/api/data/v9.1/" />
</inbound>
<backend>
<base />
</backend>
<outbound>
<base />
</outbound>
<on-error>
<base />
</on-error>
</policies>
If I paste the policy xml directly into the APIM operation everything works as expected.