# Adding an API Step to your Test

## Saving API response as variable

Test cases are not just a set of steps performed on your screen. Today, test cases require creating runtime test data from API responses and using that data in subsequent steps (or deleting data after the test has completed execution). This makes automated tests reusable and resilient.

To add an API step to a test case:

1. Log in to your Sofy account.
2. Select **Device Lab** from the left navigation bar. 
3. Acquire and launch a device.
4. Start [recording a test case](https://docs.sofy.ai/mobile-automate/creating-an-automated-test).
5. To create an API step, you may click on _**Add Step**_ on the bottom right in the Recorded Steps panel as highlighted below.

6. Now you may click on _**API step**_ to add a new API step. This will open the **API Step Modal**.

1. Specify the request URL and select the type of request. Sofy currently supports GET, POST, PUT, PATCH, and DELETE.
2. Click **Send**.
3. You can also add up to 10 test variables from the values received in the response (for example, if you want to execute sequences of API calls based on data obtained during the test execution). Test variables will be assigned a value during the test run once the test case is saved. To add a test variable:
   1. Click on any value in the response.
   2. Click the + symbol next to the value. The test variable will appear under the **Test Variables** section. 
4. While capturing a variable from an API step, you can specify to Sofy if you want to treat it as a String, Integer or Float from the dropdown: 
5. Update the **Regex** (regular expression) field if you want to save only the relevant part as a variable. For example, you may want to store only the second word of a given string.
6. While configuring your API step, you can also add new path variables, headers (like bearer tokens), and query parameters. To do this:
   1. Select the **Headers**, **Query Params**, or **Path Variables** tab under the request setting.
   2. Click **Add new** or the **+** button at far right. 
   3. Name and select a variable for the header, query param, or path variable. You can also select a test variable you created in the API step. 
7. You may also set a soft-failure for your API steps. This comes in handy if you would like your test case to continue even if a non-critical API fails. To do so, navigate to the Settings tab while configuring your API step.
   
   
   1. You may toggle the _**Allow soft failure**_ option. This is turned off by default.

_Allow soft failure_ is recommended for use if the API step is non-critical (i.e no variables are created out of it that may be used in subsequent steps or failure of the API step does not necessitate that your test flow would be broken).

1. Once you have configured your API step to your specifications, you may click on _**Add API step.**_
