Adding a Timestamp Query Parameter with Hoppscotch Pre‑request Scripts
Learn how to use a Hoppscotch pre‑request script to automatically add a unique timestamp query parameter to every request, with setup steps, verification checks, and rollback tips.
28 Feb 2026, 01:21 UTC

Desired outcome
You want every request you send from Hoppscotch to include a unique timestamp query parameter (e.g., ?ts=1728394560000) so that caching layers or downstream services treat each call as distinct.
Prerequisites
- Hoppscotch installed (web app, desktop client, or self‑hosted instance) and accessible.
- A request already created (e.g., a GET to
https://httpbin.org/anything) that you will modify. - Basic familiarity with the Hoppscotch UI: request editor, tabs, and environment variables panel.
Focused procedure
- Open the request you wish to edit. In the request editor, locate the tabs beneath the main URL/body area and click the Pre‑request Script tab.
- In the script editor, paste the following JavaScript code. This script generates a millisecond‑precision timestamp, stores it in an environment variable named
timestamp, and then adds it as a query parameter to the request URL.// Generate timestamp const ts = Date.now(); // Save to environment (persists until cleared) pm.environment.set('timestamp', ts); // Add as query parameter pm.request.url.addQueryParam({ key: 'ts', value: ts.toString() }); - Click the Save button (or press Ctrl+S) to store the script with the request.
- Optional: Verify that the environment variable is set by opening the Environment sidebar, locating the current environment, and confirming that
timestampappears with a numeric value. - Send the request using the Send button. Before the request leaves Hoppscotch, the preview pane (usually below the editor) should show the URL with the added
?ts=…parameter. - After the response arrives, open the Console panel at the bottom of the UI. Ensure there are no red error messages; any console output you placed in the script (e.g.,
console.log('timestamp set', ts)) will appear here.
Expected checks
- Request preview: URL contains
?ts=<numeric value>where the value matches the millisecond timestamp generated byDate.now(). - Environment panel: variable
timestampholds the same numeric value. - Console: no uncaught exceptions; if you added a
console.logstatement, you see its output. - Response body (from httpbin): the
argsobject includes thetskey with the same value.
Recovery options
If you discover that the timestamp is causing unintended side effects (e.g., persisting across unrelated requests), you can:
- Clear the environment variable manually: open the Environment sidebar, hover over
timestamp, and click the × button to delete it. - Disable the pre‑request script temporarily: return to the Pre‑request Script tab, comment out or delete the
pm.environment.setline, then save. - Reset the environment entirely: from the Environment dropdown, choose Clear to remove all variables, then re‑add any you need.
Limitations and practical verification
The Hoppscotch sandbox provides a limited set of globals (console, setTimeout, fetch when enabled). Avoid importing large external libraries directly; if you need complex logic, bundle it into a single script or use the built‑in fetch to retrieve small JSON payloads.
To verify that the script runs on every request, send the same request twice in quick succession and compare the two ts values in the console or response; they should differ by a few milliseconds.
0 replies
A thoughtful contribution can make all the difference. Be the first to share one.