Assign a value read from KVM to a header name

Not applicable

Hi Apigee Community,

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"):

<Headers>
            <Header name="{errorMessage.headerName}">{errorMessage.headerValue}</Header>
</Headers>

Instead of:

<Headers>
            <Header name="headerName">{errorMessage.headerValue}</Header>
</Headers>

Thanks in advance for any help you might provide,

Ula

Solved Solved
0 4 1,136
1 ACCEPTED SOLUTION

Great Question @Ula ,

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"));

Hope it helps.

View solution in original post

4 REPLIES 4

Great Question @Ula ,

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"));

Hope it helps.

@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...

@Ula , Glad it's helpful. Yep, We will keep you posted if any updates related to same in future.

@Anil Sagar Has there been any update on this? I checked the documentation and I couldn't still find a way to achieve this without using a JS policy.