Extract Variable policy is not extracting the desired variable from a response of POST method

Extract Variable policy is not extracting the desired variable from a response of POST method

I have created an apiproxy with no target and on that created apigee endpoint i am sending body data using a rest api "POST" method via apigee rest client. In apigee Preflow response i have added an extract variable policy with some desired variables to be extracted from the response, but the variables are not being extracted.

Below is my Extract variable policy :

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-json-payload">
    <DisplayName>Extract Variables-json payload</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="data_1">
            <JSONPath>$.matrics..weighted_io_time</JSONPath>
        </Variable>
        <Variable name="data_2">
            <JSONPath>$.matrics..inodes_total</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">response</Source>
</ExtractVariables>

Please find attached my api proxy

no-target-with-data-rev1-2018-10-02.zip

Note : The data what we are sending via POST method contains the desired variables to be extracted.

Solved Solved
0 12 1,393
1 ACCEPTED SOLUTION

Hi @Siddharth Barahalikar Can you please help me in this.

View solution in original post

12 REPLIES 12

Hi @Siddharth Barahalikar Can you please help me in this.

Solution is just add header "Content-Type: application/json" while sending POST request.

Add Header "Content-Type: application/json" in rest client curl/POST/Apigee rest client. Then it will work.

Hi @Ankit Goel, when using no-target proxy, why are you trying to extract on response side?

You are trying to extract a variable from request JSON(sent using Rest Client), so add the policy on request side and change the Source to request.

Most of the time we add policies on response side when we want to modify/play around with data which is returned from the backend/target service. In your example, it is no-target proxy so there is no target and hence there is no response data for extract variable policy to extract.

I tried after adding it in request flow as well but still in traces i am not able to see the extracted values.

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-json-payload">
    <DisplayName>Extract Variables-json payload</DisplayName>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="data_1">
            <JSONPath>$.matrics..weighted_io_time</JSONPath>
        </Variable>
        <Variable name="data_2">
            <JSONPath>$.matrics..inodes_total</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">request</Source>
</ExtractVariables>

Pls provide your sample JSON data.

BTW why areyou using double dots?(matrics..weighted_io_time)

I am using double dot as per the JSONPATH , As i am trying to extract the value of "weighted_io_time" and "inodes_total" in the complete JSON array 

Input is JSON nested array:

Attached is the input JSON array.

inout-json-nested-array.txt

    

<ExtractVariables async="false" continueOnError="false" enabled="true" name="Extract-Variables-json-payload">
    <DisplayName>Extract Variables-json payload</DisplayName>
    <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="data_1">
            <JSONPath>$.metrics[13].fields.weighted_io_time</JSONPath>
        </Variable>
        <Variable name="data_2">
            <JSONPath>$.metrics[18].fields.inodes_total</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">request</Source>
</ExtractVariables>

Please try this.

But here you have mentioned the index no. but my requirement is , i have to extract the desire value from the json array without mentioning index no. because the structure of JSON array is dynamic, the index no might be changing. This JSON array is being generated dynamically. I need to search the desired value and if it available then extract it.

It didn't work, same issue what i was having already.

HI @Siddharth Barahalikar Can You please see why it is not working.


I am also facing the same issue. Not able to extract variables for JOSN payload. Could you please help me with the same.

No - Please, do not ask new questions in answers to old questions.

POST a new question. If you decide to do that, post DETAILS. Not just "This is not working for me, help me please." No one can help you with that kind of request. You must provide DETAILS, including an example of your JSON payload and the specific policy configuration you used. Don't post them here. Post it as a NEW QUESTION.