How do I extract values from json NOT using extract variables policy

How do I extract values from a json payload and use it directly without using extract variable policy and assign message policy.

My intent here is to use the values from payload to do a service callout

For example :

Input request

{

"key1":"value1",

"key2":"value2"

}

use these values in service callout as query param

I've tried using

{jsonPath($.key1)}

{request.formparam.key1}

{$.key1}

nothing worked.

Below is the policy code if it helps

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ServiceCallout async="false" continueOnError="false" enabled="true" name="Info_Service">
    <DisplayName>Info_Service</DisplayName>
    <Properties/>
    <Request clearPayload="true">
        <IgnoreUnresolvedVariables>false</IgnoreUnresolvedVariables>
        <Set>
            <QueryParams>
                <QueryParam name="info">{jsonPath($.key1,request.content)}</QueryParam>
            </QueryParams>
            <Verb>GET</Verb>
        </Set>
    </Request>
    <Response>calloutResponse</Response>
    <LocalTargetConnection>
        <APIProxy>infoService</APIProxy>
        <ProxyEndpoint>/abc/bbc/def</ProxyEndpoint>
    </LocalTargetConnection>
</ServiceCallout>
1 8 520
8 REPLIES 8

You need to also include the variable upon which to use the JSON Path expression. For example:

{jsonPath($.key1,request.content)}

"faultstring": "Unresolved variable : $.key1,request.content",

<QueryParam name="info">{jsonPath($.key1,request.content)}</QueryParam>

Can you include your full policy?

This certainly looks like a bug. I was able to reproduce your error. However the same jsonPath expression works fine in other policies. Eg:

Assign Message

<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-testJSONPath">
    <DisplayName>AM-testJSONPath</DisplayName>
    <AssignVariable>
        <Name>theJSONPath</Name>
        <Template>{jsonPath($.key1,request.content)}</Template>
    </AssignVariable>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

Raise Fault

<RaiseFault async="false" continueOnError="false" enabled="true" name="RF-testJSONPath">
    <DisplayName>RF-testJSONPath</DisplayName>
    <Properties/>
    <FaultResponse>
        <Set>
            <Payload contentType="application/json">{
  "errors": [
    {
      "code": "400",
      "title": "Test JSON Path",
      "detail": "{jsonPath($.key1,request.content)}"
    }
  ]
}</Payload>
            <StatusCode>400</StatusCode>
            <ReasonPhrase>Testing JSON Path}</ReasonPhrase>
        </Set>
    </FaultResponse>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</RaiseFault>

I'll be opening a bug, but it might take a while for the fix to be available. In the meantime, I'm afraid you'll have to use either ExtractVariables or AssignMessage as a workaround

Can you please suggest how do I use extract variables and use the values in service callout. I've tried extracting and assigning to a variable in extract variable policy and refer the variable in QueryParams but that resulted in calling with name rather than value.

Even I see the same error while using JSONPath in Service callout policy.

For the time being if you want to avoid Extract variable policy, then use any Assign Message policy before the Service callout policy, set the AssignVariable and use {info} within Service callout policy,

 <AssignVariable>
        <Name>info</Name>
        <Value/>
        <Ref/>
        <Template>{jsonPath($.key1,request.content)}</Template>
    </AssignVariable>

Hi, this dint work either. there is no error and the value of variable is empty.

You can set the entire service callout request message in the AssignMessage policy, and then just reference that variable in the ServiceCallout