Skip to main content

How to add an API Call step?

You can add API calls as steps in your automated Test Case.

Jihed Othmani avatar
Written by Jihed Othmani
Updated over 3 weeks ago

What You'll Learn

  • How to integrate API calls into your Test Case

  • Setting up different types of API requests (GET, POST, PUT, DELETE)

  • Configuring request parameters, headers, and authentication

  • Defining environment-specific API parameters using the environment selector

  • Best practices for API testing in Thunder

Step-by-Step Guide

First Option

  1. Navigate to Your Test Case: Open the test case where you want to add the API call

  2. Create a New Step: Click the "Add a new step" button OR send a request in the chat to create one How to generate Test Steps?

  3. Choose API Call Type: From the "Step description" dropdown menu, select "API Call"

  1. Choose the desired environment:

    • Use the environment dropdown to configure API parameters for a specific environment.

    • This allows the same test step to behave differently depending on the active environment (e.g., dev vs prod).

    • Use the "Same Settings For All Environments" option to define shared API parameters across all environments.

    • Any environment-specific configuration overrides the “Same Settings For All Environments” when available.

    • If no environment-specific config exists, Thunder falls back to the "Same Settings For All Environments" values.

    → This helps adapt your step to multiple environments without duplicating it.

  2. Set Up Your Request

    • Method & URL

      Choose your HTTP method and enter the API endpoint

      Example: https://api.example.com/v1/

    • Parameters

      Add query parameters using the "Add Row" button

    • Headers

      Set up necessary headers like:

      Content-Type: application/json

    • Authentication

      Configure your auth method (Bearer token, Basic Auth, etc.)

    • Request Body

      Add your JSON payload for POST/PUT requests

  1. Execute your test case: Click “Execute” to execute your test case and see the result of the API call

Viewing and Copying the Full API Response

Once an API call is executed, you can view the entire response by clicking on the “Show allbutton next to the call result. This will open a modal displaying the complete API response. If you want to copy the response contents, just click the “Copy button inside the modal.

Second Option

  1. Navigate to Your Test Case: Open the test case where you want to add the API call

  2. Ask the chat to add a new API step for you: Send a request in the chat to create an API step and it will do it for you

  • Example: “Add a POST request to https://example.com with a bearer token XXX and a body containing the fields id and content”

Common Use Cases

Here are some practical ways to use API calls in Thunder:

  • Data Setup: Create test data via POST requests before running UI tests

  • Backend Verification: Use GET requests to verify data after UI interactions

  • Test Cleanup: Implement DELETE requests to clean up test data

Defining API Parameters Per Environment

Thunder allows you to define different API parameters per environment directly in your API step.

This is useful when:

  • API parameters change between development, staging, and production

  • You want to maintain a single test case with dynamic behavior across environments

How It Works:

  • Each API step has an environment selector that lets you switch between:

    • Specific environments (e.g. “Staging” or “Prod”)

    • A shared “Same Settings For All Environments” configuration

Priority Rules:

  1. If parameters are defined for the active environment, those are used.

  2. If no parameters exist for that environment, Thunder falls back to the “Same Settings For All Environments” configuration.

This means you only need to override environments where parameters are different — other environments can fallback to "Same Settings For All Environments”.

🔁 This setup allows you to avoid duplicating test steps and simplifies environment-specific testing logic.

Example:

  • “Same Settings For All Environments” config:POST > with bearer token XYZ

  • Staging config:POST > with basic auth UserName : Password

When the test runs in staging environment, it uses the staging config; otherwise, it falls back to “Same Settings For All Environments”.

Using Credentials & Variables in API Call Steps

You can also leverage credentials & variables within your API call steps to securely manage sensitive information like API keys, authentication tokens, or other confidential data required for your requests. This keeps your API calls secure and flexible, allowing you to easily switch between different environments or authentication methods without modifying your test cases.

Example: Securely Creating a User via API:

Let's imagine you have an API endpoint that creates a new user account. This endpoint requires an API key for authorization and also takes user credentials & variables in the request body.

Instead of hardcoding these sensitive values, we’ll show how to manage them securely using credentials & variables in your environment.

1. Create Credentials & Variables in Your Environment

  • Create a credential named API_KEY with your actual API key value.

  • Create a variable named USER_EMAIL with your login email.

    This will be used later in the request body to register or authenticate the user.

  • Create a credential named PASSWORD with your login password.

    Also used in the request body. This allows you to simulate a real user creation process securely.

2. Reference The Credentials & Variables in Your API Call Step

Environment: Same Setting For All Envrionments

Method: POST

Headers:

  • Content-Type: application/json

Authorization:

  • Bearer Token: [API_KEY]

Body:

{ "username": "user", "email": "[USER_EMAIL]", "password": "[PASSWORD]" }
  • Authorization: The Authorization header securely includes your [API_KEY] credential, ensuring your API requests are authenticated without exposing the key in your test definition.

  • Body: You can use credentials & variables like [USER_EMAIL] and [PASSWORD] within the request body for scenarios like creating a new user, further centralizing your secret management.

When Thunder Code executes this API call step, it will automatically substitute [API_KEY], [USER_EMAIL], and [PASSWORD] with their respective values from the chosen environment. This approach provides:

  • Enhanced Security: Your sensitive API keys and other credentials & variables are never hardcoded in your test cases.

  • Improved Maintainability: Easily update credentials & variables in one place (the Environment) without modifying multiple API call steps.

  • Greater Flexibility: Seamlessly run API tests against different environments (development, staging, production) by simply switching the active environment, provided the necessary credentials & variables are in each.

Other related reads you might find useful:

Did this answer your question?