Set HTTP Header

Template ID: setheader

Assigns a value to an existing response or request header. Also, the template can add a new response or request header. This template is available in Power Apps and Power Automate.

The target use case for this policy template is to override or add information to an HTTP request or response.

Examples

Let’s look at some examples that use the following parameters.

headers: test=foo

connectionParameters: cat=bar

Header NameHeader ValueResulting Header
test@headers('test')mootest=foomoo
testmoo@headers('test')test=moofoo
cat@connectionParameters(‘cat’, ‘’)test=foo; cat=bar
name@connectionParameters(‘name’, ‘’)test=foo; name=""

Examples from open-sourced connectors

We have multiple instances of this template being used in our open-sourced connectors repository and here are a few of them.

ConnectorScenario
GetAcceptHTTP header in the response is overriden by a new static value
PeltarionHTTP header in the request is overridden by the static value application/json, which is a common scenario
OpenText ContentServerHTTP header in the request is overridden by the end user’s connection’s settings

Input Parameters

Name Key Required Type Description
Header name x-ms-apimTemplateParameter.name True String Specifies the name of the header to be set.
Header value x-ms-apimTemplateParameter.value True String Specifies the value of the header to be set.
Action if header exists x-ms-apimTemplateParameter.existsAction Enum Specifies what action to take when the header is already specified
- override: Replaces existing value with the value from policy template.
- skip: Existing value isn't replaced with the value from policy template.
- append: Appends the value from policy template to existing value.
Run policy on x-ms-apimTemplate-policySection True Enum Specifies when to run this policy
- Request: Policy template will run before request is sent to the backend API.
- Response: Policy will run after receiving response from the backend API.
- Failure: Policy template will run only when call to the backend API fails.
Operations x-ms-apimTemplate-operationName Array Policy will run on the selected list of actions and triggers. If no operation is selected, this policy will apply to all operations.