Apidog Docs
🇺🇸 English
  • 🇺🇸 English
  • 🇯🇵 日本語
HomeLearning CenterSupport CenterAPI References
HomeLearning CenterSupport CenterAPI References
Discord Community
Slack Community
X / Twitter
🇺🇸 English
  • 🇺🇸 English
  • 🇯🇵 日本語
  1. Automated tests
  • Back to home
  • Support Center
  • Apidog Support Center
  • Import/Export
    • How to import API data into Apidog?
    • How to import cURL in Apidog?
    • How to migrate Postman environments to Apidog?
    • How to auto - group endpoints on Swagger/OpenAPI import?
  • Sending requests
    • Does Apidog support Socket.IO?
    • Why is the "+" in the parameter value decoded as a space?
    • How to send a request in Apidog?
    • How to send a graphQL request in Apidog?
    • How to send a gRPC request in Apidog?
    • How to send a SOAP/WebService request in Apidog?
    • How to send a WebSocket request in Apidog?
    • Does Apidog support pre-request/test scripts and assertions in WebSocket APIs?
    • How to send a SSE request in Apidog?
    • How to add default headers at the folder level?
    • Does Apidog support pre-request/test scripts and assertions in gRPC APIs?
    • Why am I getting a "socket hang up" error when sending a request?
    • ELANREFUSED.DNS Resolver Error
  • Designing APIs
    • How do I use variables in the path?
    • Can I use a response component as the default response?
    • How to check who has modified an endpoint?
    • How can I bulk delete endpoint folders in Apidog?
    • How can I bulk add/remove prefixes to the path of endpoints?
    • How to move a Property's level in the Schema Editor?
    • If a string property has multiple enumerated values and is used in various locations, how can this enum be consistently referenced throughout?
    • How to get Apidog resource folder ID?
    • How do I get the resource floder ID of Apidog?
    • How do I use variables in a URL path?
    • What should I do if an endpoint, document, or test scenario is accidentally deleted?
    • Does Apidog support request code for custom endpoints?
  • Debugging APIs
    • How does Apidog integrate with third-party key management systems?
    • Why does the same request work correctly in other tools (such as Postman) but not in Apidog?
    • How to fetch variable values from database in Apidog?
    • How to migrate environments from other tools to Apidog?
    • How to assert using scripts in Apidog?
    • JSONPath can only extract arrays. How can we extract a single element from within them in Apidog?
    • How to configure database operations in Apidog when different environments have different database account credentials?
    • How to get service base URL in custom script?
    • Why does Apidog report an error exceeding the maximum Node.js string length when the API response is too large?
    • What is the size limit for console printing?Why do I get an error when printing large files?
    • How to resolve DB2 database connection errors on Windows?
    • How to Generate Dynamic Values in Apidog Custom Scripts?
    • Why does the client request for the same endpoint succeed, but an error occurs when debugging on the web side: "Unable to request address"?
    • Why does Apidog report an error when the response is too large?
    • How do I use the Apidog recording endpoint?
    • When defining an endpoint response, is it allowed for the endpoint to have no response content?
    • How do I get the service baseURL in a custom script?
    • How do I view the original packet in Apidog?
    • How do I make an asynchronous request in an Apidog script?
    • What is the console print size limit? Why Do I Get an Error When I Print a Large File?
    • How do I upload a file on an endpoint request?
    • What to Do If Apidog crashes or Response Data Isn’t Showing ?
  • Mock API data
    • How to mock APIs automatically?
    • What can Apidog mocking do?
    • How to mock fixed API data in Apidog?
    • How to mock conditional data in Apidog?
    • How to enable cloud mock in Apidog?
    • How to enable self-hosted mock in Apidog?
    • Does Apidog support mocking WebSocket APIs?
    • Why Is the Browser Not Returning Content When Requesting the Mock endpoint?
  • Automated tests
    • Why do test scenarios run without issues on my local client, but errors occur when running them in the Apidog CLI or runner?
    • How to create a test scenario in Apidog?
    • How to pass data between test steps?
    • Why am I not able to successfully reference pre-step data?
    • How to use foreach loop in Apidog?
    • What are the differences between sync data from endpoints/endpoint cases?
    • How to use test data in Apidog?
    • How to retrive test data in scripts in Apidog?
    • How to run test scenarios in batch in Apidog?
    • How to schedule test tasks in Apidog?
    • How to run performance test in Apidog?
    • How can I view the actual requests and responses in the performance tests?
    • How can I export performance test reports in Apidog?
    • How to use database query results as parameters for looping API requests?
    • Capture and Validate Stripe Webhooks in ApiDog During CI/CD
    • How to resolve the "Error: unable to verify the first certificate on runner" error?
    • General Runner Docker Container "Not Found" Error.
    • How to Set the Server Host for the General Runner in Apidog Web Version?
    • Why Scheduled test scenario endedup with 0 request?
    • What should I do if the file upload parameter cannot be found in Runner or CLI?
    • How to use Runner to run a test scenario with an upload file step?
    • How do I resolve the "Error: unable to verify the first certificate on runner" error?
    • How do I access and search the runner logs to identify the issue when a problem arises with a runner?
    • What should I do if the endpoint parameter is an upload file and cannot be found in Runner or CLI?
    • Why Aren't Test Steps Automatically Synchronized When the API Use Case Changes?
    • Why Does Using Multiple Dollar Signs in a Markdown Document Cause Some Content to Not Display Correctly?
  • Publish API Docs
    • How to hide all Apidog logos in published documents?
    • When the API spec is updated, will the API doc change?
    • How to share APIs to collaborators in Apidog?
    • How to customize domain of Apidog documentations?
    • How to create multi-version documentation in Apidog?
    • Scope of sharing for Publish Docs Sites in Apidog
    • Scope of sharing for Share Doc list in Apidog
    • Why publlished Share Docs is not showing the hostname?
    • How Can Document Users Modify the Base URL in Shared Docs ?
  • Markdown
    • How to use cards to link to various pages or endpoints within Apidog?
    • Why is some content not displayed correctly when using multiple $ symbols in Markdown documents?
    • How to use transparent background images in Apidog Markdown?
    • How to set the column width of a Markdown table?
  • Branches
    • How to access the sprint branch?
  • Administration
    • How to install Apidog client silently?
    • Why am I seeing a 'No Permission' error despite having admin access?
    • How do I check the runner version number?
    • Does Apidog support win7?
    • Why does Apidog show the error "Cannot locate program entry point DiscardVirtualMemory in dynamic link library KERNEL32.dll" after installation?
    • Can I set up a separate billing account for my team in Apidog?
  • Billing
  • Account & preferences
  • Apidog Europe
  1. Automated tests

How to pass data between test steps?

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.
Previous
How to create a test scenario in Apidog?
Next
Why am I not able to successfully reference pre-step data?
Built with