Conditional Variables
Conditional variables extend reusable variables with filtering. They let you extract only items that match specific criteria, such as "only blocks where type = 'page'" or "only users where status != 'deleted'".
When to Use Conditional Variables
Use conditional filtering when:
- An API returns mixed data you need to separate
- You want to process only certain types of items
- The API doesn't support server-side filtering
Example Use Cases
| API Response | Filter | Result |
|---|---|---|
| All Notion blocks | type = 'page' | Only page blocks |
| All users | status != 'deleted' | Active users only |
| All files | name ends with '.pdf' | PDF files only |
| All records | metadata.archived exists | Records with archive flag |
Creating Conditional Variables
Step 1: Open the Conditional Variable Modal
From the Variables Panel:
- Click + New Conditional Variable
- Or click Add Filter on an existing variable
Step 2: Select Source
Choose the endpoint that provides the array data:
- Only endpoints with test results are available
- Test the source endpoint first if needed
Step 3: Choose Array Path
Select which array to filter:
- Common paths are suggested from the response
- Shows item count for each array
- Preview first item structure
Step 4: Define Filter Condition
Set the filtering criteria:
Field: The property to check on each item
- Supports dot notation for nested fields (
user.profile.type) - Auto-complete shows available fields
Operator: How to compare
equals- Exact matchnot_equals- Does not matchcontains- Substring presentstarts_with- Begins with valueends_with- Ends with valueexists- Field is present and not null
Value: What to compare against
- Auto-complete shows existing values in the data
- Not needed for
existsoperator
Step 5: Preview and Confirm
The modal shows:
- Matching count: "15 of 42 items match"
- Sample matches: First few matching items
- Extract field: Which field to extract from matches
Step 6: Name and Save
Give the variable a descriptive name that indicates both source and filter:
- Good:
PageBlocks,ActiveUsers,PdfFiles - Include filter hint:
UsersNotDeleted,BlocksTypePage
Filter Operators
equals
Exact string match after type conversion:
Items: [{ type: "page" }, { type: "database" }, { type: "page" }]
Filter: type = 'page'
Matches: 2 items
not_equals
Excludes matching items:
Items: [{ status: "active" }, { status: "deleted" }, { status: "active" }]
Filter: status != 'deleted'
Matches: 2 items
contains
Substring search (case-sensitive):
Items: [{ name: "Report Q1" }, { name: "Summary" }, { name: "Report Q2" }]
Filter: name contains 'Report'
Matches: 2 items
starts_with / ends_with
Prefix or suffix matching:
Items: [{ id: "user_123" }, { id: "org_456" }, { id: "user_789" }]
Filter: id starts with 'user_'
Matches: 2 items
exists
Checks field is present and not null:
Items: [
{ id: 1, email: "a@x.com" },
{ id: 2, email: null },
{ id: 3 }
]
Filter: email exists
Matches: 1 item (only first has non-null email)
Nested Field Filtering
Filter on nested object properties using dot notation:
Items: [
{ id: 1, meta: { type: "page", archived: false } },
{ id: 2, meta: { type: "database", archived: true } },
{ id: 3, meta: { type: "page", archived: false } }
]
Filter: meta.type = 'page'
Matches: items 1 and 3
Filter: meta.archived = 'true'
Matches: item 2
Applying Conditional Variables
Conditional variables work exactly like regular variables:
- Apply to any parameter drop zone
- In iterate mode, target runs once per matching item
- Filter is applied at extraction time
Variable: PageBlockIds
Source: List Blocks (returns 100 blocks)
Filter: type = 'page' (matches 15 blocks)
Extract: id
Applied to: GET /blocks/{blockId}/content
Result: Runs 15 times (only page blocks)
Editing Filters
Modify Existing Filter
- Find variable in Variables Panel
- Click Edit
- Adjust filter condition
- Preview updated matches
- Save changes
All endpoints using this variable will use the new filter on next test.
Remove Filter
- Edit the variable
- Clear the filter fields
- Save as regular variable (no filtering)
Best Practices
Filter at the Right Level
For nested arrays like pages[*].blocks[*]:
- Filter applies at the last array (blocks)
- Can't filter pages and blocks independently
- Create separate variables if needed
Check Filter Effectiveness
Always preview match counts:
- 0 matches = filter too restrictive or field name wrong
- All items match = filter not filtering (check operator/value)
- Expected subset = filter working correctly
Name Clearly
Include filter intent in name:
ActiveUsers(implies filtered)AllUsers(implies no filter)UsersWithEmail(implies exists filter)
Document Complex Filters
Use the description field for filters that aren't obvious:
- "Filters to blocks created by the primary user"
- "Excludes test accounts (email contains 'test')"
Troubleshooting
"Filter matches nothing"
- Check field name spelling (exact match required)
- Verify field exists on items (use exists operator to test)
- Check value format (strings are case-sensitive)
- Look at actual data in JSON viewer
"Filter matches everything"
- Operator might be inverted (equals vs not_equals)
- Value might be empty or whitespace
- Field might have unexpected type
"Wrong items filtered"
- Verify you're filtering the correct array level
- Check nested path is complete (
meta.typenot justtype) - Review sample matches in preview
Related Documentation
- Reusable Variables - Base variable concept
- Conditional Filtering Algorithm - Technical details
- Dependency Mapping - Mapping overview