How to modify json payload request and add new json parameter from KVM.

Not applicable

How to modify json payload request and add new json parameter from KVM (or generate unique number to add to json payload) request. Is it possible without javascript policy by using extract variable and assign message policies.

I need to increment the KVM value and put into KVM after adding to JSON request payload. Any ideas ?

0 2 3,247
2 REPLIES 2

adas
New Member
@Venkateswarlu Pesala

For such cases, I usually do something like this:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<AssignMessage name="AssignRequestPayload">
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
    <Set>
        <Payload contentType="application/json" variablePrefix="#" variableSuffix="$">
{"amountTransaction": {
    "clientCorrelator": "#apigee.client_id$",
    "endUserId": "#request.header.Authorization$",
    "paymentAmount": {
        "chargingInformation": {
            "amount": 10,
            "currency": "USD",
            "description": "#apigee.developer.app.name$"
        },
        "totalAmountCharged": "$10"
    },
    "referenceCode": "REF-#messageid$",
    "serverReferenceCode": "SRF-#messageid$",
    "resourceURL": "http://example.com/1/payment/#messageid$",
    "transactionOperationStatus": "Charged"
}}</Payload>
    </Set>
<AssignTo createNew="false" transport="http" type="request">targetRequest</AssignTo>
</AssignMessage>

In the above case messageid variable is the unique id that I am appending to the request payload using an assign message policy.

Hi @Arghya, Thanks for your response.

"referenceCode": "REF-#messageid$", is returning messageid but without REF prefix. "referenceCode": "#messageid$",

 "clientCorrelator": "#apigee.client_id$", is not returning any value. I tried multiple ways by providing #req.client_id$ and #request.client_id$ etc.

can you please tell me is it working for you ?