Extract variable content from an input request Json body using JsonPath is not working as expected

Not applicable

I have this input body

{ "ignoreTransactionRequest": { "reservationStatus": "Pending", "confirmationNumber": "64174560" } }

with header {"Content-Type":"application/json"}

And this policy to extract the values using

<IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>

<Source clearPayload="false">request</Source>

<JSONPayload>

<Variable name="reservationStatus"> <JSONPath>$.ignoreTransactionRequest.reservationStatus</JSONPath>

</Variable>

<Variable name="confirmationNumber"> <JSONPath>$.ignoreTransactionRequest.confirmationNumber</JSONPath>

</Variable>

</JSONPayload>

<VariablePrefix>reservation</VariablePrefix>

</ExtractVariables>

I simply cannot get the content of the json data into the reservation.resservationStatus nor reservation.confirmationNumber.

What is wrong?

0 3 7,475
3 REPLIES 3

@Normand Plouffe , Welcome to Apigee Communtity,

It works fine for me, Please find sample proxy, policy, API call below,

Proxy Attached : no-target-3-rev1-2017-05-04.zip

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-1">
    <DisplayName>Extract Variables-1</DisplayName>
    <Properties/>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <Source clearPayload="false">request</Source>
    <JSONPayload>
        <Variable name="reservationStatus">
            <JSONPath>$.ignoreTransactionRequest.reservationStatus</JSONPath>
        </Variable>
        <Variable name="confirmationNumber">
            <JSONPath>$.ignoreTransactionRequest.confirmationNumber</JSONPath>
        </Variable>
    </JSONPayload>
    <VariablePrefix>reservation</VariablePrefix>
</ExtractVariables>

API Call :

curl -X POST \
  http://apigee4mv4d-test.apigee.net/no-target-3 \
  -H 'cache-control: no-cache' \
  -H 'content-type: application/json' \
  -d '{ "ignoreTransactionRequest": { "reservationStatus": "Pending", "confirmationNumber": "64174560" } }'

Trace Output with JS Policy to verify same :

 print(context.getVariable("reservation.reservationStatus"));
 print(context.getVariable("reservation.confirmationNumber"));

4775-screen-shot-2017-05-04-at-84530-am.png

Remember, Trace doesn't show variables until unless they are used in other policies. For example, In above proxy, we have used variables in JS Policy, When you click on JS Policy in trace you can see the filled in variables.

Hope it helps. Keep us posted moving forward if any query related to APIs / Apigee.

HI @Anil Sagar @ Google i am also facing similar issue and i not seeing that extract variable policy is extracting any value at all, even i tried with your attached api proxy revision but i am not seeing any value extracted even at JS script policy.

Please look at my question as well

https://community.apigee.com/questions/61373/extract-variable-policy-is-not-extracting-the-desi.html...



Not applicable

I also faced the same issue while using Postman as the client. And the below steps solved the problem.

Change content-type to text and post the request.

Again, change content-type to application\json and post the request.

This solved the problem and didn't faced it again.