How to extract values from a ServiceCallout response?

I want to parse only two variables from service callout response payload to main proxy , how can i parse these variables from servicecallout response to my main proxy and how to access these variables in main proxy?

Proxy 1 is sending some data and when it calls another proxy using service callout , my proxy 2 runs and provide me response , i want to use this response payload from proxy 2 and extract three varibles from this proxy to compare with some variable in proxy1

Solved Solved
0 2 1,471
2 ACCEPTED SOLUTIONS

Not applicable

You will see the response from service callout will be assigned to a variable, that is specified in the service callout policy as below.

<Response>calloutResponse</Response>

Now next to the service callout you have to use an extract variable policy which will be over the above response and you can extract what you want from the response body and use the same further in the main request.

View solution in original post

You have some options.

  • ExtractVariables can be used. In the EV policy configuration, You need to specify the Source message to be the Response message from the ServiceCallout.

    <ExtractVariables name='EV-1'>
      <Source>serviceCalloutResponse</Source>
      <VariablePrefix>extracted</VariablePrefix>
      <JSONPayload>
        <Variable name='something'>
           <JSONPath>$.results[?(@.name == 'Chris Schiller')][0].address.line1</JSONPath>
        </Variable>
      </JSONPayload>
    </ExtractVariables>
    
    
    
  • If your response is in XML or JSON, You can use AssignMessage and message templates, using the xpath or jsonpath functions.

     <AssignMessage name='AM-Extract'>
     
      <AssignVariable>
        <Name>json_path_1</Name>
        <Value>$.results[?(@.name == 'Chris Schiller')][0].address.line1</Value>
      </AssignVariable>
      <AssignVariable>
        <Name>assigned</Name>
        <Value>BADDBEEF</Value>
        <Template>{jsonPath(json_path_1,serviceCalloutResponse.content)}</Template>
      </AssignVariable>
    
    
    </AssignMessage>
    
    
    

View solution in original post

2 REPLIES 2

Not applicable

You will see the response from service callout will be assigned to a variable, that is specified in the service callout policy as below.

<Response>calloutResponse</Response>

Now next to the service callout you have to use an extract variable policy which will be over the above response and you can extract what you want from the response body and use the same further in the main request.

You have some options.

  • ExtractVariables can be used. In the EV policy configuration, You need to specify the Source message to be the Response message from the ServiceCallout.

    <ExtractVariables name='EV-1'>
      <Source>serviceCalloutResponse</Source>
      <VariablePrefix>extracted</VariablePrefix>
      <JSONPayload>
        <Variable name='something'>
           <JSONPath>$.results[?(@.name == 'Chris Schiller')][0].address.line1</JSONPath>
        </Variable>
      </JSONPayload>
    </ExtractVariables>
    
    
    
  • If your response is in XML or JSON, You can use AssignMessage and message templates, using the xpath or jsonpath functions.

     <AssignMessage name='AM-Extract'>
     
      <AssignVariable>
        <Name>json_path_1</Name>
        <Value>$.results[?(@.name == 'Chris Schiller')][0].address.line1</Value>
      </AssignVariable>
      <AssignVariable>
        <Name>assigned</Name>
        <Value>BADDBEEF</Value>
        <Template>{jsonPath(json_path_1,serviceCalloutResponse.content)}</Template>
      </AssignVariable>
    
    
    </AssignMessage>