# API

{% hint style="info" %}
Monitor ID's can be any unique arbitrary string, but we recommend UUIDs.\
<https://www.uuidgenerator.net/version4>&#x20;

*For the API calls, ensure it is properly URL encoded.*&#x20;
{% endhint %}

## Get monitor info

<mark style="color:green;">`GET`</mark> `/(monitor-id)`

Returns the information on the specified monitor.&#x20;

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
    "name": "Monitor 1",
    "id": "8ad4a5dc-5481-4973-aa99-e0183904528d",
    "interval": 2880,
    "message": null,
    "alert_ping": null,
    "alert_timeout": null,
    "timeout": "2024-08-10T22:07:55.173Z"
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "status": "error",
  "message": "Invalid request"
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "status": "error",
  "message": "No match found"
}
```

{% endtab %}
{% endtabs %}

## Ping monitor&#x20;

<mark style="color:green;">`GET`</mark> `/(monitor-id)/ping`

Records the ping event.&#x20;

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "success",
  "message": "Operation completed successfully.",
  "data": {
    "timeout": "2024-08-10T22:07:55.173Z" 
  }
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "status": "error",
  "message": "Invalid request"
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "status": "error",
  "message": "No match found"
} 
```

{% endtab %}

{% tab title="500" %}

```json
{
  "status": "error",
  "message": "Failed to update monitor"
}
```

{% endtab %}
{% endtabs %}

## Test monitor alerting

<mark style="color:green;">`GET`</mark> `/(monitor-id)/test`

Performs alerting on both ping and timeout.&#x20;

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "success",
  "message": "Test alert sent"
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "status": "error",
  "message": "Invalid request"
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "status": "error",
  "message": "Monitor not found"
} 
```

{% endtab %}

{% tab title="500" %}

```json
{
  "status": "error",
  "message": "Failed to send alert"
}
```

{% endtab %}
{% endtabs %}

## Add monitor&#x20;

<mark style="color:green;">`POST`</mark> `/`

Create a new monitor

**Body**

<table><thead><tr><th width="201">Name</th><th width="127">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>id</code></td><td>string</td><td>( optional ). If unspecified, monitor instance is assigned a UUID</td></tr><tr><td><code>name</code></td><td>string</td><td>Name of the monitor</td></tr><tr><td><code>interval</code></td><td>number</td><td>Timeout interval ( in mins ) </td></tr><tr><td><code>message</code></td><td>string</td><td>The message to send</td></tr><tr><td><code>alert_ping</code></td><td>string</td><td>The alerting profile to use</td></tr><tr><td><code>alert_timeout</code></td><td>string</td><td>The alerting profile to use for timeout events</td></tr></tbody></table>

Example;

```json
{
    "name": "Test",
    "interval": 2880,
    "message": "A new booking was made",
    "alert_ping": "sygnal-pushbullet",
    "alert_timeout": "sygnal-pushbullet"
}
```

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "success",
  "message": "Test alert sent",
  "data": {
    "id": "8ad4a5dc-5481-4973-aa99-e0183904528d" 
  }
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "status": "error",
  "message": "Invalid request"
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "status": "error",
  "message": "Monitor not found"
} 
```

{% endtab %}

{% tab title="500" %}

```json
{
  "status": "error",
  "message": "Failed to send alert"
}
```

{% endtab %}
{% endtabs %}

## Update monitor&#x20;

<mark style="color:green;">`PATCH`</mark> `/(monitor-id)`

Update a monitor

**Body**

<table><thead><tr><th width="201">Name</th><th width="127">Type</th><th>Description</th></tr></thead><tbody><tr><td><code>name</code></td><td>string</td><td>Name of the monitor</td></tr><tr><td><code>interval</code></td><td>number</td><td>Timeout interval ( in mins ) </td></tr><tr><td><code>message</code></td><td>string</td><td>The message to send</td></tr><tr><td><code>alert_ping</code></td><td>string</td><td>The alerting profile to use</td></tr><tr><td><code>alert_timeout</code></td><td>string</td><td>The alerting profile to use for timeout events</td></tr></tbody></table>

**Response**

{% tabs %}
{% tab title="200" %}

```json
{
  "status": "success",
  "message": "Monitor updated" 
}
```

{% endtab %}

{% tab title="400" %}

```json
{
  "status": "error",
  "message": "Invalid request"
}
```

{% endtab %}

{% tab title="404" %}

```json
{
  "status": "error",
  "message": "Monitor not found"
} 
```

{% endtab %}

{% tab title="500" %}

```json
{
  "status": "error",
  "message": "Failed to send alert"
}
```

{% endtab %}
{% endtabs %}
