Apidog Docs
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
HomeLearning CenterSupport CenterAPI References
HomeLearning CenterSupport CenterAPI References
Discord Community
Slack Community
X / Twitter
πŸ‡ΊπŸ‡Έ English
  • πŸ‡ΊπŸ‡Έ English
  • πŸ‡―πŸ‡΅ ζ—₯本θͺž
  1. Test scenarios
  • Apidog Learning Center
  • Get started
    • Introduce Apidog
    • Basic concepts in Apidog
    • Navigating Apidog
    • Quick Start
      • Overview
      • Specify a new endpoint
      • Make a request to the endpoint
      • Add an assertion
      • Create a test scenario
      • Share your API documentation
      • Explore more
      • Send a request and save as an endpoint
    • Migration
      • Overview
      • Manual import
      • Scheduled import
      • Import options
      • Export data
      • Import from...
        • Import from Postman
        • Import OpenAPI (Swagger) spec
        • Import cURL
        • Import Markdowns
        • Import from Insomnia
        • Import from apiDoc
        • Import .har file
        • Import WSDL
  • Design APIs
    • Overview
    • Create a new API project
    • Endpoint basics
    • Components
    • Common fields
    • Global parameters
    • Endpoint change history
    • Batch endpoint management
    • Configure multiple request body examples
    • Schemas
      • Overview
      • Create a new schema
      • Build a schema
      • Generate Schemas from JSON etc.
    • Security schemes
      • Overview
      • Create a security scheme
      • Use the security scheme
      • Security scheme in online documentation
    • Advanced features
      • Custom endpoint fields
      • Import endpoints as test steps
      • Endpoint status
      • Appearance of parameter lists
      • Endpoint unique idenfication
  • Develop and Debug APIs
    • Overview
    • Generate requests
    • Send requests
    • Endpoint cases
    • Dynamic values
    • Validate responses
    • Design-first Mode & Request-first Mode
    • Generate code
    • Environments & variables
      • Overview
      • Using variables
      • Environments & services
    • Vault secrets
      • Overview
      • HashiCorp Vault
      • Azure Key Vault
      • AWS Secrets Manager
    • Pre/Post processors
      • Overview
      • Assertion
      • Extract variable
      • Wait
      • Database operations
        • Overview
        • MongoDB
        • Redis
        • Oracle Client
      • Using scripts
        • Overview
        • Postman scripts reference
        • Pre processor scripts
        • Post processor scripts
        • Public scripts
        • 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
    • Dynamic values Modules
  • Mock API data
    • Overview
    • Smart mock
    • Custom mock
    • Mock priority sequence
    • Mock scripts
    • Cloud mock
    • Self-hosted runner mock
    • Mock language (Locales)
  • Automated tests
    • Overview
    • Test reports
    • Test scenarios
      • Create a test scenario
      • Pass data between requests
      • Flow control conditions
      • Import endpoints/endpoint cases from other projects
      • Sync data from endpoints/endpoint cases
      • Export test scenarios
    • Run test scenarios
      • Run a test scenario
      • Data-driven testing
      • Run test scenarios in batch
      • Scheduled tasks
      • Manage the runtime environment of APIs from other projects
    • Test APIs
      • Integration testing
      • Performance testing
      • End-to-end testing
      • Regression testing
    • Apidog CLI
      • Overview
      • Installing and running Apidog CLI
      • Apidog CLI Options
    • CI/CD
      • Overview
      • Integrate with Jenkins
      • Integration with Gitlab
  • Publish API Docs
    • Overview
    • API Technologies Supported
    • Quick share
    • View the API documentation
    • Publish docs sites
    • Folder tree settings
    • Custom layouts
    • Visibility settings
    • Endpoint SEO settings
    • Custom domain
    • Embedding values in document URLs
    • Documentation Search
    • Integrating Google Analytics with Doc Sites
    • CORS Proxy
    • API Versions
      • Overview
      • Create API versions
      • Publish API versions
      • Share endpoints with API versions
  • Send requests
    • Overview
    • gRPC
    • Use request proxy agents for debugging
    • SOAP/WebService
    • GraphQL
    • WebSocket
    • Socket.IO
    • SSE debugging
    • Create requests
      • Request History
      • Request basics
      • Parameters and body
      • Request headers
      • Request settings
      • HTTP/2
    • 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
      • Save the request as an endpoint
  • Branches
    • Overview
    • Create a new sprint branch
    • Test APIs in a branch
    • Design API in a branch
    • Merge sprint branches
    • Manage sprint branches
  • Apidog MCP Server
    • Overview
    • Conntect API Specification within Apidog Project to AI via Apidog MCP Server
    • Conntect Online API Documentation Published by Apidog to AI via Apidog MCP Server
    • Conntect OpenAPI Files to AI via Apidog MCP Server
  • Best practices
    • How to handle API signatures
    • How to access OAuth 2.0 protected APIs
    • Apidog collaboration workflow
    • Managing authentication state in Apidog
  • Administration
    • Onboarding Checklist
      • Basic Concepts
      • Onboarding Guide
    • Managing Teams
      • Managing Teams
      • Managing Team Members
      • Member Roles & Permission Settings
      • Team Activities
      • Team Resources
        • General Runner
        • Team Variables
        • Request Proxy Agent
      • Real-time Collaborations
        • Team Collaboration
    • Managing Projects
      • Managing Projects
      • Managing Project Members
      • Notification Settings
      • Project Resources
        • Database Connection
    • Managing Organizations
      • Single Sign-On (SSO)
        • SSO Overview
        • Configure Microsoft Entra ID
        • Configure Okta
        • Configure SSO for an Organization
        • Managing user accounts
        • Mapping Groups to Teams
      • SCIM Provisioning
        • Intro to SCIM Provisioning
        • Microsoft Entra ID
        • Okta
      • Organization Resources
        • Self-hosted Runner
  • Billing
    • Overview
    • Credits
    • Unable to use credit cards?
    • Managing subscriptions
    • Upgrade plan
  • Data & Security
    • Where is Apidog's data stored, and how is data security ensured?
    • How is user data stored? Will this data be public? Or will it be private? Will all data be stored in the cloud?
    • When sending requests, do they go through the Apidog server? Is data security ensured?
  • Add-ons
    • API Hub
    • Apidog Intellij IDEA plugin
    • Browser Extension
      • Chrome
      • Microsoft Edge
    • Request Proxy
      • Request proxy in Apidog web
      • Request proxy in shared docs
      • Request proxy in Apidog client
  • Account & preferences
    • Language settings
    • Data backup
    • Network proxy configuration
    • Hot keys
    • Updating Apidog
    • Generate OpenAPI access token
    • Deleting account
    • Account settings
  • 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
  • Apidog Europe
    • Apidog Europe
  • Support Center
  1. Test scenarios

