Extract Variable Policy not working

I am trying to extract variables of request payload using extract variable policy. below is the code I am using. 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables continueOnError="false" enabled="true" name="EV-Payload">
<DisplayName>EV-Payload</DisplayName>
<Properties/>
<IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
<JSONPayload>
<Variable name="MillId">
<JSONPath>$.MillId</JSONPath>
</Variable>  
<Variable name="Quantity">
<JSONPath>$.Quantity</JSONPath>
</Variable> 
</JSONPayload>
<Source clearPayload="false">request</Source>
<VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>

 

But the policy is not extracting values. Can anyone identify the error I made. 

Thanks,

Hira

2 2 57
2 REPLIES 2

My payload is below 

{
    "MillId": "98"
    "Quantity": "1500"     
}

 

ExtractVariables with the JSONPayload optionwill work, only if the content-type is application/json .

If you have a text/plain content-type, then EV will ignore it and will not extract. Could that possibly be what you are seeing?

When I try your policy with a sample proxy, it works if the content-type is correct.

$ curl -i $apigee/ev-json-payload-test/t1 -H content-type:application/json -d '{ "MillId": "abcd", "Quantity" : "1500" }' 
HTTP/2 200 
content-type: application/json
content-length: 72
apiproxy: ev-json-payload-test r1
x-request-id: b36abf87-0021-47df-a1fd-f7cc5524fc01
date: Fri, 23 Feb 2024 17:33:36 GMT
via: 1.1 google, 1.1 google
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

{
    "status" : "ok",
    "MillId" : "abcd",
    "Quantity" : "1500"
}

$ curl -i $apigee/ev-json-payload-test/t1 -d '{ "MillId": "abcd", "Quantity" : "1500" }'                  
HTTP/2 200 
content-length: 64
content-type: application/json
apiproxy: ev-json-payload-test r1
x-request-id: 896f7d00-5e89-4e92-a369-06822bec1a45
date: Fri, 23 Feb 2024 17:33:47 GMT
via: 1.1 google, 1.1 google
alt-svc: h3=":443"; ma=2592000,h3-29=":443"; ma=2592000

{
    "status" : "ok",
    "MillId" : "",
    "Quantity" : ""
}