Extract Variable

Im trying to extract the ErrorCode from the response content as show in the image capture3.png

Im using the below extract variable policy and Im not able to extract the ErrorCode.

Is the below written policy is wrong?

<ExtractVariables async="false" continueOnError="false" enabled="true" name="EV-ClientErrorHandling"> 
  <DisplayName>EV-ClientErrorHandling</DisplayName> 
  <Properties/> 
  <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables> 
  <JSONPayload> 
    <Variable name="errorCode"> 
      <JSONPath>$.ErrorCode</JSONPath> 
    </Variable> 
  </JSONPayload> 
  <Source clearPayload="false">response</Source> 
</ExtractVariables>
Solved Solved
0 3 135
1 ACCEPTED SOLUTION

HI @Gopal D J - nothing wrong with the policy. Is that a response coming from a backend ? Can you confirm the Content-Type header is set to application/json on the response as well

View solution in original post

3 REPLIES 3

HI @Gopal D J - nothing wrong with the policy. Is that a response coming from a backend ? Can you confirm the Content-Type header is set to application/json on the response as well

@Sai Saran Vaidyanathan the response is coming from OAuth when the authentication fails and the content-type header is application/x-www-form-urlencoded.

But when I set the Content-Type header to application/json , Im getting this error -

{ "fault": { "faultstring": "Invalid JSON path $.ErrorCode in policy EV-ClientErrorHandling.", "detail": { "errorcode": "steps.extractvariables.InvalidJSONPath" } } }

you wrote:

the response is coming from OAuth

What system is OAuth? is that an external system? If the OAuth system is a target (from the perspective of Apigee Edge), and if the target is also sending an HTTP status code that is not in the 200-range, for example a 400 or 401, then the response flow within Apigee will enter fault state. This means the policies placed in the normal response flow will not be executed, and instead the policies in the fault rules will be executed.

If this is what is happening, then perhaps your correctly-configured policy is not actually executing. You could confirm this by using the Trace UI to see which policies run, and which do not.

To avoid this, you need to either:

  • attach the policy to a FaultRule, OR
  • Set the successCodes on the http target so that 4xx status codes do not result in fault flow within Apigee Edge.