API Academy
🌐 English
  • 🌐 English
  • 🌐 繁體中文
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Working with APIs
  • Introduction
  • Table of Contents
  • API Academy
    • Get Started
      • What is an API?
      • How Does an API Work?
      • How to Call an API?
      • How to Read an API Documentation?
      • Chapter Summary
      • Get realtime weather
    • API Fundamentals
      • API Funtamentals: Overview
      • Method & Path
      • Parameters
      • Request Body
      • Responses
      • API Specification & OAS
      • Chapter Summary
    • Working with APIs
      • Working with APIs: Overview
      • Making Requests from Spec
      • Environments and Variables
      • Chaining Multiple Endpoints
      • Handling Authentication
      • Handling API Signatures
      • Introduction to Scripts
      • Chapter Summary
    • Mocking APIs
      • Mocking APIs: Overview
      • Smart Mock
      • Mock Expectations
      • Cloud Mock
      • Mock Scripts
      • Chapter Summary
    • Designing APIs
      • Designing APIs: Overview
      • Introduction to API Design
      • Creating Your First API Project
      • Analyzing Requirements and Planning Your API
      • Designing Data Models
      • Designing Endpoints
      • Using Components and Reusability
      • Setting Up Authentication
      • API Design Guidelines
      • Chapter Summary
    • Developing APIs
      • Developing APIs: Overview
      • Setup: Install Your AI Coding Assistant
      • Quick Start: From Spec to Running API in 30 Minutes
      • Understanding the Generated Code
      • Testing Your API with Apidog
      • Deployment: Put Your API Online
      • Chapter Summary
    • Testing APIs
      • Testing APIs: Overview
      • Getting Started: Your First Test Scenario
      • Integration Testing and Data Passing
      • Dynamic Values
      • Assertions and Validations
      • Flow Control: If, For, ForEach
      • Data-Driven Testing
      • Performance Testing
      • Test Reports and Analysis
      • CI/CD Integration
      • Scheduled Tasks and Automation
      • Advanced Testing Strategies
      • Chapter Summary
    • API Documentations
      • API Documentations: Overview
      • Publishing Your First API Doc
      • Customizing Documentation Appearance
      • Interactive Features for Consumers
      • Advanced Publishing Settings
      • Managing API Versions
      • Chapter Summary
    • Advanced API Technologies
      • API Technologies: Overview
      • GraphQL
      • gRPC
      • WebSocket
      • Socket.IO
      • Server-Sent Events (SSE)
      • SOAP
      • Chapter Summary
    • API Lifecycle
      • API Lifecycle: Overview
      • Stages of the API Lifecycle
      • API Governance
      • API Security Best Practices
      • Monitoring and Analytics
      • API Versioning Strategies
      • The Future of APIs
      • Chapter Summary
    • API Security
      • API Security: Overview
      • API Security Fundamentals
      • Authentication vs Authorization
      • Understanding OAuth 2.0 and OpenID Connect
      • JSON Web Tokens (JWT)
      • OWASP API Security Top 10
      • Encryption and HTTPS
      • Chapter Summary
    • API Tools
      • API Tools: Overview
      • The Evolution of API Tools
      • API Clients
      • Command Line Tools (cURL, HTTPie)
      • API Design and Documentation Tools
      • API Mocking Tools
      • API Testing Tools
      • All-in-One API Platforms
      • Chapter Summary
    • API Gateway
      • API Gateway: Overview
      • What is an API Gateway?
      • Key Features of API Gateways
      • API Gateway vs Load Balancer vs Service Mesh
      • Popular API Gateway Solutions
      • The BFF (Backend for Frontend) Pattern
      • Chapter Summary
  • Modern Pet Store
    • Pet
      • Get Pet
      • Update Pet
      • Delete Pet
      • Create Pet
      • List Pets
      • Upload Pet Image
    • User
      • Update User
      • Get User
      • Delete User
      • Login
      • Logout
      • Create User
    • Store
      • List Inventory
      • Create Order
      • Get Order
      • Delete Order
      • Callback Example
      • Pay for an Order
    • Payments
      • Pay Order
    • Chat
      • Create Chat Completion
    • Webhooks
      • Pet Adopted Event
      • New Pet Available Event
  • Schemas
    • Pet
    • Category
    • User
    • ApiResponse
    • OrderPayment
    • Tag
    • Order
    • Links-Order
    • PetCollection
    • Bank Card
    • Bank Account
    • Links
    • Error
HomePetstore APIExplore more APIs
HomePetstore APIExplore more APIs
🌐 English
  • 🌐 English
  • 🌐 繁體中文
🌐 English
  • 🌐 English
  • 🌐 繁體中文
  1. Working with APIs

Chaining Multiple Endpoints

In real-world API workflows, you rarely work with just a single endpoint. Most tasks require a sequence of operationsβ€”creating a resource, retrieving it, updating it, and so on. Each step often depends on data from the previous step.
In this article, we'll learn how to chain multiple endpoints together using Apidog, demonstrating a complete workflow: creating a pet, querying its details, and updating its information. We'll use variables to pass data between requests, making the workflow seamless and automated.

1. The Workflow: Create, Query, and Update#

Let's walk through a practical scenario using the Pet Store API:
1.
Create a pet using POST /pets β€” this returns a pet object with an id
2.
Query the pet details using GET /pets/{id} β€” using the ID from step 1
3.
Update the pet using PUT /pets/{id} β€” modifying the pet's information
The key challenge is that each step needs data from the previous step. Without variables, you'd have to manually copy and paste the pet ID between requests. With Apidog's variable extraction feature, this becomes automatic.

2. Step 1: Create a Pet and Extract the ID#

