Raise Fault condition to check the property in Json Response Service callout

I have a use case where I am creating a composite proxy.. I am doing a service callout and extract variables from the JSON response a particular value. I want to raise  a fault when this json does not contain this property.

How do I check in my Raise fault condition if the response json from the service callout does not contain the property ?

 

 

    <PreFlow name="PreFlow">
        <Request>
            <Step>
                <Name>get-apikey</Name>
            </Step>
            <Step>
                <Name>Search-Endpoint</Name>
            </Step>
            <Step>
                <Name>extract-content-id</Name>
            </Step>
            <Step>
                <Name>Empty-Search-Results-Raise-Fault</Name>
                <Condition>($.content-id == null)</Condition>
            </Step>
            <Step>
                <Name>set-apikey-header</Name>
            </Step>
        </Request>
        <Response/>
    </PreFlow>

 

 

 

Solved Solved
1 4 239
1 ACCEPTED SOLUTION

The configuration of the ExtractVariables policy determines the variable name that will contain the extracted value. If you followed the example policy configuration that I showed you, then extracted.content-id is the name of the variable that will hold the extracted content-id. The VariablePrefix element specifies the prefix of the variable name to set. In my case, this is "extracted". The name attribute on the Variable element indicates the variable-name suffix. Concatenated, this gives you extracted.content-id. I just looked and ... I think the documentation could be clearer on this point. I'll see about getting it updated.

After ExtractVariables executes, this variable will hold the value of the top-level field named content-id in the JSON. This variable will be null if no top-level field named content-id was present in the JSON. If you used some other configuration for ExtractVariables, then your variable may be different.

If you're still having trouble, maybe you could show me what you used for ExtractVariables, and for your Condition?

View solution in original post

4 REPLIES 4

A Condition cannot peer into a JSON payload. You cannot use jsonpath expressions directly in a condition, at least not at the moment! 

So you would need to extract the value, with an ExtractVariables policy, and then in the Condition examine the extracted value.  Your policy step named  "extract-content-id" suggests that you are already trying to do that. The ExtractVariables policy will look something like this: 

<ExtractVariables name='EV-Content-ID'>
  <!-- the Source should refer to the response message from the ServiceCallout -->
  <Source>tokenResponse</Source>
  <VariablePrefix>extracted</VariablePrefix>
  <JSONPayload>
    <Variable name='content-id'>
       <JSONPath>$.contend-id</JSONPath>
    </Variable>
  </JSONPayload>
</ExtractVariables>

And then the policy flow, including the condition around the RaiseFault, is like this: 

...
<Step>
  <Name>SC-External-Search</Name>
</Step>
<Step>
  <Name>EV-Content-ID</Name>
</Step>
<Step>
  <Condition>extracted.content-id = null</Condition>
  <Name>RF-Missing-Content-ID</Name>
</Step>
...

 

When I do the check I always get the condition to be true even though the value is still present. I was wondering how to refer the variable that is extracted in the condition ?

The configuration of the ExtractVariables policy determines the variable name that will contain the extracted value. If you followed the example policy configuration that I showed you, then extracted.content-id is the name of the variable that will hold the extracted content-id. The VariablePrefix element specifies the prefix of the variable name to set. In my case, this is "extracted". The name attribute on the Variable element indicates the variable-name suffix. Concatenated, this gives you extracted.content-id. I just looked and ... I think the documentation could be clearer on this point. I'll see about getting it updated.

After ExtractVariables executes, this variable will hold the value of the top-level field named content-id in the JSON. This variable will be null if no top-level field named content-id was present in the JSON. If you used some other configuration for ExtractVariables, then your variable may be different.

If you're still having trouble, maybe you could show me what you used for ExtractVariables, and for your Condition?

It is my bad.. I missed it 🙂 .. Thank you it all worked