Pass data between requests

In automated testing scenarios, passing data between multiple requests is very common. Typical cases include:
Request 1 is a login request that returns a token; Request 2 uses this token to request other data.
Request 1 returns an ID; Request 2 performs operations based on this ID.
Request 1 returns a list; Request 2 uses data from this list.
For such scenarios, Apidog provides two different solutions to handle data passing between requests. You can choose the appropriate solution based on the specific problem at hand.
Retrieve pre-step data: This feature allows you to directly use data from preceding requests in subsequent requests.
The advantage is simplicity, without the need to introduce additional variables.
However, it may become slightly cumbersome when data needs to be referenced multiple times.
Retrieve pre-step data feature can be ONLY used in the "Tests" module and not in the "APIs" module.
Use variables: Add "Extract Variables" in the pre-processor of the preceding request to store the required data in a variable, and then call this variable in the subsequent requests.
The advantage is convenience when referencing data multiple times, but it may be slightly more complex for single references.
Variables can be used both in "Tests" module and "APIs" module.

Retrieve pre-step data#

Let's consider a scenario where Request 1 is a login request that returns a token, and Request 2 uses this token to request additional data.
1
Add the login request (Request 1) to the test scenario.
2
Add the query request (Request 2) to the test scenario.
3
The query parameter for Request 2 needs to include the token returned by Request 1. Click on the "magic wand" icon πŸͺ„ in the token field in the query parameters of Request 2 and select "Retrieve pre-step data".
4
Choose Request 1 for data retrieval, select the response body, and use JSONPath to extract the token returned by Request 1, like $.token.
5
Click Insert, and you'll see {{$.2.response.body.token}} inserted as the query param.
6
Click the "Run" button in the Test scenario to successfully pass the data from Request 1 to Request 2.
The feature of "Retrieve pre-step data" is ONLY AVAILABLE in the "Tests" module and not in the "APIs" module.
When using "Retrieve pre-step data", the value can ONLY be obtained when the entire test scenario is run together; it cannot be accessed when running individual steps.

