Dear Team
I have below JSON payload .
I wanted to extract paynumber as json variable.
i tried using "$.usefullFields.paynumber".
However the value is not getting extracted.
Do you have any ideas?, I am running out of luck. No idea why we have this strange behavior!! 🙂
{ "usefull_val": "f243b5d507bc4c1a8e74b3c926390da468f5e161", "usefullFields": { "paynumber": "002022059182" }, "customuser": { "timezone": "America/Los_Angeles" }, "costomer_source": { "id": "e16e9a992d2f4044", "url": "http://example.com/e16e9a992d2f4044" } }
I'm assuming you are sourcing from the request payload?
I've been able to extract the paynumber and assign it to a req.body.paynumber variable using the following:
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-ExtractReqPayload"> <DisplayName>EV-ExtractReqPayload</DisplayName> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <JSONPayload> <Variable name="req.body.paynumber"> <JSONPath>$.usefullFields.paynumber</JSONPath> </Variable> </JSONPayload> <Source clearPayload="false">request</Source> </ExtractVariables>
yes, you are right, its request payload.
however the same straightforward one does not work for me.
BTW , paynumber is always a number .
Below is my policy. I use opdk latest version.
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> <ExtractVariables async="false" continueOnError="false" enabled="true" name="EV.Body"> <DisplayName>EV.Body</DisplayName> <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables> <Properties/> <JSONPayload> <Varable name="payNumber"> <JSONPath>$.usefullFields.paynumber</JSONPath>
</Varable> <Variable name="countlimit"> <JSONPath>$.countlimit</JSONPath> </Variable> </JSONPayload> </ExtractVariables>
Anyways , i solved it by using js and it worked fine. I dont prefer the js though.
<br>var inReq= context.getVariable("request.content"); <br>var inReqObject = JSON.parse(inReq); <br>var payNumber= inReqObject.usefullFields.paynumber;<br>context.setVariable('payNumber', payNumber);
odd that it doesn't work. does your policy extract countlimit correctly? the only time i've encountered issues with extract is when i've set my content-type to 'text' rather than 'application/json' in postman.
i agree - JS isn't ideal
Make sure you are setting the Content Type to application/json
Extract Variables policy will need that if it needs to parse the JSON request.
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |