# REST API Sequence Monitoring
## Overview
Modern web and mobile applications depend on a series of REST API calls to fetch data and perform actions. When one API call in the series fails, the whole workflow of the application can break. The REST API Sequence monitor runs these API calls in order, as steps, and monitors the availability and response time of each step and of the complete workflow.
## Creating a new REST API Sequence monitor
To configure REST API Sequence monitor, follow the steps mentioned below:
1. Click on **Add New Monitor** link under **New Monitor**. Select **REST API Sequence**.
2. Enter Display Name of the monitor.
3. Specify the **polling interval** for which the status of the monitor should be updated (in minutes).
4. Provide the **transaction steps** that are to be monitored. Each step represents an API call in your application's workflow. Transaction steps can be added by choosing any one of the following options:
1. **Import Steps:** This option lets you import the API requests from a HAR file, a Postman Collection or an OpenAPI / Swagger file, and add the ones you need as steps. Refer [Importing steps from a file](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#importSteps) to know more.
2. **Add Step:** This option lets you add the transaction steps manually. After selecting this option, enter the following details:
- Specify the **step name** that is to be added.
- Enter the **Endpoint URL** of the REST API to be monitored. The URL must start with *http://* or *https://*.
- Enable the **Stop on error** option if the remaining steps should not run when this step fails.
**Note:**
- When **Stop on error** is enabled and the step fails, the remaining steps are not run and the monitor is marked as down immediately. Use it for critical steps, such as a login step that the other steps depend on.
- When it is disabled, the remaining steps are run even if the step fails.
- Specify the **Timeout** in seconds.
- Select the **Form Submission Method** (HTTP method) of the request: **GET**, **POST**, **PUT** or **DELETE**.
- If you select **POST** or **PUT** method, you will be asked to choose the **Request Body Type** from the following options:
- **FORM:** If you select this, enter the **Request body** in a line-by-line format.
- **Text:** If you select this, enter the **Request body** in text format.
- **XML:** If you select this, enter the **Request body** in XML format.
- **JSON:** If you select this, enter the **Request body** in JSON format.
- Configure the **HTTP Request Headers** required to establish a connection with the API server.
- If the API requires authentication, select one of the following options. Choose **None** if no authentication is required.
- **Basic authentication:** Authenticates the REST API endpoint using basic credentials such as username and password.
- **Credential Manager:** Authenticates the REST API endpoint by selecting credentials from [Credential Manager](https://www.manageengine.com/products/applications_manager/help/credential-manager.html).
- **OAuth Token:** Authenticates the REST API endpoint using an [OAuth Provider](https://www.manageengine.com/products/applications_manager/help/oauth-provider.html).
- **Web Token:** Authenticates the REST API endpoint using a [Web Token](https://www.manageengine.com/products/applications_manager/help/web-tokens.html).
- Specify the list of **success status code(s)** that indicate successful response, separated by commas. **Example:** *202,200*
You can also provide the status code range separated with a colon. **Example:** *200:250*
- Specify the **Response Type** to be expected. For XML and JSON responses, you can choose specific values from the response to monitor in the [Response Details](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#response) tab of the monitor.
- Enable the **Add content check for response** checkbox if you wish to perform content check in the API response. Once enabled, perform the following steps:
- Specify the content that the API response **should contain** and/or **should not contain**.
- Enable the **Do case sensitive keyword search** checkbox if you wish to perform a content check for case-sensitive character strings.
- Enable the **Regular Expression** checkbox if you wish to perform a content check based on regular expressions. Refer [Regex Guide](https://www.manageengine.com/products/applications_manager/help/regular-expressions.html) for more information.
**Note:**
- Ensure that the content you try to match is present in the API response.
- The content search is case-sensitive. If you provide two or more words, the content match is performed for the words separately. Space character will be acting as the delimiter.
- For example, if you specify the content as '*applications manager*', the match is found for '*applications*' and '*manager*' separately. If you need the content match to be performed for the complete text, specify the two words in quotes, like *"applications manager"*.
- Select the **Response Format** (*Text*, *XML* or *JSON*) used to extract values from the response for [parameter forwarding](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#paramFwd).
- To extract values from the API response, add **parameters** as name-value pairs. Enter the value based on the response format:
- For ***TEXT***, provide value as regular expression.
- For ***JSON***, provide value as JSONPath expression.
- For ***XML*** provide value as XPath expression.
Refer [Parameter Forwarding](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#paramFwd) to know more.
- To extract a value from the response headers, enter a name and a regular expression in the **Response Header** field. The value can then be used in the next steps.
After entering all the above details, click **Save**.
5. Choose the **Monitor Group** from the combo box with which you want to associate REST API Sequence monitor (optional). You can choose multiple groups to associate your monitor.
6. Click **Add Monitor(s)**. Applications Manager starts monitoring the REST API sequence.
**Note:**
- A monitor can have a maximum of 25 steps.
- **Security/firewall requirement:** The API should be accessible from the machine where the Applications Manager server is running.
- **User privilege:** The required credentials should be provided to read the API response.
### Importing steps from a file
Instead of adding each step manually, you can import the API requests from a file and choose the ones you want to monitor. The following file types are supported:
| File type | Supported versions | File extension |
|---|---|---|
| HAR file | Recorded by any web browser | .har |
| Postman Collection | v2 and v2.1 | .json |
| OpenAPI / Swagger | OpenAPI 3.x and Swagger 2.0 | .json, .yaml, .yml |
**To import steps:**
1. In the **Add Monitor** page of the REST API Sequence monitor, click **Import Steps**.
2. Select the **File type**.
3. Click **Browse** and select the file, then click **Next**.
4. If the file uses values that it does not define, such as the base URL of the API or a variable, you are asked to enter them. Enter each value once and click **Apply and continue**. The value is applied to all the steps that use it. To use a value from the response of an earlier step, enter it as *${name}* (refer [Parameter Forwarding](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#paramFwd)). You can also click **Skip** and enter the values in each step later.
5. In **Select the API calls**, select the requests you want to monitor. You can change the **Step Name** of each selected request. Click **Import**. If a selected request uses a method other than GET, POST, PUT or DELETE, you are asked to confirm; the step is added, and you must choose a supported method before saving the monitor.
6. Check the imported steps and edit the steps marked in red (refer [Reviewing imported steps](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#reviewImport)). Then save the monitor.
**Note:** The maximum file size is 60 MB for a HAR file and 30 MB for a Postman Collection or an OpenAPI / Swagger file. Only the first 100 requests in a file are imported.
**HAR file**
A HAR file records the requests that your browser sends while you use a web application. To create one, open the developer tools of your browser (**F12**), go to the **Network** tab, perform the actions you want to monitor, then right-click the list of requests and select **Save all as HAR**. Refer [Generate HAR Files](https://www.manageengine.com/products/applications_manager/help/har-file.html) for the steps for each browser.
- Requests are added in the order the browser sent them.
- Only API requests are imported. Images, scripts, style sheets, fonts, and analytics or advertising requests are skipped. The number of skipped requests is shown after the import.
- Requests that failed while recording, for example with a 404 error, are also imported so that the monitor reports them.
- Browser cookies and session details are not imported. If the API requires you to be signed in, add credentials to the step, or add a login step and pass its token to the next steps using [parameter forwarding](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#paramFwd).
- The response type (*JSON*, *XML* or *Text*) is set from the recorded response.
**Postman Collection**
To export a collection from Postman, click **⋯** (More actions) next to the collection, select **Export**, choose **Collection v2.1** and click **Export**.
- Requests are imported in the same order as in the collection.
- Variables defined in the collection are replaced with their values. Variables defined outside the collection, such as in a Postman environment, are listed during import for you to enter.
- **Basic**, **Bearer Token** and **API Key** authentication are imported. Other types, such as OAuth 2.0, are not imported; select the credentials in the step after import.
- Request bodies are imported, except file uploads.
- Pre-request scripts and tests are not imported.
**OpenAPI / Swagger**
Each API operation in the file, for example *GET /users/{id}*, is listed as a request that you can add as a step.
- The server URL in the file is used as the base URL. If it is missing or incomplete, enter the base URL during import.
- Parameters use the example or default values given in the file. Parameters without a value are listed during import for you to enter.
- If a request body has no example in the file, a sample body is added. Replace its sample values with real values.
- **API Key**, **Basic** and **Bearer** authentication are listed during import for you to enter. OAuth 2.0 and OpenID Connect are not imported.
### Reviewing imported steps
After the import, steps that need your attention are marked in the step list. Hover over a marker to see what to do. Steps with red markers must be fixed before you can save the monitor.
| Marker | What it means and what to do | Must be fixed before saving |
|---|---|---|
| Method not supported | The request uses a method other than GET, POST, PUT or DELETE. Edit the step and select a supported method. | Yes |
| Incomplete URL | The URL does not start with *http://* or *https://*. Edit the step and enter the full URL. | Yes |
| Unresolved variable | The request contains a variable in the *{{variable}}* format, which is not replaced when the monitor runs. Replace it with the actual value, or with *${variable}* to use a value from an earlier step. | Yes |
| Replace sample value | The request body contains sample values, such as *string* or *0*. Edit the step and enter real values. | No |
| Session cookies removed | The cookies recorded in the browser were not imported. If the API needs a signed-in session, add credentials, or pass the token from a login step. | No |
| CSRF token copied | A security header such as *X-CSRF-Token* was copied from the recording and works only in that browser session. Pass it from an earlier step, or remove it. | No |
| Token may expire | The step uses a token copied from the file, and the step fails once the token expires. Use credentials, or pass the token from a login step. | No |
| Sign-in not imported | The authentication used in the file could not be imported. Edit the step and select the credentials. | No |
| Sent as URL-encoded form | The request body was a form with file uploads. It was imported as a regular form, without the files. The step works only if the API also accepts this form type. | No |
When you save the monitor, a message shows the first step that needs attention. Click **Edit step** to fix it.
### Parameter Forwarding
Parameter forwarding lets you pass a value from the response of one step to the steps that follow, for example a session token returned by a login API.
1. In the step that returns the value, add a parameter that extracts it. Use a regular expression for a *Text* response, an XPath expression for an *XML* response, or a JSONPath expression for a *JSON* response. You can also extract a value from the response headers using a regular expression.
2. In the later steps, enter *${ParameterName}* in the URL or request body where the value is needed.
When the monitor runs, *${ParameterName}* is replaced with the value extracted from the earlier response.


## Monitored Parameters
Go to the **Monitors Category View** by clicking the **Monitors** tab. Click on **REST API Sequence** under the **Web Server/Services** section. Displayed is the REST API Sequence Monitor's bulk configuration view distributed into three tabs:
- **Availability** tab gives the Availability history for the past 24 hours or 30 days.
- **Performance** tab gives the Health Status and events for the past 24 hours or 30 days.
- **List view** enables you to perform [bulk admin configurations](https://www.manageengine.com/products/applications_manager/help/bulk-config.html).
The following metrics are shown in the REST API Sequence monitor:
- [Performance Overview](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#overview)
- [Response Details](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#response)
### Performance Overview
| Parameter | Description |
|---|---|
| Average Response Time | Average time taken to obtain complete response of all the APIs in the sequence (in ms). |
| Transaction Time | Total time taken to complete all the transactions in the sequence (in ms). |
| Step Response Time | Total time taken to obtain response of the API in a recorded step (in ms). |
| Page Size | Total response size of the API in a recorded step (in bytes). |
### Response Details
| Parameter | Description |
|---|---|
| **REST API Sequence** | |
| Step Name | Name of the recorded step. |
| Response Time | Time taken to obtain response of the API in a recorded step (in ms). |
| DNS Time | Amount of time spent for resolving domain name for the request (in ms). |
| Connection Time | Amount of time spent for establishing TCP connection with server (in ms). |
| First Byte Time | Amount of time taken from when the connection to the server is established until the first response starts coming in for the API (in ms). |
| Download Time | Amount of time taken for receiving last byte of the response for the API (in ms). |
| Page Size | Total response size of the API in a recorded step (in bytes). |
| Response Code | The HTTP status code returned by the API, which shows whether the request was successful. The codes are grouped as follows:
- Informational responses (100 to 199)
- Successful responses (200 to 299)
- Redirection messages (300 to 399)
- Client error responses (400 to 499)
- Server error responses (500 to 599) |
| Response | Displays the response of the API obtained in the recorded step. You can also monitor specific values by defining custom attributes in the API response. [Learn more](https://www.manageengine.com/products/applications_manager/help/rest-api-sequence-monitoring-tools.html#custom) |
### Custom attributes in API response
To customize your own attributes to monitor specific values in the API response, go to the Response Details tab of the REST API Sequence monitor and select the Response icon. A pop-up window displaying the custom attribute option will open. Refer [Custom attributes](https://www.manageengine.com/products/applications_manager/help/rest-api-custom-attributes.html) to learn more.