This section will walk you through the essentials of creating, executing, and validating your API tests on our codeless platform. Learn how to make your first call, handle dynamic data, chain requests, and ensure your application's backend is functioning perfectly.
Scenario: We will test a standard e-commerce workflow:
- Search Products: Send a
GETrequest to/productsto retrieve a list of all products in the "laptops" category. - Fetch Details: Extract the ID of the first product from the list and use it to send a
GETrequest to/products/{productId}to fetch its specific details.
Part 1: The First API Call (Search for Products)
We'll start by making the API call to get a list of laptops.
Step 1: Insert a REST Call
In the ACCELQ Action editor, click the + API button and select Insert REST call.
Step 2: Configure the Service Information
This screen defines our initial search request.
- Reference Name: Enter
searchLaptopsRequest. This name is crucial for linking our steps. - Endpoint URL: Enter the search URL, e.g.,
https://api.my-store.com/v1/products?category=laptops. - Method Type: Select
GETfrom the dropdown.
Since this is a simple GET request, no headers or payload are needed. Click Next, and then Save to add the statement to your Action.
Part 2: Extracting the Product ID for the Chain
Now, we need to process the response from searchLaptopsRequest to get the ID of the first product. Let's assume the API returns a JSON array like this:
JSON
{
"count": 2,
"data": [
{ "id": "lp-mac-pro-16", "name": "ProBook 16", "price": 2499 },
{ "id": "lp-win-ultra-14", "name": "UltraSlim 14", "price": 1399 }
]
}
On the next line in your Action editor, add the Get JSON Node value command to extract the ID of the first item in the data array. We use the JSONPath index [0] for this.
Get JSON Node value from the Response of ReST call
searchLaptopsRequest. JSONPath expression is$.data[0].id. Store the value in parameterfirstProductId.
This command finds the first object in the data array, gets the value of its id field, and stores it in a variable named firstProductId.
Part 3: The Second API Call (Fetch Product Details)
With the product ID stored in a variable, we are ready to build the second request to get its details.
Step 1: Insert the Second REST Call
Once again, click + API and Insert REST call.
Step 2: Configure with the Parameterized Product ID
In the REST Service Information window, we'll use the firstProductId variable.
- Reference Name: Enter
getProductDetailsRequest. - Endpoint URL: Parameterize the URL by referencing the variable:
https://api.my-store.com/v1/products/{param: firstProductId}. - Method Type: Select
GET.
Click Next, then Save. ACCELQ now adds the second API call to your Action.
Part 4: Verifying the Final Result
Your Action now contains the complete, non-sensitive chained flow. The final step is to verify that the second API call returned the correct information.
Click on the response verification link in the getProductDetailsRequest statement. In the Response Information screen, you can add powerful assertions, such as:
- Verifying the Status Code is
200 OK. - Verifying that the product
idin the response body matches the ID we requested. This creates a closed-loop verification. To do this, you would add a verification on theidnode in the response and set the expected value to{param: firstProductId}.
This approach effectively demonstrates API chaining for a realistic workflow without exposing any sensitive data in your test logic.
Comments
0 comments
Please sign in to leave a comment.