Register today for Oracle CloudWorld. October 17th - 20th, Las Vegas

Register now

Hillel Cooperman, Senior VP of User Experience Design, has a message for you on Oracle CloudWorld

Watch now
Modify field JSON Payload Groovy — Cloud Customer Connect
You're almost there! Please answer a few more questions for access to the Applications content. Complete registration
Interested in joining? Complete your registration by providing Areas of Interest here. Register

Modify field JSON Payload Groovy

Accepted answer
3
Views
1
Comments
edited Aug 10, 2021 3:35PM in API Management 1 comment

Content

Hi Gurus,

I am trying to modify one field of the JSON Payload I am receiving as an Input with a Groovy Policy.

For example, I receive this:

{

"field1": "value1",

"field2": "value2"

}

And I need to send this:

{

"field1": "value1",

"field2": "1234"

}

 

I've found this link:

https://github.com/anishi1222/api-groovy/blob/master/apip/ModifyMessageInRequestPipeline.groovy

def body = context.ApiRequest.getBody()
body.asJSONObject().put("field2", "1234")

def length = body.asString().length().toString()

context.ServiceRequest.setBody(body).setHeader("Content-Length",length)

 

but it is not working. Am I doing something worng?

Thanks in advance!

 

 

Tagged:

Howdy, Stranger!

Log In

To view full details, sign in.

Register

Don't have an account? Click here to get started!