When receiving a request on API Connect I want to add a header to the subsequent call that it makes to my backend, I've tried using the set-variable policy like so:
execute:
- set-variable:
title: SetCustomHeader
actions:
- value: xxx
set: X-HEADER-NAME
And using the Gateway Script:
- gatewayscript:
title: gatewayscript
version: 1.0.0
source: 'apim.setvariable(''X-HEADER-NAME'', ''xxx'');'
I've tried having the action as either set or add, and I've tried setting the variable name as just the name of the header, and message.headers.X-HEADER-NAME.
According to questions like this one, as well as IBM documentation either one should work, but when logging the request headers on my backend I still don't see the header.
What am I missing?
You need to mention the apim context variables in order to make api connect understand that you want to set the header value. so the value will be :
Where "name" is the name of the header and "value" is the value of header to be set.
You can find all the api connect context variables here : https://www.ibm.com/docs/en/api-connect/10.0.x?topic=reference-api-connect-context-variables