Add key-value in request header via Apigee

Not applicable

I'm using Apigee as a proxy server for backend API's. My problem statement is to add host ip in request header(Received from API consumer) and forward it to backend server.I'm accessing IP address using context variable "proxy.client.ip".How to add this value in header and pass it further.I have tried following solutions-

var contentIp = context.getVariable("proxy.client.ip");
context.setVariable("IpValue", contentIp);

It is showing value in variables,while debugging trace session.But how to add it in request headers.Thanks.

Solved Solved
0 5 1,914
1 ACCEPTED SOLUTION

@Kaushik Tanna , Welcome to Apigee Community.

Please use Assign Message Policy.

DO NOT reinvent the wheel by writing javascript policies when out of the box policies solves the problem.

You need to set request.header.headername variable to proxy.client.ip variable using assign message policy. Hope it helps.

View solution in original post

5 REPLIES 5

@Kaushik Tanna , Welcome to Apigee Community.

Please use Assign Message Policy.

DO NOT reinvent the wheel by writing javascript policies when out of the box policies solves the problem.

You need to set request.header.headername variable to proxy.client.ip variable using assign message policy. Hope it helps.

@Anil Sagar - Thanks a lot.Issue resolved. 🙂

Awesome, Keep us posted moving forward if any !

Hi,

I am new in APIGEE. As part of this, we need to add a header component "Authorization" with value with a header. When we do this in direct API it works but when we trying to give this through APIGEE its doesn't. we have added a header value using 'Assign message policy'. But the added header value is not getting in our end point.I have added like this.

<AssignMessage async="false" continueOnError="false" enabled="true" name="Assign-Message-1">
    <DisplayName>Assign Message-1</DisplayName>
    <AssignTo createNew="false" type="request"/>
    <Properties/>
    <Add>
        <Headers>
            <Header name="Authorization">abcd123</Header>
        </Headers>
        <Verb>POST</Verb>
    </Add>
    <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
</AssignMessage>

Where is THIS ^^ policy attached?

If you are only intending to set a header, why not use Set element (not Add) ?

Also if you intend to only set a header, why not remove the Verb element? I don't even think that's valid within an Add element.