How to override API request body using Javascript
Rohan Mathur
February 17, 2025
1MIN READ
Learn how to override API request bodies using Javascript for testing and development. Use Requestly to easily modify request payloads

Introduction
Overriding HTTP request payload is a process of updating the request data/body sent by client to your API server. We can achieve this by using Requestly’s Modify Request body rule.
Use-cases
- 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.
- 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 payload 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.
Overriding HTTP request payload using Javascript
Let’s see an example for modifying API request body on https://www.agoda.com/en-in/.
- Install the browser extension.
- Goto Requestly and create a new Modify Request Body rule.
Screen Recording 2023-12-13 at 2.01.08 PM.mov - Specify the URL condition and enter
/GetTopDestinations
. - Select Programmatic (JavaScript) option to modify the request body using JavaScript code. Update the
requestType
for top destinations request from “International” to “Domestic”.
How to test if the request body was modified?
There are multiple ways to validate when a rule is successfully applied on a page. You can check out the documentation here.
To check whether the request body is modified, you can also inspect the HTTP request body in Chrome DevTools. You should see the overridden body is sent to the server.
Learn more
Written by
Rohan Mathur
Rohan has been a valuable member of our team as a frontend developer for the past year. His expertise in modern web technologies and commitment to crafting user-friendly interfaces have significantly contributed to our projects. Rohan’s collaborative approach and problem-solving skills have made him a key player in developing innovative web solutions.
Contents
Subscribe for latest updates
Share this article
Related posts

How to use access token from another API response
Learn how to capture, store, and reuse API authentication tokens in Requestly. Simplify authentication by using environment variables and collection authorization.
Dinesh Thakur
February 24, 2025

Organized 125k APIs and improved productivity by 20% using the Requestly API Client: Cyrisma
Cyrisma improved API management with Requestly’s API client, boosting security, reducing errors, and accelerating development. Learn how they did it
Sagar Soni
February 19, 2025
How to Test FastAPI Efficiently with Requestly API Client
Learn how to test FastAPI APIs with Requestly API Client for easy debugging, request modifications, and automation. Take control over your API testing workflow!
Dinesh Thakur
February 13, 2025