Apicat Docs
  1. Script examples
Apicat Docs
  • What is Apicat?
  • Send requests
    • Create requests
      • Request basics
      • Parameters and body
      • Request headers
      • Request settings
      • Dynamic values
      • HTTP/2
      • SOAP/WebService
    • Authentication and authorization
      • Overview
      • CA and client certificates
      • Authorization types supported by Apidog
      • Digest Auth
      • OAuth 1.0
      • OAuth 2.0
      • Hawk Authentication
      • Kerberos
      • NTLM
      • Akamai EdgeGrid
    • Response and cookies
      • Overview
      • API response in Apidog
      • Create and send cookies
      • Debug requests
    • Dynamic values Modules
      • Airline
      • Animal
      • Color
      • Commerce
      • Company
      • Database
      • Datatype
      • Date
      • Finance
      • Food
      • Git
      • Hacker
      • Helpers
      • Image
      • Internet
      • Location
      • Lorem
      • Music
      • Number
      • Person
      • Phone
      • Science
      • String
      • System
      • Vehicle
      • Word
  • Environments & variables
    • Overview
    • Using variables
    • Environments & services
  • Pre/Post processors
    • Overview
    • Assertion
    • Extract variable
    • Wait
    • Database operations
      • Overview
      • MySQL
      • MongoDB
      • Redis
      • Oracle Client
    • Using scripts
      • Overview
      • Pre processor scripts
      • Post processor scripts
      • Public scripts
      • Postman scripts reference
      • Calling other programming languages
      • Using JS libraries
      • Visualizing responses
      • Script examples
        • Assertion scripts
        • Using variables in scripts
        • Using scripts to modify request messages
        • Other examples
  • Best practices
    • How to handle API signatures
    • How to access OAuth 2.0 protected APIs
    • Apidog collaboration workflow
    • Managing authentication state in Apidog
  • Account & preferences
    • Account settings
    • Generate OpenAPI access token
    • Language settings
    • Hot keys
    • Network proxy configuration
    • Data backup
    • Updating Apidog
    • Deleting account
    • Experimental Features
  • References
    • API-Design First Approach
    • Apidog OpenAPI/Swagger Specificaiton Extensions
    • JSONPath
    • XPath
    • Regular Expressions
    • JSON Schema
    • CSV File Format
    • Install Java Environment
    • Runner deployment environment
    • Apidog flavored Markdown
  1. Script examples

Using scripts to modify request messages

You can use pm.request to read or modify request messages.
You can use scripts to get all request parameters, but you can only use scripts to modify header and query parameters.
Modifying header and query parameters are only valid in preprocessor scripts, not in postprocessor scripts.
Using scripts to get API parameters: if the parameter contains a variable, it will not be replaced with the corresponding value. You need to use the pm.variables.replaceIn to get the actual value.
// pm.variables.replaceIn: handling variables in parameters
var body = pm.variables.replaceIn(pm.request.body.raw);
var jsonData = JSON.parse(body);
TIP
In Apidog pre processors, there is a Built-In preprocessor named Variable Substitution, which replaces all variables (including dynamic variables) in the request with the actual value.
Scripts like set variable need to be placed before Variable Substitution so that the variable can be set successfully.
Scripts like API signature need to be dragged after Variable Substitution to get actual values of the parameters.

URL related information#

Header parameters#

Get header parameters
Modifying Header Parameters

Query parameters#

Get query parameters
Modifying Query Parameters

Body parameters#

Body parameters come from pm.request.body which is a RequestBody instance.
View more details here.
TIP
We recommend referencing variables in the Body to modify body data. You can modify the value of the corresponding variable in preprocessor scripts.
We support direct modification of body parameters in Apidog version 1.4.16 or later. See example of how to use it below:
var body = pm.request.body.toJSON();
console.log("body object", body);

var bodyStr = body.raw;
console.log("body string", bodyStr);

var bodyJSON = JSON.parse(bodyStr);
bodyJSON.id = 100;
pm.request.body.update(JSON.stringify(bodyJSON, null, 2));
console.log("Modified body", pm.request.body.toJSON());

1. Body Type: form-data#

Get form-data info.

2. Body Type: x-www-form-urlencode#

Get x-www-form-urlencode info.

3. Body Type: JSON#

Get JSON info.

4. Body Type: raw#

Get raw info.
Modified at 2025-06-25 07:57:16
Previous
Using variables in scripts
Next
Other examples
Built with