# Custom attributes in REST API Custom attributes in the REST API and REST API Sequence monitors are the attributes that are fetched from the XML/JSON response of the REST API. To fetch these attributes, the XSLT Code or JSON Schema is defined and used to retrieve the attribute from the response, which can then be monitored. You define custom attributes in the **Response Details** tab of the monitor. You can pick the values you want from the last API response, or write the XSLT code or JSON Schema yourself. Refer to the following topics: - [Picking values from the response](https://www.manageengine.com/products/applications_manager/help/rest-api-custom-attributes.html#picker) - [Testing the schema](https://www.manageengine.com/products/applications_manager/help/rest-api-custom-attributes.html#test) - [XML response](https://www.manageengine.com/products/applications_manager/help/rest-api-custom-attributes.html#xml) - [JSON response](https://www.manageengine.com/products/applications_manager/help/rest-api-custom-attributes.html#json) **Note:** Reports cannot be generated if the custom attributes monitored are in String format. ## Picking values from the response Instead of writing the paths yourself, you can pick the values to monitor from the last API response. 1. Go to the **Response Details** tab of the monitor. 2. Click **Add/View JSON Schema** for a JSON response, or **Add/View XSLT Code** for an XML response. The last response is shown as a tree. 3. Click the icon next to a value (for XML, an element or attribute) to add it as an attribute. The matching line is added to the schema box. Click the icon again to remove the attribute. 4. Rename the attributes in the schema box if required. 5. Click **Test** to check the attributes (refer [Testing the schema](https://www.manageengine.com/products/applications_manager/help/rest-api-custom-attributes.html#test)), then click **Update JSON Schema** or **Update XSLT Code** to save. - Each attribute is named after the path of its value, for example *servers[1].status*. If two attributes get the same name, a number is added to the second one, for example *_2*. - Lines already in the schema box are kept. You can still type or edit lines yourself, and the tree is updated to match. - For an XML response, the XSLT code is created for you when you pick the first value. - Use **Formatted** and **Raw** to switch between the tree and the plain response. Use the search box to find a key or value. **Values that cannot be picked** Some values cannot be monitored. Their icon is disabled; hover over it to see the reason. | Value | Reason | |---|---| | An object, array or XML element that contains other values | Only single values and XML attributes can be monitored. Expand it and pick a value inside. | | A value inside a nested array, or directly inside an array at the top of the response | The JSON Schema cannot reach it. | | A JSON key that contains *[*, *]*, *::*, quotes or *_sep_*, or starts or ends with a space | The JSON Schema cannot reach it. | **Note:** - *null* values can be picked and are collected as the text *null*. - Values longer than 500 characters can be picked but may not be stored. - The tree is not shown when the response is larger than 2 MB, is not valid JSON or XML, or contains only a single value. In these cases, write the schema manually as described in [XML response](https://www.manageengine.com/products/applications_manager/help/rest-api-custom-attributes.html#xml) or [JSON response](https://www.manageengine.com/products/applications_manager/help/rest-api-custom-attributes.html#json). ## Testing the schema Click **Test** to try the schema on the last collected response before you save it. Nothing is saved. The **Test** window lists each **Attribute** with its **Value** and **Type** (*Numeric*, *Float* or *String*), in the order of the schema. These are the attributes the next poll collects. | Message | What to do | |---|---| | Data collection yet to start | Wait for the first poll of the monitor, then test again. | | The schema did not produce any attribute | Check the paths in the schema against the response. | | The XSLT could not be applied | Check that the XSLT code is complete and contains **. | Before you test or update, the schema is checked: - Each attribute name must be unique. Names that differ only in upper and lower case count as the same name. - In a JSON Schema, each line must be in the format *Name::path*. Blank lines and extra spaces are removed for you. - XSLT code must start with * attributename: ``` To define specific attributes to be monitored, ensure that the following conditions are met: - The output method should be of type 'text'. ** - The final output of the path to fetch the attribute should be of the format *attributeName:attributeValue*. **Example:** *Days:* would create an attribute '***Days***' whose value will be the value of the ** tag present in the API Response. When you click **Update XSLT Code**, the defined attributes will be fetched and monitored along with their corresponding values in the table below, which can then be used to configure alarms, thresholds, and actions, and generate reports as well. **Example:** Let us consider the following API response code of XML format which will be displayed upon accessing the **Response Details** tab: ```xml 256 18 10235 ``` Let's say you want to monitor the **Response Code** and **Response Time** attributes from the API response. To do so, click **Add/View XSLT Code** and define the attributes in the following format: ```xml ResponseCode: ResponseTime: ``` where, - ****** refers to the output method of XSLT. - ****** selects the complete XML. - ***ResponseCode:*** refers to the path to fetch attribute, in which, - ***ResponseCode*** is the name of the attribute. - ***xml/result*** is used to traverse through the nodes. Here we are selecting the *result* node which is inside the *xml* node. - ***response/@response-code*** is used to select the attribute from the node. Here we are selecting the *response-code* attribute from the *response* node. Similarly, to fetch the *response* node value, we can define it as *xml/result/response* in the path which will fetch the *response* node value. When you click **Update XSLT Code**, the attributes *ResponseCode* and *ResponseTime* will be monitored along with their corresponding values in the table, which will then be used to configure alarms, thresholds, and actions, and generate reports as well. ![Applications Manager Custom attributes in REST API: Monitoring custom attributes via XSLT code](https://www.manageengine.com/products/applications_manager/help/images/custom-attributes-xml.png) ## JSON response If the response is of the JSON type, you can define specific values to be monitored using the JSON Schema. To do so, select ***JSON*** as the **Response Type** while adding/editing the monitor. Then click **Add/View JSON Schema** in the **Response Details** tab of the monitor and define the attributes to be monitored in the following format: **Syntax for JSON Schema** ```text :: ``` To define specific attributes to be monitored, ensure that the following conditions are met: - The attribute should be defined as *attributeName::attributeValue*. **Example:** *Temperature::response.weather.temperature* would create an attribute ***Temperature*** whose value will be the value of the *temperature* variable present in the API Response. - If the JSON key contains a dot(.), then it should be replaced with ***_sep_***. This should be done for all the individual keys which contain dot(.) in it. - In case of multiple JSON Schemas, they should be defined by using new line as the delimiter. When you click **Update JSON Schema**, the defined attributes will be fetched and monitored along with their corresponding values in the table below, which can then be used to configure alarms, thresholds, and actions, and generate reports as well. **Example:** Let us consider the following API response code of JSON format which will be shown upon accessing the **Response Details** tab: ```json { "response": { "result": [ { "responsecode": "200", "responsetime": "371 ms", "responsetimeinms": "371", "httpresponse": "OK", "httpmessage": "resource is up" } ] } } ``` Let's say you want to monitor the **Response Code** and **Response Message** attributes from the API response. To do so, click **Add/View JSON Schema** and define the attributes in the following format: ```text Response Code::response.result[0].responsecode Response Message::response.result[0].httpmessage ``` where, - ***Response Code*** is the name we are giving for the attribute. - ***response.result[0].responsecode*** refers to the path used to fetch attribute in which, - ***response.result*** is the keyname used to traverse through the object from the JSON array. Here we are selecting the *result* object which is inside of the *response* object. - ***result[0]*** is the array index used to specify the object from the JSON array. - ***responsecode*** is used to select the attribute from the JSON array. Here we are selecting *responsecode* attribute from *result* object present under the *response* object. Similarly, to fetch *response* object values, we can define as *response.result[0]* in the path which will fetch the *response* object values. When you click **Update JSON Schema**, the attributes *Response Code* and *Response Message* will be monitored along with their corresponding values in the table, which can then be used to configure alarms, thresholds, actions, and generate reports as well. ![Applications Manager Custom attributes in REST API: Monitoring custom attributes via JSON Schema](https://www.manageengine.com/products/applications_manager/help/images/custom-attributes-json.png)