An Azure service that provides a hybrid, multi-cloud management platform for APIs.
Also one more thing I noticed, when I change POST request to get request, I am getting same error.
Expression evaluation failed. The message body is not a valid JSON. Unexpected character encountered while parsing value: <. Path '', line 0, position 0. at Newtonsoft.Json.JsonTextReader.ParseValue() at Newtonsoft.Json.Linq.JObject.Load(JsonReader reader, JsonLoadSettings settings) at Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.MessageBody.AsJObject(Stream stream, Encoding encoding, JsonSerializerSettings settings) at Microsoft.WindowsAzure.ApiManagement.Proxy.Gateway.MessageBody.As[T](Boolean preserveContent)
I am getting error at below line.
<set-header name="Authorization" exists-action="override">
<value>@("Bearer " + (String)((IResponse)context.Variables["bearerToken"]).Body.As<JObject>()["access_token"])</value>
</set-header>
Here is my complete Policy
<inbound>
<base />
<set-variable name="token" value="@(context.Request.Headers.GetValueOrDefault("Authorization","scheme param").Split(' ').Last())" />
<set-header name="Authorization" exists-action="delete" />
<!-- Send request to Token Server to validate token (see RFC 7662) -->
<send-request ignore-error="true" timeout="20" response-variable-name="bearerToken" mode="new">
<set-url>https://login.microsoftonline.com/{tanentid}/oauth2/v2.0/token</set-url>
<set-method>GET</set-method>
<set-header name="Content-Type" exists-action="override">
<value>application/x-www-form-urlencoded</value>
</set-header>
<set-body>@{
return "client_id={xxx}&scope={api://xxxx/.default}&client_secret={xxxx}&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://nma3-dpioto-bld-fa2.azurewebsites.net/api/bus/inbound-general-q" />
</inbound>