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.
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.
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",
...
}
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".
3.
Configure the variable extraction: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
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.
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.
3.
In the path parameter field for id, instead of typing a value, enter: {{pet_id}}
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.
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.
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.
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.