# Pre-requisite-API

## Pre requisite API and Dynamic Variable

Pre requisite API are those API, which are executed before the actual scripts. End user can use the dynamic variables across the script and for the referenced dynamic variable’s pre requisite script will run internally and pre requisite reports will be tagged for the respective scripts.

### Contents

* [Pre requisite API](#pre-requisite-api-and-dynamic-variable)
  * [Get started with Pre requisite API](#get-started-with-pre-requisite-api)
  * [Editing a Pre requisite API](#editing-a-pre-requisite-api)
  * [Deleting a Pre requisite API](#deleting-a-pre-requisite-api)
  * [Running a Pre requisite API](#running-a-pre-requisite-api)
  * [Viewing a Pre requisite API Report](#viewing-a-pre-requisite-api-report)
* [Dynamic Variable](#dynamic-variable)
  * [Ability to fetch a dynamic variable](#ability-to-fetch-a-dynamic-variable)
* [Related topics](#related-topics)

***

### Get started with Pre requisite API:

Step-1: Select a project.

Step-2: Under any Functional, Performance or API Process service, click on **Project Setup**.

Step-3: Under Project Setup, click on **Prerequisite API**.

![Prerequisite Tab](/files/3Eb1MDRS557XJ9L8W0E1)

Step-4: There will be a list of all the Prerequisite API or if not we can create as required.

Step-5: Click on **Add API**

![Alt text](/files/h9hbKGccdnkRoirdNzWD)

Step-6: Your Prerequisite API will require the following **Info**:

* Name – the name of Prerequisite API script
* Request URL – a request URL of your script
* Timeout – Provide API timeout in ms
* URL Encode Enabled – Enable or disable URL Encode
* Verbs – the type of API call. GET, POST, PUT, DELETE or PATCH

![Alt text](/files/r9qgBpLZJRODvgdtL2dm)

Step-7: Click a Prerequisite script: **Authorization & Certificate** tab

* For prerequisite APIs, authentication can be done by
  1. Basic Auth - user can add username and password
  2. OAuth 2.0 - user can add Access Token with an option to add access token to Header & Query Param.
  3. If there are certificates in respective project, Authorization & Certificates tab will be enabled and User can add the certificates as mode of authorization for the API’s.

Step-8: Click a Prerequisite script: **Headers & Params** tab.

* Clicking on the "Header & Params" button will bring you to the menu below.\
  ![Alt text](/files/5gsPLufG6zSeGtM7oTx2)
* On this page, you can add Request Headers, Path parameters and Query parameters. Clicking on the corresponding "Add" button will add a form to the corresponding list.
* A Request Header field requires a Key and a Value.

  ![Header](/files/c7LzO4k4KPNCZLAINyYq)
* Path and Query parameters require a Parameter Name and a Parameter Value.

  ![Params](/files/2pxzVTCjYOejrPXNzQu8)

Step-9: Click a Prerequisite script: **Body** tab

* When you are doing a POST, PUT, DELETE or PATCH method, the "Body" option will appear. This is where you will add the Body of your Request.

Step-10: Click a Prerequisite script: **Data Handlers** tab.

* Here an user can provide what are the Dynamic Variables that can be generated from API’s Response by selecting “Path Type” as “JsonPath” or “Xpath” and click “Save”.
  * Use “Path Type” as “JsonPath” when API is of type REST API
  * Use “Path Type” as “Xpath” when API is of type SOAP API
* For JSON path or XPath, can use Path Extractor Tool.

  ![Alt text](/files/SRt4m2Fs4L0BVlLlcIBQ)

Step-11: Click on **Save** Button.

***

### Editing a Pre requisite API:

Step 1: Under Project Setup, click on Prerequisite API where there will be a list of all the Prerequisite API.

Step 2: CLick on **Go to Test**. ![Alt text](/files/aSXJlv6FTKFzFGBajRen)

Step 3: Modify the required changes and click on **Save** button.

***

### Deleting a Pre requisite API:

Step 1: Under Project Setup, click on Prerequisite API where there will be a list of all the Prerequisite API. ![Alt text](/files/5J1pbFvg7tJoAgFLGTNi)

Step 2: Click on **Delete** icon & Delete popup will get displayed. ![Alt text](/files/W7MmVGrQIgLg0sV0944l)

Step 3: An user can confirm deletion hitting **Delete** button.

***

### Running a Pre requisite API:

Step 1: Under Project Setup, click on Prerequisite API where there will be a list of all the Prerequisite API. ![Alt text](/files/rJAQtqf0OFD6H1SJHonU)

Step 2: CLick on **Run** icon.

Step 3: API will get executed and navigated to report listing page.

***

### Viewing a Pre requisite API Report:

Step 1: Under Project Setup, click on Prerequisite API where there will be a list of all the Prerequisite API.

Step 2: CLick on **View Report** icon.

![Alt text](/files/M7hwetBKmis28D4RC7Gr)

Step 3: An user will be navigating to result page.

![Alt text](/files/o9RbHPnfJWcFy06NNDGN)

Step 4: Click on **View Details**

![Alt text](/files/kXiJIk46kY8uTzQ5iCqk)

***

## Dynamic Variable

End user can use the dynamic variables across the script and for the referenced dynamic variable’s pre requisite script will run internally and pre requisite reports will be tagged for the respective scripts.

***

#### Ability to fetch a dynamic variable

Step 1: Create API and enter all the mandatory fields by clicking on “Add API” button under Variables → Prerequisite API

![Alt text](/files/bretNBfPMtNEw9PdCNdj)

Step 2: Navigate to “Data Handlers” where you can provide what are the Dynamic Variables that can be generated from API’s Response by selecting “Path Type” as “JsonPath” or “Xpath” and click “Save”.

* Use “Path Type” as “JsonPath” when API is of type REST API
* Use “Path Type” as “Xpath” when API is of type SOAP API

![Alt text](/files/P7GB1AohiNuMwwO4Yetl)

* The above screenshot shows the example of a REST API.

  **Note**:

  * Variable Names in “Data Handlers” must be unique across pre requisite scripts created.
  * Avoid giving xpaths for APIs which are having json responses and json paths for APIs having XML responses.

Step-3 : All the created dynamic variable will be listed under **Dynamic Variable** tab.

![Alt text](/files/qTlbZBmvy05tHyn4XtDt)

Step 4 : To use Dynamic Variables in scripts follow this syntax #VariableName#

![Dynamic Variable Usage](/files/t5M5iyiicS5XUKWp4d25)

Step-5 : Verify dynamic variable on result page.

![Dynamic Variable Value](/files/8yoGeKukdjmSfDMnDD0e)

* As we can see in the above snapshot, the dynamic variables have been replaced with the actual values and a successful response is obtained.

![PrerequisteReport](/files/gBOKbnlzcw45TQlDKVjv)

* As we can see in the above snapshot, the result of Prerequiste API.

***

Note:

* Also please provide valid variable names in data handlers, You can use underscore as the only special character for naming variables.

#### Valid ones

```
Varibale
or
Variable_name
or
Variable123
or
variable_name_123
or
Variable_name_Usn_001
```

#### Invalid ones

```
_varible_name_123
or
_123_variable_names_123
or
#Variable_name$usn&123
or
$Variable_name
```

***

#### Related topics

* [Integratiom](/api-testing/project-setup/integration.md)
* [Database Configuration](/api-testing/project-setup/database-configuration.md)
* [Global & Environment](/api-testing/project-setup/global-and-environment.md)


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.qyrus.com/api-testing/project-setup/pre-requisite-api.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
