Skip to main content

Modify Request Payload

  • Only requests triggered by XHR/fetch can be modified by the browser extension. For other type of requests, use Desktop App

Modifying the request payload is the process of changing the data sent to the server when making an HTTP request. You can use Modify Request Body rule to override the API request body with static data or programmatically modify the existing request payload.

Static Request Body Modification

In this mode, you can enter a static request body (JSON) you want to forward to the server.

Response Rule Static
  1. Source Condition: Source condition is where you set criteria for the rules. You can use URL, Host, or Path with Regex, Contains, Wildcard, or Equals to match the source request. Learn more about source conditions here.
  2. Static Request Body: Define the static request body which must be passed to the server.
  3. Source Filters: You can define better targeting conditions and restrict rules to apply on specific web pages (or domains), request types, request methods, or request payloads. Learn more about source filters here.

Programmatic Request Body Modification

The existing request body can be modified programmatically using JavaScript.

Response Rule - Programmatic

Programmatic Modification Script (JS) is where you write a JavaScript script that can modify the existing request body programmatically.

Arguments of modifyRequestBody

  1. method (string)- The HTTP method of the request. GET | POST | PUT | DELETE etc.
  2. url (string) - The request URL.
  3. body (string)- The original request body stringified:
  1. bodyAsJson (JSON object)- The original request body parsed into JSON object:

Return type of modifyRequestBody

You can return modified body as string or JSON object.

How to modify the body of a POST request.

We use to test this which echoes back the request.

  1. We make the following POST request.
const options = {
method: 'POST',
headers: {'content-type': 'application/json'},
body: '{"app":"requestly"}'

fetch('', options)
.then(response => response.json())
.then(response => console.log(response))
.catch(err => console.error(err));
  1. Create a Modify Request Body rule uses the following JavaScript. You can find the rule here.
function modifyRequestBody(args) {
const { method, url, body, bodyAsJson } = args;
// Change request body below depending upon request attributes received in args
let newBody;
if (method === "POST") {
newBody = bodyAsJson;
newBody["feature"] = "modify request";
return newBody;
  1. You can see the key feature being added to the request body when hoppscotch echoes back the request.
  • Primarily used in sending additional data in request payload to the API server: There might be situations where additional data needs to be sent in request payloads to the API server when making a POST or PUT request.
  • Modifying GraphQL Queries: GraphQL queries can be modified by modifying the request body of the request. This can be done by changing the query string or variables in the request body.
  • Testing different edge cases: You may modify an API request payload to include an invalid or unsupported field. The server will likely reject the API request and return an error message.


Request Rule not working

Rule might not be working for below reasons

  • Is not XHR/fetch request
    Only requests triggered by XHR/fetch can be modified by the browser extension due to technical constraints. For other type of requests, use Desktop App instead.