Quickstart
What made this section unhelpful for you?
On this page
- Quickstart
API Import
What made this section unhelpful for you?
On this page
- API Import
Other Docs & User Guides
What made this section unhelpful for you?
On this page
- Other Docs & User Guides
Themes & Templates
What made this section unhelpful for you?
On this page
- Themes & Templates
Migration
What made this section unhelpful for you?
On this page
- Migration
Markdown support
What made this section unhelpful for you?
On this page
- Markdown support
API Specs & Supported Formats
On this page
- API Specs & Supported Formats
API Testing
What made this section unhelpful for you?
On this page
- API Testing
Pre-Request Scripting
Pre-Request Scripts allow you to execute code before each HTTP request, making them ideal for tasks such as authentication, request headers manipulation, and setting up a consistent environment before fetching data from an external API. By incorporating pre-request scripts, you can streamline your request handling process and ensure consistent behavior across various endpoints.
1.Reading Environment Variables
You can access environment variables using the following syntax:
const myVariable = theneo.variables["variable-name"];2. Reading Endpoints
To retrieve endpoints, use the following code:
const myEndpoint = theneo.endpoints;3. Reading Parameters
Access parameters in your pre-request script using:
const myParameter = theneo.parameters;4. Reading Query Parameters
To access query parameters, use the following syntax:
const myQueryParameter = theneo.queryParameters;5. Reading Header Variables
Header variables can be accessed as follows:
const myHeader = theneo.headers["header-name"];6. Setting Header Values
You can modify or set new header values with the following command:
theneo.headers["header-name"] = "header value";7. Reading Request Body
To access the request body in JSON format, use:
const requestBody = theneo.requestBody.json;8. Sending Requests within Pre-Request Scripts
You can send requests to other endpoints using the fetch API or similar methods. For instance, setting an Authorization header might look like this:
const token = theneo.variables["authToken"];
theneo.headers["Authorization"] = Bearer ${token};9. Example Script
Here’s a complete example of a pre-request 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);Available Libraries
Running Your Script
Reading External Query Parameters
To authenticate users in your API explorer by reading and using externally passed query parameters, such as ?my_token=<token>and utilizing them in the pre-request script context.
Steps to Implement
Setting up a Dynamic Base URL in API Explorer
The goal is to allow users to overwrite the default base URL from the API Explorer with a custom base URL set through a new field. This enables requests to be sent to a dynamic base URL specified by the user instead of a predetermined one.
What made this section unhelpful for you?
On this page
- Pre-Request Scripting
API Authentication
What made this section unhelpful for you?
On this page
- API Authentication
API Versioning
What made this section unhelpful for you?
On this page
- API Versioning
API Changelog
What made this section unhelpful for you?
On this page
- API Changelog
Web Editor Widgets
On this page
- Web Editor Widgets
API Management inside the editor
What made this section unhelpful for you?
On this page
- API Management inside the editor
Live Collaboration
What made this section unhelpful for you?
On this page
- Live Collaboration
Preview Changes
What made this section unhelpful for you?
On this page
- Preview Changes
Publish a Documentation
What made this section unhelpful for you?
On this page
- Publish a Documentation
Branding & Styling
What made this section unhelpful for you?
On this page
- Branding & Styling
Custom Domain
What made this section unhelpful for you?
On this page
- Custom Domain
Feedback & Analytics
What made this section unhelpful for you?
On this page
- Feedback & Analytics
Theneo UI
What made this section unhelpful for you?
On this page
- Theneo UI
Github Actions
What made this section unhelpful for you?
On this page
- Github Actions
Visual Studio Code Extension
What made this section unhelpful for you?
On this page
- Visual Studio Code Extension
Theneo CLI
What made this section unhelpful for you?
On this page
- Theneo CLI
Theneo SDK
What made this section unhelpful for you?
On this page
- Theneo SDK
Postman Sync
What made this section unhelpful for you?
On this page
- Postman Sync
GitLab Sync
What made this section unhelpful for you?
On this page
- GitLab Sync
Bitbucket
On this page
- Bitbucket
AI Co-Pilot
What made this section unhelpful for you?
On this page
- AI Co-Pilot
AI Search
What made this section unhelpful for you?
On this page
- AI Search
AI Chatbot
What made this section unhelpful for you?
On this page
- AI Chatbot
AI Export
What made this section unhelpful for you?
On this page
- AI Export
Templates
What made this section unhelpful for you?
On this page
- Templates
Custom Design
What made this section unhelpful for you?
On this page
- Custom Design
Developer Portal Editor
What made this section unhelpful for you?
On this page
- Developer Portal Editor
Export / Import Code
What made this section unhelpful for you?
On this page
- Export / Import Code
Developer Portal Dashboard & Page Management
What made this section unhelpful for you?
On this page
- Developer Portal Dashboard & Page Management
Project Management
On this page
- Project Management
Workspace Configuration
On this page
- Workspace Configuration