I’m successfully reading values from the KVMs (using standard Key Value Maps Operations Policy)**. Then I’m using these values to create customised error messages with Assign Message Policy. Everything works fine except when I try to replace the name value of the header with a name retrieved from a KVM.
My question: Is it possible to assign a header name value instead of just typing it in?
Ex. to somehow have this (in the example below, header value is read correctly, while header name is read as a string “errorMessage.headerName”):
As far as I know, not every place Apigee policies support dynamic variables. Yep, It’s strange. I believe that’s the way system is designed as of today. I have posted a similar question in community sometime back that you can find here.
Coming to your question, I don’t think AssignMessagepolicy supports dynamic header naming. As a workaround, you can use a javascript policy with code like below,
var headerName = context.getVariable("errorMessage.headerName");
context.setVariable('request.header.' + headerName, context.getVariable("errorMessage.headerValue"));
@Anil Sagar, thanks a lot for your answer! It’s indeed very strange, but definitely good to know. I wonder whether there are any plans to improve it in the future…