Pre-Request Scripting
Pre-Request Scripts run code before each request — for authentication, headers, and setup.
1. Read environment variables
const myVariable = theneo.variables["variable-name"];
2. Read endpoints
const myEndpoint = theneo.endpoints;
3. Read parameters
const myParameter = theneo.parameters;
4. Read query parameters
const myQueryParameter = theneo.queryParameters;
5. Read header variables
const myHeader = theneo.headers["header-name"];
6. Set header values
theneo.headers["header-name"] = "header value";
7. Read the request body
const requestBody = theneo.requestBody.json;
8. Send requests within a pre-request script
You can call other endpoints using the Fetch API or similar. For example, setting an Authorization header:
const token = theneo.variables["authToken"];
theneo.headers["Authorization"] = `Bearer ${token}`;
9. Full example
A complete script that generates an HMAC signature and sets custom headers:
const apiKey = theneo.variables["apiKey"];
const apiSecret = theneo.variables["apiSecretKey"];
const timestamp = new Date().getTime();
console.log("API Key:", apiKey);
console.log("API Secret:", apiSecret);
console.log("Timestamp:", timestamp);
const requestData = JSON.stringify(theneo.requestBody.json);
const rawSignature = `${apiKey}:${timestamp}:${requestData}`;
function generateHMAC(rawSignature, secret) {
const signature = CryptoJS.HmacSHA256(rawSignature, secret);
return CryptoJS.enc.Hex.stringify(signature);
}
const signature = generateHMAC(rawSignature, apiSecret);
theneo.headers = {
"API-Key": apiKey,
"Timestamp": timestamp.toString(),
"Signature": signature,
"Content-Type": "application/json",
"Accept": "*/*"
};
console.log("Headers set for request:", theneo.headers);
Async operations are currently limited.
Available libraries
Currently, only the crypto library is available, and you can use any method it provides. To request an additional library, contact our support team at hello@theneo.io.
Running your script
1
Enable pre-request scripts
Go to Settings → Features → Pre-request script in your project.
2
Run your script
In the API Explorer, press Run Request. The pre-request script runs first, followed by your regular request.
3
Verify
Use the Network tab to confirm the correct authorization values are sent — verifying your script works as expected.
Reading external query parameters
To authenticate users in the API Explorer using externally passed query parameters (such as ?my_token=):
1
Pass query parameters
When redirecting users from your site to the API Explorer, include the token in the URL:
https://api-explorer.yoursite.com?myToken=<token>2
Use the token in your script
Modify the pre-request script to read the token from local storage and use it as needed.
Dynamic base URL in the API Explorer
Let users override the default base URL from the API Explorer with their own:
1
Write the pre-request script
Add this line to your Pre-request Script:
theneo.baseUrl = theneo.variables["baseURL"];
This takes the value entered in the baseURL field and assigns it to theneo.baseUrl, setting a dynamic base URL for the request.
2
Enter the base URL in the Explorer
- Reopen the API Explorer; a new
baseURL
field is created automatically based on your configuration. * Enter the custom base URL you want to use.
3
Send requests
All requests from the Explorer now use your custom base URL instead of the default — send to any dynamic endpoint simply by entering its base URL.
On this page
- Pre-Request Scripting