How to use Extract variable using JSON payload with Assign Message policy

This is my JSON payload

 

{
    "correlationId": "ID:PRE002-EPIC-EMS-SERVER-1.60656218C00C1:2D862D279",
    "time": "2022-03-14T07:32:24.816Z",
    "eventType": "Activation",
    "serviceId": "test102@test.com"
}

 

Event type can be Activation or Deactivation

This is my Extract Variable Policy

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<ExtractVariables async="false" continueOnError="false" enabled="true" name="TBP-Notification">
    <DisplayName>TBP Notification</DisplayName>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <JSONPayload>
        <Variable name="eventType">
            <JSONPath>$.eventType</JSONPath>
        </Variable>
        <Variable name="serviceId">
            <JSONPath>$.serviceId</JSONPath>
        </Variable>
    </JSONPayload>
    <Source clearPayload="false">request</Source>
</ExtractVariables>

 

 
I want to return a response like this using Assign Message policy and message should be based from the extract variables depending on the payload if activation/deactivation

 

{
    "code": "*****",
    "method": "POST",
    "data": {
        "message": "test102@test.com has been set for activation"
    },
    "correlationId": "ID:PRE002-EPIC-EMS-SERVER-1.60656218C00C1:2D862D279",
    "time": "2022-03-14T18:32:19",
    "status": "200"
}

 

Anyone who can help me please, Thank you

 

0 3 300
3 REPLIES 3

Use AssignMessage and set the JSON Body,

Link to doc: 

 

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage async="false" continueOnError="false" enabled="true" name="AM-JSONBody">
    <DisplayName>AM-JSONBody</DisplayName>
    <Set>
        <Payload contentType="application/json" variablePrefix="$" variableSuffix="$">
            {
              "message" : "$eventType$ is set to $serviceId$"
            }
        </Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

 

Yes , and keep in mind the default variablePrefix and variableSuffix are curly braces. So this also works: 

<AssignMessage name="AM-JSONBody">
    <DisplayName>AM-JSONBody</DisplayName>
    <Set>
        <Payload contentType="application/json">{
              "message" : "{eventType} is set to {serviceId}"
}
</Payload>
    </Set>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

 

Thanks for the help @johnwilliams  & @dchiesa1 . Appreciate it