Referencing pre-step data using variable syntax#

Using the example of {{$.2.response.body.token}} from the previous text:
'2' represents the step ID, which can be found in each test step.
'response.body' indicates the position of the data from the pre-step. This can include data from the request's header, body, or the response's header or body, among others. See below for specifics.
'token' represents the 'token' data at the next level within the body. You can use JSONPath syntax to extract the desired data.
Pre-step data can be utilized in various parts of the request, such as request parameters, headers, authentication, and more. You can also directly insert the data into the request body, as shown below.
It's important to note that if you need to use pre-step data in your scripts, you cannot directly reference variables using {{variable}} syntax. Instead, you should use pm.variables.get to reference pre-step data. For example:

Syntax reference#

Category Function Syntax Example
RequestURL{{$.<step id>.request.url}}
Path parameter{{$.<step id>.request.pathParam.<field name>}}
Query{{$.<step id>.request.query.<field name>}}
Header{{$.<step id>.request.header.<field name>}}
Body (form){{$.<step id>.request.body.<field name>}}
Body (json){{$.<step id>.request.body.<field path>}}
ResponseBody{{$.<step id>.response.body.<field path>}}
Header{{$.<step id>.response.header.<field name>}}
Cookie{{$.<step id>.response.cookie.<field name>}}
LoopElement (array element in ForEach loop){{$.<loop step id>.element.<field path>}}
Index{{$.<loop step id>.index}}

Use variables to pass data#

Let's consider a scenario where Request 1 is a login request that returns a token, and Request 2 uses this token to request additional data.
1
Add the login request (Request 1) to the test scenario.
2
In the post processors of Request 1, add an "Extract Variable" action to extract $.token as {{token}}.
Learn more about Extract variable.
3
Add the query request (Request 2) to the test scenario.
4
Reference the variable {{token}} in the query parameters of Request 2.
5
Click the "Run" button in the Test scenario to successfully pass the data from Request 1 to Request 2.

FAQ#

Q: Why am I not able to successfully reference pre-step data?
A: Firstly, make sure you're now in "Tests" module. "Referencing pre-step data" feature is available only in Tests module but not APIs module.
If you're now surely in Tests module, switch to the "Actual Request" tab to confirm whether the pre-step data referenced in the request has been successfully incorporated.
If the reference in the actual request still appears as {{$.n.response.body.abc}} instead of showing actual data, it indicates that the reference has not been applied.
In this case, consider the following common reasons:
1.
Have you run the entire test scenario instead of just a single step? Referencing pre-step data requires running the complete test scenario for it to take effect.
2.
Verify if the step ID is correct and corresponds to the step you intend to reference.
3.
Ensure that the JSONPath used matches the data source accurately.
Previous
Create a test scenario
Next
Flow control conditions
Built with