Clean request body

Hi Apigee Community,

I want to make sure that only a select number of fields from the request body are sent to the target server. I wanted a solution that is both light and easy to maintain, preferably with the allowed fields definition centralized on only one location.

Example:

Allowed fields = [name, surname, date_of_birth]

request.content = {
	name,
	surname,
	age
}

would turn into:

request.content = {
	name,
	surname
}

What are the best solutions for this?

Thank you in advance.

Solved Solved
0 2 786
1 ACCEPTED SOLUTION

You could use Javascript policy to modify the request payload.

Please see: https://community.apigee.com/questions/45357/how-to-modify-existing-value-in-json-payload-body.html

Or possibly use AssignMessage policy.

Please see: https://community.apigee.com/questions/64140/how-can-we-perform-json-to-json-transformation-usi.html

Regarding "easy to maintain" and "fields definition centralized" , I would suggest:

  • Storing the fields in a KVM, and using KeyValueMapOperations policy to copy the values into a flow variable before transforming the request content. If you do use a KVM, you might be better off using the Javascript policy solution mentioned above, as you could use Javascript to split a string list (of the JSON fields you are interested in) read out from a KVM value.
  • Doing all of the above in a SharedFlow - if this operation will be be used in multiple proxies. Please see: https://docs.apigee.com/api-platform/fundamentals/shared-flows

View solution in original post

2 REPLIES 2

You could use Javascript policy to modify the request payload.

Please see: https://community.apigee.com/questions/45357/how-to-modify-existing-value-in-json-payload-body.html

Or possibly use AssignMessage policy.

Please see: https://community.apigee.com/questions/64140/how-can-we-perform-json-to-json-transformation-usi.html

Regarding "easy to maintain" and "fields definition centralized" , I would suggest:

  • Storing the fields in a KVM, and using KeyValueMapOperations policy to copy the values into a flow variable before transforming the request content. If you do use a KVM, you might be better off using the Javascript policy solution mentioned above, as you could use Javascript to split a string list (of the JSON fields you are interested in) read out from a KVM value.
  • Doing all of the above in a SharedFlow - if this operation will be be used in multiple proxies. Please see: https://docs.apigee.com/api-platform/fundamentals/shared-flows

Not applicable

Allowed fields can be stored in KVM. Then using KVM policy you can extract the allowed fields. Using a javascript the condition can be checked and extra content parameters can be deleted.