Skip to content

Notifications

TechieGuy12 edited this page Jul 12, 2024 · 16 revisions

Notifications allow File Watcher to send out an API request to an endpoint once a change has occurred. All notifications for a watch are specified under the <notifications> element within the <watch> element.

Two child elements can be specified under the <notifications> element: <waittime> and <notification>.

The <waittime> element specifies the number of milliseconds between sending requests. This applies to all notifications listed under the same <notifications> element. The default, and lowest amount of time, is 30,000 milliseconds (30 seconds). If you specify anything lower than 30,000 milliseconds, then the default of 30,000 will be used. This value is used to ensure an endpoint isn't overloaded with requests if many changes are detected. All changes that will be sent to the same notification endpoint, will be queued and sent as one request to that endpoint.

The <notification> element specifies the details of the request, which are outlined in the following sections.

Structure

<watches>
    <watch>
        <notifications>
            <waittime></waittime>
            <variables></variables>            
            <notification>
                <url></url>     
                <method></method>
                <triggers>
                    <trigger></trigger>
                </triggers>
                <data>
                    <headers>
                        <header>
                            <name></name>
                            <value></value>
                        </header>
                    </headers>
                    <body></body>
                    <type></type>            
                </data>
                <variables></variables>                
            </notification>
        </notifications>
    </watch>
</watches>

Notifications Elements

A <notifications> element can contain the following child elements:

Element Description
variables (Optional) (Version 2.x or higher.) The variables for all child steps. For more information, see Variables.
notification A notification to send to an endpoint.

Notification Elements

To send a notification request to an endpoint, the following information can be specified:

Element Description
url The URL to connect to for the notification. Can include Placeholders
method The HTTP method to use for the request. Default: POST
triggers The triggers for the notification. For more information, see Triggers.
data (Optional) Data to send for the request.
variables (Optional) (Version 2.x or higher.) The variables for all child steps. For more information, see Variables.

URL

This is the valid URL to the endpoint and is specified using the <url> element.

Method

The <method> element specifies the HTTP method used in the request to the endpoint. The valid values are:

Method
POST
GET
PUT
DELETE

Note: The method names are case-sensitive, so they must be added to the configuration file exactly as shown in the table above.

The default value for the <method> element is POST.

Triggers

Information about the valid triggers, can be found on the Triggers page.

Data

The <data> element contains information that is sent to the endpoint. This element contains the <headers>, <body>, and <type> child elements to provide details about the data sent with the request.

Headers

The <headers> element allows you to specify various headers to include in the request. Each header is specified within a <header> child element, and contains a <name> and <value> pair of elements.

The <value> element can include Placeholders.

For example:

<headers>
    <header>
        <name>HeaderName</name>
        <value>HeaderValue</value>
    </header>
</headers>

Body

The <body> element provides information to send in the request. You can specify any message in the <body> element, or you can use the [message] placeholder to have File Watcher write the change message into the body.

The <body> element can include Placeholders.

Type

The <type> element indicates the type of request is to be sent to the endpoint. The valid values are:

Type
JSON
XML

Note: The type names are case-sensitive, so they must be added to the configuration file exactly as shown in the table above.

The default value for the <type> element is JSON.

Examples

Send a notification (every 60 seconds) to a Gotify endpoint when a file is created or changed in C:\Temp.

Note that both the Gotify URL and key are retrieved from two environment variables.

<watches>
    <watch>
        <path>C:\Temp</path>
        <notifications>
            <waittime>60000</waittime>
            <notification>
                <url>[env:gotify_url]/message</url>
                <method>POST</method>
                <triggers>
                    <trigger>Change</trigger>
                    <trigger>Create</trigger>
                </triggers>
                <data>
                    <headers>
                        <header>
                            <name>X-Gotify-Key</name>
                            <value>[env:gotify_key]</value>
                        </header>
                    </headers>
                    <body>
                        {
                            "message": "[message]",
                            "priority": 7,
                            "title": "File Watcher"
                        }            
                    </body>
                </data>
            </notification>
        </notifications>
    </watch>
</watches>