You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

347 lines
11 KiB

{% extends "front/base_docs.html" %}
{% load compress staticfiles hc_extras %}
{% block title %}REST API - {% site_name %}{% endblock %}
{% block docs_content %}
<h2>REST API</h2>
<p>
This is early days for healtchecks.io REST API. For now, there's API calls to:
</p>
<ul>
<li><a href="#list-checks">List existing checks</a></li>
<li><a href="#create-check">Create a new check</a></li>
<li><a href="#update-check">Update an existing check</a></li>
<li><a href="#pause-check">Pause monitoring of a check</a></li>
</ul>
<h2 class="rule">Authentication</h2>
<p>Your requests to healtchecks.io REST API must authenticate using an
API key. By default, an user account on {% site_name %} doesn't have
an API key. You can create one in the <a href="{% url 'hc-profile' %}">Settings</a> page.
</p>
<p>The client can authenticate itself by sending an appropriate HTTP
request header. The header's name should be <code>X-Api-Key</code> and
its value should be your API key.
</p>
<p> Alternatively, for POST requests with a JSON request body,
the client can include an <code>api_key</code> field in the JSON document.
See below the "Create a check" section for an example.
</p>
<h2 class="rule">API Requests</h2>
<p>
For POST requests, the {% site_name %} API expects request body to be
a JSON document (<em>not</em> a <code>multipart/form-data</code> encoded
form data).
</p>
<h2 class="rule">API Responses</h2>
<p>
{% site_name %} uses HTTP status codes wherever possible.
In general, 2xx class indicates success, 4xx indicates an client error,
and 5xx indicates a server error.
</p>
<p>
The response may contain a JSON document with additional data.
</p>
<!-- ********************************************************************** /-->
<a class="section" name="list-checks">
<h2 class="rule">List checks</h2>
</a>
<div class="api-path">GET {{ SITE_ROOT }}/api/v1/checks/</div>
<p>
Returns a list of checks. This API call takes no parameters and returns
a JSON document with all checks in user's account.
</p>
<h3 class="api-section">Example Request</h3>
{% include "front/snippets/list_checks_request.html" %}
<h3 class="api-section">Example Response</h3>
{% include "front/snippets/list_checks_response.html" %}
<!-- ********************************************************************** /-->
<a class="section" name="create-check">
<h2 class="rule">Create a check</h2>
</a>
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/</div>
<strong></strong>
<p>
Creates a new check and returns its ping URL.
All request parameters are optional and will use their default
values if omitted.
</p>
<p>This API call can be used to create both "simple" and "cron" checks.
To create a "simple" check, specify the "timeout" parameter.
To create a "cron" check, specify the "schedule" and "tz" parameters.
</p>
<h3 class="api-section">Request Parameters</h3>
<table class="table">
<tr>
<th>name</th>
<td>
<p>string, optional, default value: ""</p>
<p>Name for the new check.</p>
</td>
</tr>
<tr>
<th>tags</th>
<td>
<p>string, optional, default value: ""</p>
<p>A space-delimited list of tags for the new check.</p>
<p>Example:</p>
<pre>{"tags": "reports staging"}</pre>
</td>
</tr>
<tr>
<th>timeout</th>
<td>
<p>number, optional, default value: {{ default_timeout }}.</p>
<p>A number of seconds, the expected period of this check.</p>
<p>Minimum: 60 (one minute), maximum: 604800 (one week).</p>
<p>Example for 5 minute timeout:</p>
<pre>{"kind": "simple", "timeout": 300}</pre>
</td>
</tr>
<tr>
<th>grace</th>
<td>
<p>number, optional, default value: {{ default_grace }}.</p>
<p>A number of seconds, the grace period for this check.</p>
<p>Minimum: 60 (one minute), maximum: 604800 (one week).</p>
</td>
</tr>
<tr>
<th>schedule</th>
<td>
<p>string, optional, default value: "* * * * *".</p>
<p>A cron expression defining this check's schedule.</p>
<p>If you specify both "timeout" and "schedule" parameters,
"timeout" will be ignored and "schedule" will be used.</p>
<p>Example for a check running every half-hour:</p>
<pre>{"schedule": "0,30 * * * *"}</pre>
</td>
</tr>
<tr>
<th>tz</th>
<td>
<p>string, optional, default value: "UTC".</p>
<p>Server's timezone. This setting only has effect in combination
with the "schedule" paremeter.</p>
<p>Example:</p>
<pre>{"tz": "Europe/Riga"}</pre>
</td>
</tr>
<tr>
<th>channels</th>
<td>
<p>string, optional, default value: ""</p>
<p>By default, if a check is created through API, no notification
channels are assigned to it. So, when the check goes up or down,
no notifications would be sent. Set this field to a special value "*"
to automatically assign all existing notification channels.</p>
</td>
</tr>
<tr>
<th>unique</th>
<td>
<p>array of string values, optional, default value: [].</p>
<p>Before creating a check, look for existing checks, filtered
by fields listed in <code>unique</code>. If a matching check is
found, return it with HTTP status code 200. If no matching check is
found, proceed as normal: create a check and return it
with HTTP status code 201.</p>
<p>The accepted values are: <code>name</code>,
<code>tags</code>, <code>timeout</code> and <code>grace</code>.</p>
<p>Example:</p>
<pre>{"name": "Backups", unique: ["name"]}</pre>
<p>In this example, if a check named "Backups" exists, it will
be returned. Otherwise, a new check will be created and
returned.</p>
</td>
</tr>
</table>
<h3 class="api-section">Response Codes</h3>
<table class="table">
<tr>
<th>201 Created</th>
<td>Returned if the check was successfully created.</td>
</tr>
<tr>
<th>200 OK</th>
<td>Returned if the <code>unique</code> parameter was used and an
existing check was matched.</td>
</tr>
</table>
<h3 class="api-section">Example Request</h3>
{% include "front/snippets/create_check_request_a.html" %}
<br>
<p>Or, alternatively:</p>
{% include "front/snippets/create_check_request_b.html" %}
<h3 class="api-section">Example Response</h3>
{% include "front/snippets/create_check_response.html" %}
<!-- ********************************************************************** /-->
<a class="section" name="update-check">
<h2 class="rule">Update an existing check</h2>
</a>
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/&lt;code&gt;</div>
<strong></strong>
<p>
Updates an existing check. All request parameters are optional. The
check is updated only with the supplied request parameters.
If any parameter is omitted, its value is left unchanged.
</p>
<h3 class="api-section">Request Parameters</h3>
<table class="table">
<tr>
<th>name</th>
<td>
<p>string, optional.</p>
<p>Name for the check.</p>
</td>
</tr>
<tr>
<th>tags</th>
<td>
<p>string, optional.</p>
<p>A space-delimited list of tags for the check.</p>
<p>Example:</p>
<pre>{"tags": "reports staging"}</pre>
</td>
</tr>
<tr>
<th>timeout</th>
<td>
<p>number, optional.</p>
<p>A number of seconds, the expected period of this check.</p>
<p>Minimum: 60 (one minute), maximum: 604800 (one week).</p>
<p>Example for 5 minute timeout:</p>
<pre>{"kind": "simple", "timeout": 300}</pre>
</td>
</tr>
<tr>
<th>grace</th>
<td>
<p>number, optional.</p>
<p>A number of seconds, the grace period for this check.</p>
<p>Minimum: 60 (one minute), maximum: 604800 (one week).</p>
</td>
</tr>
<tr>
<th>schedule</th>
<td>
<p>string, optional.</p>
<p>A cron expression defining this check's schedule.</p>
<p>If you specify both "timeout" and "schedule" parameters,
"timeout" will be ignored and "schedule" will be used.</p>
<p>Example for a check running every half-hour:</p>
<pre>{"schedule": "0,30 * * * *"}</pre>
</td>
</tr>
<tr>
<th>tz</th>
<td>
<p>string, optional.</p>
<p>Server's timezone. This setting only has effect in combination
with the "schedule" paremeter.</p>
<p>Example:</p>
<pre>{"tz": "Europe/Riga"}</pre>
</td>
</tr>
<tr>
<th>channels</th>
<td>
<p>string, optional.</p>
<p>Set this field to a special value "*"
to automatically assign all existing notification channels.
</p>
<p>Set this field to a special value "" (empty string)
to automatically <em>unassign</em> all notification channels.
</p>
</td>
</tr>
</table>
<h3 class="api-section">Response Codes</h3>
<table class="table">
<tr>
<th>200 OK</th>
<td>Returned if the check was successfully updated.</td>
</tr>
</table>
<h3 class="api-section">Example Request</h3>
{% include "front/snippets/update_check_request_a.html" %}
<br>
<p>Or, alternatively:</p>
{% include "front/snippets/update_check_request_b.html" %}
<h3 class="api-section">Example Response</h3>
{% include "front/snippets/create_check_response.html" %}
<!-- ********************************************************************** /-->
<a class="section" name="pause-check">
<h2 class="rule">Pause Monitoring of a Check</h2>
</a>
<div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/&lt;uuid&gt;/pause</div>
<strong></strong>
<p>
Disables monitoring for a check, without removing it. The check goes
into a "paused" state. You can resume monitoring of the check by pinging
it.
</p>
<p>
This API call has no request parameters.
</p>
<h3 class="api-section">Example Request</h3>
{% include "front/snippets/pause_check_request.html" %}
<h3 class="api-section">Example Response</h3>
{% include "front/snippets/pause_check_response.html" %}
{% endblock %}
{% block scripts %}
{% compress js %}
<script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
<script src="{% static 'js/bootstrap.min.js' %}"></script>
<script src="{% static 'js/clipboard.min.js' %}"></script>
<script src="{% static 'js/snippet-copy.js' %}"></script>
{% endcompress %}
{% endblock %}