First, let's create a pet and extract its ID into a variable for use in subsequent requests.

Create the Pet#

1.
Open the "Create a pet" endpoint (POST /pets) in your Apidog project.
2.
Switch to the "Run" tab.
3.
In the request body section, you can use Apidog's "Auto-generate" feature to automatically generate a request body based on the API specification. Click the "Auto-generate" button, and Apidog will create a sample request body with all required fields.
image.png
Alternatively, you can manually fill in the request body with pet information. For example:
{
  "name": "Luna",
  "species": "DOG",
  "breed": "Golden Retriever",
  "ageMonths": 24,
  "size": "LARGE",
  "color": "Golden",
  "gender": "FEMALE",
  "goodWithKids": true,
  "goodWithPets": true,
  "adoptionFee": 150.00,
  "description": "Friendly golden retriever looking for an active family",
  "status": "AVAILABLE"
}
4.
Click "Send" to create the pet.
5.
After the request completes, you'll see a response like this:
{
  "id": "pet_1Nv0FGQ9RKHgCVdK",
  "name": "Luna",
  "species": "DOG",
  "breed": "Golden Retriever",
  "ageMonths": 24,
  "status": "AVAILABLE",
  ...
}

Extract the Pet ID as a Variable#

Now we need to extract the id from the response and save it as a variable:
1.
In the Run tab, scroll down to the Post Processors section (below the response area).
2.
Click "Add PostProcessor" and select "Extract Variable".
image.png
3.
Configure the variable extraction:
Variable Name: pet_id
Variable Scope: Choose "Global Variables Shared within Project" (so it can be used in other endpoints)
Extraction Source: Select "Response JSON"
JSONPath Expression: Enter $.id to extract the id field from the response
image.png
4.
Click "Save" to save the extraction configuration.
5.
Now, send the request again. After the request completes, the pet ID will be stored in the {{pet_id}} variable.
6.
You can verify the extraction worked by checking the Console tab in the response area, which will show logs confirming the variable was extracted.
image.png
JSONPath Syntax: The expression $.id means "get the id field from the root of the JSON object". If the response structure was nested (e.g., {"data": {"pet": {"id": "..."}}}), you would use $.data.pet.id instead.

3. Step 2: Query the Pet Details#

Now that we have the pet ID stored in a variable, we can use it to query the pet details.
1.
Open the "Get a pet" endpoint (GET /pets/{id}) in your Apidog project.
2.
Switch to the "Run" tab.
3.
In the path parameter field for id, instead of typing a value, enter: {{pet_id}}
image.png
4.
When you hover over {{pet_id}}, Apidog will show you the current value (the pet ID we extracted in step 1).
5.
Click "Send" to execute the request.
6.
Apidog will automatically replace {{pet_id}} with the actual pet ID value (e.g., pet_1Nv0FGQ9RKHgCVdK) when sending the request.
The request URL will be something like:
https://api.petstoreapi.com/v1/pets/pet_1Nv0FGQ9RKHgCVdK
You should receive the complete pet details in the response.

4. Step 3: Update the Pet Information#

Finally, let's update the pet's information. This demonstrates how to use variables in the request body (JSON).
1.
Open the "Update Pet" endpoint (PUT /pets/{id}) in your Apidog project.
2.
Switch to the "Run" tab.
3.
In the path parameter field for id, enter: {{pet_id}} (same as in step 2).
4.
In the request body, you can use variables in the JSON. For example, to update the pet's description while keeping other fields, you might use:
{
  "id": "{{pet_id}}",
  "name": "Luna",
  "species": "DOG",
  "breed": "Golden Retriever",
  "ageMonths": 24,
  "size": "LARGE",
  "color": "Golden",
  "gender": "FEMALE",
  "goodWithKids": true,
  "goodWithPets": true,
  "adoptionFee": 150.00,
  "description": "Updated: Friendly golden retriever looking for an active family. Great with children!",
  "status": "AVAILABLE"
}
Notice that we're using {{pet_id}} in the JSON body. When you send the request, Apidog will replace it with the actual pet ID value.
Using Variables in JSON: When using variables in JSON request bodies, make sure to wrap string variables in quotes (e.g., "{{pet_id}}"). For non-string values like numbers or booleans, you don't need quotes (e.g., {{quantity}} for a number).
5.
Click "Send" to update the pet.
6.
The response will confirm the pet was updated with the new information.

5. Viewing the Actual Requests#

After sending requests with variables, you can see how Apidog resolved them:
1.
In the response panel, switch to the "Actual Request" tab.
2.
You'll see the actual request that was sent, with all variables replaced by their values.
image.png
For example, if you used {{pet_id}} in the path parameter, you'll see the actual pet ID in the URL. If you used {{pet_id}} in the JSON body, you'll see the actual value there as well.
This is helpful for debugging and understanding exactly what data was sent to the server.

6. Key Takeaways#

Chaining endpoints means using the output from one request as input for the next request.
Extract variables from responses using Post Processors to capture data you need for subsequent requests.
Use variables in path parameters, query parameters, headers, and request bodies using {{variable_name}} syntax.
JSONPath expressions (like $.id) allow you to extract specific fields from JSON responses.
Variable scope matters: use "Global Variables Shared within Project" if you want to use the variable across different endpoints.
View actual requests to see how variables were resolved and verify your workflow is working correctly.

By chaining multiple endpoints together with variables, you can build complete workflows that automate complex API operations. This is the foundation for creating test scenarios and automated API testing, which we'll explore in future articles.
Continue with β†’ Handling Authentication
Modified atΒ 2025-12-25 09:38:45
Previous
Environments and Variables
Next
Handling Authentication
Built with