Need to add a custom key value (clientCode=ABC) in request header to target server.

Hi, We have a requirement where we need to pass a custom value in the Header say clientCode=ABC when we invoke the APIGEE proxy. We added a AssignMessage policy as below :-

<AssignMessage async="false" continueOnError="false" enabled="true"
               name="set-client-code">
  <DisplayName>Set Client Code</DisplayName>
  <Set>
    <Headers>
      <Header name="clientCode">ABC</Header>
    </Headers>
  </Set>
  <IgnoreUnresolvedVariables>true</IgnoreUnresolvedVariables>
  <AssignTo createNew="false" transport="http" type="request"/>
</AssignMessage>

This policy as added to the flow as below

  <PostFlow name="PostFlow">
    <Request>
      <Step> <Name>set-client-code</Name> </Step>
    </Request>
    <Response/>
  </PostFlow>

However the custom header is not getting added. Can someone please let me know on how to proceed ?

1 2 150
2 REPLIES 2

There is nothing wrong with the policy config.

How are you determining that the header is not getting added?

Can you check and provide the Trace sessions?

BTW where do you want to add the header in request or response?

@Mahesh Raj,

Have you tried using the <Add> option instead of the <Set>?

<Set> allows you to update existing headers, while <Add> allows you to create new headers.

Check this link: https://docs.apigee.com/api-platform/reference/policies/assign-message-policy#set

<Set>

Sets information in the request or response message, which is specified by the <AssignTo> element. <Set> overwrites headers or parameters that already exist in the original message. To create a new header or parameter, use the <Add> element instead.