Given I set header "Header-Name" with value "Some-Value"

This step sets a single HTTP request header by name and value. The header is stored and applied to all subsequent requests in the scenario. If any placeholder tokens such as {{token}} appear in the value, they are replaced with their registered values before the header is stored. Setting the same header name a second time overwrites the previous value.

Use this step when you need to inject a single header such as Content-Type, Accept, or a custom API key. For Bearer token authentication, supply the full value including the scheme, for example Bearer eyJhbGc.... To set multiple headers at once, prefer the table-based step. The I and we subject forms are interchangeable.

Accepted phrasings

Given I set header "Header-Name" with value "some-value"
Given we set header "Header-Name" with value "some-value"
Given set header "Header-Name" with value "some-value"

Examples

Given I set header "Content-Type" with value "application/json"
Given I set header "Authorization" with value "Bearer token123"
Given we set header "X-Api-Key" with value "abcd-1234"
Given I set header "Accept" with value "application/xml"

In a real scenario

Scenario: API returns JSON when Accept header is set correctly
  Given the API base URL is "https://api.example.org/v1"
  And I set header "Accept" with value "application/json"
  And I set header "X-Api-Key" with value "key-abc-123"
  When I send a GET request to "/products"
  Then the API response code should be 200
  And the API response should contain "id"

Related steps

Back to Api Steps