API Flows – Chaining Multiple APIs
Learn how to chain multiple API requests together to create complex workflows and test complete user scenarios in Maeris.
What are API Flows?
API Flows are sequences of API requests that are executed in order, where the response from one request can be used as input for subsequent requests. This allows you to test complete workflows and scenarios that involve multiple API calls.
Common Use Cases
- Authentication Flows: Login, get token, use token in subsequent requests
- CRUD Operations: Create, read, update, and delete resources in sequence
- Multi-Step Workflows: Complete business processes that require multiple API calls
- Data Dependencies: Use data from one API call in another
- End-to-End Testing: Test complete user journeys through APIs
Creating API Flows
- Create Your First Request: Start with the first API request in your flow
- Add Subsequent Requests: Add additional requests that depend on previous ones
- Extract Variables: Extract data from responses using response parsing
Common extractions: IDs, tokens, status values, etc.
- Use Variables in Next Requests: Reference extracted variables in subsequent requests
Use {{variableName}}" syntax to reference variables
- Add Assertions: Validate responses at each step to ensure the flow works correctly
- Run the Flow: Execute the entire flow and review results
Extracting Data from Responses
To chain requests together, you need to extract data from one response and use it in the next request. Maeris provides several ways to extract data from API responses.
Extraction Methods
- JSON Path: Extract values from JSON responses using JSON path expressions
Example:
$.data.userIdto extract userId from response - Response Headers: Extract values from response headers
Example: Extract authorization token from headers
- Response Body: Extract specific fields from the response body
Use dot notation or JSON path to access nested values
- Scripts: Use scripts for complex extraction logic
Write custom JavaScript to parse and extract data
Example: Authentication Flow
Here's an example of a typical authentication flow:
Conditional Logic in Flows
You can add conditional logic to your flows to handle different scenarios and make decisions based on response data.
Common Conditional Patterns
- Skip Steps: Skip certain requests based on conditions
- Retry Logic: Retry failed requests before continuing
- Branching: Execute different requests based on response values
- Error Handling: Handle errors and continue or stop the flow
Best Practices
- Validate Each Step: Add assertions after each request to catch issues early
- Use Descriptive Names: Name your flows and requests clearly
- Handle Errors: Add error handling for failed requests
- Document Dependencies: Document which requests depend on which data
- Test Individual Steps: Test each request independently before chaining
- Use Variables: Store extracted values in variables for clarity
- Clean Up: Include cleanup steps (like deleting test data) when needed
Next Steps
- API Assertions and Validations - Add validations to your flows
- Advanced API Assertions - Use advanced validation techniques
- API Test Results and Analysis - Analyze flow execution results