Trouble with ExtractVariables policy

Not applicable

when I am working with the ExtractVariables policy, it shows 500 Error.

My Baas Collection code is

{ "Name": "PavanKumar", "LOC": "Bhogapuram", "ID": "3537" }

In Extract variable i want to extract only Name from the Json payload.For that i was written the code below

<ExtractVariables name="Extract-Variables">
  <DisplayName>Extract Variables</DisplayName>
  <Source>Response</Source>
  <JSONPayload>
    <Variable name="Name" type="String">
      <JSONPath>$.results[0].pavans.Name.lat</JSONPath>
    </Variable>
  </JSONPayload>
</ExtractVariables>

when I am executing, it gives error content like

{
    "fault": {
        "faultstring": "Response message is not available for ExtractVariable: Extract-Variables",
        "detail": {
            "errorcode": "steps.extractvariables.SourceMessageNotAvailable"
        }
    }
}

please guide me to work out it.

1 4 1,527
4 REPLIES 4

The ExtractVariables policy is really nice, but there is one thing that often trips people up: ExtractVariables operates on a message.

The error message you provided says "SourceMessageNotAvailable". I conclude that the source message you are specifying isn't available, or has the value null.

In your policy configuration you specify the source as "Response". Does this variable exist? You can check this using the Trace UI. The normal name of the response message is 'response' - all lowercase. These may resolve to different values.

Second, if you use the ExtractVariables policy configured that way in the request flow, the response variable will not yet exist. It will resolve to null.

So I think the solution is for you to specify the correct Source element in the ExtractVariables policy.

You can check out the doc for ExtractVariables, as well as a couple short screencasts walking through how it works.

The last thing I will mention.... the JSONPath you specify

<JSONPath>$.results[0].pavans.Name.lat</JSONPath>

...does not apply to the message body you cited, which is

{ "Name": "PavanKumar", "LOC": "Bhogapuram", "ID": "3537" }

That JSONPath will not work with your payload. Maybe you are already aware.

As per your suggestion I changed path to

<JSONPath>$.results[0].pavans.name.Name</JSONPath>

It's also showing 500-internal server error.

It's written the Error content

{"fault":{"detail":{"errorcode":"steps.extractvariables.InvalidJSONPath"},"faultstring":"Invalid JSON path $.results[0].pavans.Name in policy Extract-Variables."}}

please help me to solve this problem.

Yes,

Supposing your payload is like this:

{ "Name": "PavanKumar", "LOC": "Bhogapuram", "ID": "3537" }

Then the JSON Path for the elements there is:

path element value
$.Name Name Pavan
$.LOC LOC Bhogapuram
$.ID ID 3537
$.results[0].pavans.name.Name -- invalid!

But I suspect that your payload is more complex than that.

You can try out JSONPath expressions using an online evaluator, like http://jsonpath.com/.

This might sound really simple, but try the source as 'request' instead of 'Request'.