Get hands-on experience with 20+ free Google Cloud products and $300 in free credit for new customers.

Access JSON payload properties in Assign Message policy

I found that we can do request.header.{header_name}.value to get header values.

Instead of doing a extract variable for each property and then use Assign Message.

Is there any way we can use directly the properties of JSON payload in Assign Message?

It would be a good enhancement to access payload using JSONPath or XPath in policies if its not available already.

Solved Solved
4 5 1,913
1 ACCEPTED SOLUTION

Great Question & Suggestion @Mohammed Zuber ,

I don't think Assign Message Policy supports jsonPath or Xpath as of today. You need to use java callout / javascript / extract variables & then assign message to do same as of today.

EDIT: not quite completely true. See answer lower in this thread.

View solution in original post

5 REPLIES 5

Great Question & Suggestion @Mohammed Zuber ,

I don't think Assign Message Policy supports jsonPath or Xpath as of today. You need to use java callout / javascript / extract variables & then assign message to do same as of today.

EDIT: not quite completely true. See answer lower in this thread.

Hi

I just use jsonPath to extract value from json, 

I m calling service callout, and this service callout throwing exception with error message in a variable : 

ServiceCallout.response

This variable having value:  {"code":"","message":"some error message"}

my intention to extract both code and message.

and my code of assignmessage policy is

<AssignVariable>
<Name>sco.err.mesg.path</Name>
<Value>message</Value>
</AssignVariable>
<AssignVariable>
<Name>sco.err.msg</Name>
<Template>{jsonPath(sco.err.mesg.path,ServiceCallout.response)}</Template>
</AssignVariable>

I got the message value in variable: sco.err.msg

some error message

 

I think the only solution today is to use a javascript policy, then you can parse do a template there... Yes it would be nice if AssignMessage supported this, but not the case at the moment...  Or you can first extract all variables and then build your message like this:

<AssignMessage continueOnError="false" enabled="true" name="AM-SetResponse">
  <DisplayName>AM-SetResponse</DisplayName>
  <Properties/>
  <Set>
    <Payload contentType="application/json">
      {"userData":"{result.userData}", "developerData":"{result.developerData}"}
    </Payload>
  </Set>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignTo createNew="false" transport="http" type="response"/>
</AssignMessage>

Hi

I think you are saying the jsonpath is not giving you the results you expect. If that is the case, then I think you need to refer to the .content field in the response, in your jsonPath.

...
  <AssignVariable>
<Name>mesg-path</Name>
<Value>$.message</Value>
</AssignVariable>
<AssignVariable>
<Name>code-path</Name>
<Value>$.code</Value>
</AssignVariable>
<AssignVariable>
<Name>sco.err.msg</Name>
<Template>{jsonPath(mesg-path,ServiceCallout.response.content)}</Template> <!-- look here --> </AssignVariable> <AssignVariable>
<Name>sco.err.code</Name>
<Template>{jsonPath(code-path,ServiceCallout.response.content)}</Template> <!-- look here -->
</AssignVariable>
...

Some more explanation. You wrote:

This variable having value: {"code":"","message":"some error message"}

But that's not quite right. The ServiceCallout.response holds a MESSAGE Object, which itself holds headers, path, verb, response code, content.... You specifically want to evaluate a jsonPath on the content (response body) of that MESSAGE.

Let me know if this helps.

hi

thanks for response

I will check this and will try to update here.