This step sets the request body for the next POST, PUT, or PATCH request using a JSON string written directly in the Gherkin step. The string is enclosed in single quotes rather than double quotes, allowing double quotes inside the JSON payload without escaping conflicts. Placeholder tokens are expanded before the string is parsed, so dynamic values such as {{userId}} can appear inside the JSON. If the resulting string is not valid JSON, the step fails immediately with a descriptive message.
The body is parsed into a JavaScript object and passed as the request data. Use this step for compact, single-line payloads. For multi-field bodies that benefit from a table layout, see the table-based body step. The request body is reset before each scenario along with all other API state.
Accepted phrasings
Given I set the request body to '{"key": "value"}'
Given we set the request body to '{"key": "value"}'
Given the request body is '{"key": "value"}'
Examples
Given I set the request body to '{"name": "John", "email": "john@example.org"}'
Given the request body is '{"title": "Test Post", "body": "This is a test"}'
Given I set the request body to '{"id": 1, "tags": ["qa","api"]}'
Given we set the request body to '{"status": "published"}'
In a real scenario
Scenario: Create a new record via the API
Given the API base URL is "https://api.example.org/v1"
And I set the following headers:
| Content-Type | application/json |
| Accept | application/json |
And I set the request body to '{"name": "Alice", "email": "alice@example.org", "active": true}'
When I send a POST request to "/users"
Then the API response code should be 201
And the API response should contain "alice@example.org"