Can we append new field into request payload in Service callout?

I have a request with payload and i need to append new attribute into the existing payload("request.content") before hitting the backend. Is it possible to do that via Service callout? Tried the same using Js and got the expected payload.But looking for precompiled policy to do that. any help?

Sample

Original request payload

{"attribute1":"Value1"}



Expected request payload

{"attribute1":"Value1","attribute2":"Value2"}

Thanks

Maivizhi A

0 6 722
6 REPLIES 6

@maivizhi , I don't think you can manipulate the payload using policies other than extension policies like JS / Python / java callouts. I don't think there is a precompiled policy just to do that. You need to use JS / Python / Java policies to do same.

Is there a reason you would prefer to use something other than the JavaScript policy? It's well-suited for manipulating json as you need.

@Carlos Eberhardt As service callout policy allows to add additional queryparam to the request before hitting the target ,i tried the same for request content too. Now , am clear that it can't be done.Thanks @Anil Sagar and @Carlos Eberhardt.

can you send the code?

Thanks

@maivizhi

This can be done. First, you would use an Extract Variables Policy to get the attribute1 and then use an Assign Message Policy to change the body of the payload to be what you want it to be or assign the request directly in Service Callout Policy in the payload section.

But the suggested method is using JS/Java callout/Python.

can you provide a sample code for that?