📝Store API Variables

Overview

In scriptless automation, storing values from API responses allows subsequent API calls to utilize these stored values for further operations or validations. This document explains how to configure the storage of response values and how to utilize them in subsequent API calls.

Storing Values from API Responses

Configuration

The CSV template for an API call includes a RESPONSE:STORE_VALUE parameter that determines whether to store a specific value from the API response. The configuration is as follows:

  • RESPONSE:STORE_VALUE: Set to a variable name to store the corresponding value from the given JSON path in the response. Set to NONE to skip storage.

Example

For an API call that creates a new entry (e.g., using POST), the template might look like this:

DEPENDANT_TEST_CASE,NONE,
END_POINT,https://api-generator.retool.com/7kbSLy/data,
METHOD,POST,
PARAMS:KEY,NONE,
PARAMS:VALUE,NONE,
AUTH:KEY,NONE,
AUTH:VALUE,NONE,
HEADERS:KEY,Content-Type,
HEADERS:VALUE,application/json,
BODY:KEY,Column 1,
BODY:VALUE,PrecisionTestAutomation,
RESPONSE:CODE,201,
RESPONSE:JSON_PATH,NONE,'Column 1'
RESPONSE:EXPECTED_VALUE,NONE,PrecisionTestAutomation
RESPONSE:STORE_VALUE,NONE,Name

In this example, the value from 'Column 1' in the response is stored in a variable named Name.

Utilising Stored Values in Subsequent Calls

Usage Template

Stored values can be utilized in subsequent API calls by referencing them in the template. The reference is made using a specific syntax, often prefixed with an identifier like ApiGlobalVariables.

Example

For a subsequent API call that retrieves data (e.g., using GET), the template might reference the stored variable as follows:

DEPENDANT_TEST_CASE,POST,
END_POINT,https://api-generator.retool.com/7kbSLy/data/1,
METHOD,GET,
...
RESPONSE:CODE,200,
RESPONSE:JSON_PATH,NONE,id,'Column 1'
RESPONSE:EXPECTED_VALUE,NONE,1,ApiGlobalVariables:Name
RESPONSE:STORE_VALUE,NONE,NONE,NONE

In this example, the template references ApiGlobalVariables:Name, which utilizes the value stored in the variable Name from the previous API response.

Use of Stored Values

In addition to the RESPONSE:EXPECTED_VALUE, stored values can be utilized in various other parts of the API call template. Stored values can be used in the following components:

  1. END_POINT: Incorporate stored variables into the endpoint URL to dynamically change API endpoints based on previous responses.

    END_POINT,https://api-generator.retool.com/7kbSLy/data/ApiGlobalVariables:XXX,
  2. PARAMS:VALUE: Use stored variables as parameter values in the API request.

    PARAMS:VALUE,ApiGlobalVariables:XXX,
  3. AUTH:VALUE: Apply stored variables in authentication fields, useful for dynamic authentication scenarios.

    AUTH:VALUE,ApiGlobalVariables:XXX,
  4. HEADERS:VALUE: Include stored variables in request headers, such as dynamically generated tokens or session data.

    HEADERS:VALUE,ApiGlobalVariables:XXX,
  5. BODY:VALUE: Insert stored variables in the request body, allowing the body content to change based on previous responses.

    BODY:VALUE,ApiGlobalVariables:XXX,

Conclusion

Storing and utilising values from API responses is a powerful feature in scriptless automation, enabling dynamic data handling and interdependent API testing. By configuring the RESPONSE:STORE_VALUE appropriately and referencing stored values using a designated syntax, testers can create flexible and efficient automated API tests. This approach is particularly useful in scenarios where the output of one API call is a prerequisite for subsequent calls.

Last updated

Was this helpful?