JSONPath Question

I am trying to extract a JSON variable and need some rudimentary help. The target is another ApiProxy which returns back a JSON body. However, when I run my ApiProxy (proxies/Gigya-Redux/develop/1) in Trace, the ExtractVariables never shows any extracted values. I've tried several variations of the JSONPath including the following (which all are valid JSONPath):


<JSONPath>$.callId</JSONPath>
<JSONPath>$.results[0].lastUpdatedTimestamp</JSONPath>


Any help would be appreciated.


The LocalTargetConnection returns this JSON in the body:

{
  "callId": "2976aaf1fb184608ac9c9d2fc24f75ba",
  "errorCode": 0,
  "apiVersion": 2,
  "statusCode": 200,
  "statusReason": "OK",
  "time": "2019-05-16T22:34:10.901Z",
  "results": [
    {
      "lastUpdatedTimestamp": 1557859336355,
    }
  ],
  "objectsCount": 1,
  "totalCount": 1
}



My ApiProxy looks like this:

<ProxyEndpoint name="default">
...
    <PreFlow name="PreFlow">
        <Request/>
        <Response>
            <Step>
                <Name>EV-JSON-name</Name>
            </Step>
        </Response>
     </PreFlow>
...
</ProxyEndpoint>

The ExtractVariables EV-JSON-name looks like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-JSON-name">
    <Source clearPayload="false">response</Source>
    <DisplayName>EV-JSON-name</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="name">
            <JSONPath>$.callId</JSONPath>
        </Variable>
    </JSONPayload>
    <VariablePrefix>apigee</VariablePrefix>
</ExtractVariables>
0 4 253
4 REPLIES 4

Can you verify the content type of your payload is application/json?

I've added the following AssignMessage in the proxy preflow response and it seems to change the the header as expected. However, the ExtractVariables EV-JSON which runs after the AssignMessage, still does not pick up any of the JSON. Any ideas?

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="setContentHeaderJson">
    <DisplayName>setContentHeaderJson</DisplayName>
    <Set>
        <Headers>
            <Header name="Content_Type">application/json</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

@Nagashree B Thank you!!

had a typo in the above method:

<Header name="Content_Type">application/json</Header>

rather than

<Header name="Content-Type">application/json</Header>	

Thus, the fix is to have the AssignMessages before the ExtractVariables

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="setContentHeaderJson">
    <DisplayName>setContentHeaderJson</DisplayName>
    <Set>
        <Headers>
            <Header name="Content-Type">application/json</Header>
        </Headers>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Glad you figured it out!