I have a middleware Azure API where the consumers POST a json body value such as this
{
"subscriptionId": "42345",
"type": "MailPieceId",
"status": [
{
"failedValues": [
"abc",
"123@"
],
"reason": "Invalid barcodes"
}
],
"customerWebhook": "https://url",
"referenceNumber": "12345"
}
I need to fetch the value of "customerWebhook" from the json request body and set it as the service backend url, as the url in the json body will be different for every new request.
Currently i am using this in my inbound policy.
<set-variable name="myVar" value="@(context.Request.Body.As<JObject>()["customerWebhook"])" />
<set-backend-service base-url="@(((string)context.Variables["myVar"]).ToString())" />
But this is the error that i keep getting.
"message": "Expression evaluation failed.",
"expression": "((string)context.Variables[\"myVar\"]).ToString()",
"details": "Unable to cast object of type 'Newtonsoft.Json.Linq.JValue' to type 'System.String'."
Can anyone please let me know a solution in this case.