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.

358 lines
11 KiB

  1. {% extends "front/base_docs.html" %}
  2. {% load compress staticfiles hc_extras %}
  3. {% block title %}REST API - {% site_name %}{% endblock %}
  4. {% block docs_content %}
  5. <h2>REST API</h2>
  6. <p>
  7. This is early days for healtchecks.io REST API. For now, there's API calls to:
  8. </p>
  9. <ul>
  10. <li><a href="#list-checks">List existing checks</a></li>
  11. <li><a href="#create-check">Create a new check</a></li>
  12. <li><a href="#update-check">Update an existing check</a></li>
  13. <li><a href="#pause-check">Pause monitoring of a check</a></li>
  14. </ul>
  15. <h2 class="rule">Authentication</h2>
  16. <p>Your requests to healtchecks.io REST API must authenticate using an
  17. API key. By default, an user account on {% site_name %} doesn't have
  18. an API key. You can create one in the <a href="{% url 'hc-profile' %}">Settings</a> page.
  19. </p>
  20. <p>The client can authenticate itself by sending an appropriate HTTP
  21. request header. The header's name should be <code>X-Api-Key</code> and
  22. its value should be your API key.
  23. </p>
  24. <p> Alternatively, for POST requests with a JSON request body,
  25. the client can include an <code>api_key</code> field in the JSON document.
  26. See below the "Create a check" section for an example.
  27. </p>
  28. <h2>API Requests</h2>
  29. <p>
  30. For POST requests, the {% site_name %} API expects request body to be
  31. a JSON document (<em>not</em> a <code>multipart/form-data</code> encoded
  32. form data).
  33. </p>
  34. <h2>API Responses</h2>
  35. <p>
  36. {% site_name %} uses HTTP status codes wherever possible.
  37. In general, 2xx class indicates success, 4xx indicates an client error,
  38. and 5xx indicates a server error.
  39. </p>
  40. <p>
  41. The response may contain a JSON document with additional data.
  42. </p>
  43. <!-- ********************************************************************** /-->
  44. <a class="section" name="list-checks">
  45. <h2 class="rule">List checks</h2>
  46. </a>
  47. <div class="api-path">GET {{ SITE_ROOT }}/api/v1/checks/</div>
  48. <p>
  49. Returns a list of checks. This API call takes no parameters and returns
  50. a JSON document with all checks in user's account.
  51. </p>
  52. <h3 class="api-section">Example Request</h3>
  53. {% include "front/snippets/list_checks_request.html" %}
  54. <h3 class="api-section">Example Response</h3>
  55. {% include "front/snippets/list_checks_response.html" %}
  56. <!-- ********************************************************************** /-->
  57. <a class="section" name="create-check">
  58. <h2 class="rule">Create a check</h2>
  59. </a>
  60. <div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/</div>
  61. <strong></strong>
  62. <p>
  63. Creates a new check and returns its ping URL.
  64. All request parameters are optional and will use their default
  65. values if omitted.
  66. </p>
  67. <p>This API call can be used to create both "simple" and "cron" checks.
  68. To create a "simple" check, specify the "timeout" parameter.
  69. To create a "cron" check, specify the "schedule" and "tz" parameters.
  70. </p>
  71. <h3 class="api-section">Request Parameters</h3>
  72. <table class="table">
  73. <tr>
  74. <th>name</th>
  75. <td>
  76. <p>string, optional, default value: ""</p>
  77. <p>Name for the new check.</p>
  78. </td>
  79. </tr>
  80. <tr>
  81. <th>tags</th>
  82. <td>
  83. <p>string, optional, default value: ""</p>
  84. <p>A space-delimited list of tags for the new check.</p>
  85. <p>Example:</p>
  86. <pre>{"tags": "reports staging"}</pre>
  87. </td>
  88. </tr>
  89. <tr>
  90. <th>timeout</th>
  91. <td>
  92. <p>number, optional, default value: {{ default_timeout }}.</p>
  93. <p>A number of seconds, the expected period of this check.</p>
  94. <p>Minimum: 60 (one minute), maximum: 604800 (one week).</p>
  95. <p>Example for 5 minute timeout:</p>
  96. <pre>{"kind": "simple", "timeout": 300}</pre>
  97. </td>
  98. </tr>
  99. <tr>
  100. <th>grace</th>
  101. <td>
  102. <p>number, optional, default value: {{ default_grace }}.</p>
  103. <p>A number of seconds, the grace period for this check.</p>
  104. <p>Minimum: 60 (one minute), maximum: 604800 (one week).</p>
  105. </td>
  106. </tr>
  107. <tr>
  108. <th>schedule</th>
  109. <td>
  110. <p>string, optional, default value: "* * * * *".</p>
  111. <p>A cron expression defining this check's schedule.</p>
  112. <p>If you specify both "timeout" and "schedule" parameters,
  113. "timeout" will be ignored and "schedule" will be used.</p>
  114. <p>Example for a check running every half-hour:</p>
  115. <pre>{"schedule": "0,30 * * * *"}</pre>
  116. </td>
  117. </tr>
  118. <tr>
  119. <th>tz</th>
  120. <td>
  121. <p>string, optional, default value: "UTC".</p>
  122. <p>Server's timezone. This setting only has effect in combination
  123. with the "schedule" paremeter.</p>
  124. <p>Example:</p>
  125. <pre>{"tz": "Europe/Riga"}</pre>
  126. </td>
  127. </tr>
  128. <tr>
  129. <th>channels</th>
  130. <td>
  131. <p>string, optional, default value: ""</p>
  132. <p>By default, if a check is created through API, no notification
  133. channels are assigned to it. So, when the check goes up or down,
  134. no notifications would be sent. Set this field to a special value "*"
  135. to automatically assign all existing notification channels.</p>
  136. </td>
  137. </tr>
  138. <tr>
  139. <th>unique</th>
  140. <td>
  141. <p>array of string values, optional, default value: [].</p>
  142. <p>Before creating a check, look for existing checks, filtered
  143. by fields listed in <code>unique</code>. If a matching check is
  144. found, return it with HTTP status code 200. If no matching check is
  145. found, proceed as normal: create a check and return it
  146. with HTTP status code 201.</p>
  147. <p>The accepted values are: <code>name</code>,
  148. <code>tags</code>, <code>timeout</code> and <code>grace</code>.</p>
  149. <p>Example:</p>
  150. <pre>{"name": "Backups", unique: ["name"]}</pre>
  151. <p>In this example, if a check named "Backups" exists, it will
  152. be returned. Otherwise, a new check will be created and
  153. returned.</p>
  154. </td>
  155. </tr>
  156. </table>
  157. <h3 class="api-section">Response Codes</h3>
  158. <table class="table">
  159. <tr>
  160. <th>201 Created</th>
  161. <td>Returned if the check was successfully created.</td>
  162. </tr>
  163. <tr>
  164. <th>200 OK</th>
  165. <td>Returned if the <code>unique</code> parameter was used and an
  166. existing check was matched.</td>
  167. </tr>
  168. <tr>
  169. <th>403 Forbidden</th>
  170. <td>Returned if the account's check limit has been reached.
  171. For free accounts, the limit is 20 checks per account.</td>
  172. </tr>
  173. </table>
  174. <h3 class="api-section">Example Request</h3>
  175. {% include "front/snippets/create_check_request_a.html" %}
  176. <br>
  177. <p>Or, alternatively:</p>
  178. {% include "front/snippets/create_check_request_b.html" %}
  179. <h3 class="api-section">Example Response</h3>
  180. {% include "front/snippets/create_check_response.html" %}
  181. <!-- ********************************************************************** /-->
  182. <a class="section" name="update-check">
  183. <h2 class="rule">Update an existing check</h2>
  184. </a>
  185. <div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/&lt;code&gt;</div>
  186. <strong></strong>
  187. <p>
  188. Updates an existing check. All request parameters are optional. The
  189. check is updated only with the supplied request parameters.
  190. If any parameter is omitted, its value is left unchanged.
  191. </p>
  192. <h3 class="api-section">Request Parameters</h3>
  193. <table class="table">
  194. <tr>
  195. <th>name</th>
  196. <td>
  197. <p>string, optional.</p>
  198. <p>Name for the check.</p>
  199. </td>
  200. </tr>
  201. <tr>
  202. <th>tags</th>
  203. <td>
  204. <p>string, optional.</p>
  205. <p>A space-delimited list of tags for the check.</p>
  206. <p>Example:</p>
  207. <pre>{"tags": "reports staging"}</pre>
  208. </td>
  209. </tr>
  210. <tr>
  211. <th>timeout</th>
  212. <td>
  213. <p>number, optional.</p>
  214. <p>A number of seconds, the expected period of this check.</p>
  215. <p>Minimum: 60 (one minute), maximum: 604800 (one week).</p>
  216. <p>Example for 5 minute timeout:</p>
  217. <pre>{"kind": "simple", "timeout": 300}</pre>
  218. </td>
  219. </tr>
  220. <tr>
  221. <th>grace</th>
  222. <td>
  223. <p>number, optional.</p>
  224. <p>A number of seconds, the grace period for this check.</p>
  225. <p>Minimum: 60 (one minute), maximum: 604800 (one week).</p>
  226. </td>
  227. </tr>
  228. <tr>
  229. <th>schedule</th>
  230. <td>
  231. <p>string, optional.</p>
  232. <p>A cron expression defining this check's schedule.</p>
  233. <p>If you specify both "timeout" and "schedule" parameters,
  234. "timeout" will be ignored and "schedule" will be used.</p>
  235. <p>Example for a check running every half-hour:</p>
  236. <pre>{"schedule": "0,30 * * * *"}</pre>
  237. </td>
  238. </tr>
  239. <tr>
  240. <th>tz</th>
  241. <td>
  242. <p>string, optional.</p>
  243. <p>Server's timezone. This setting only has effect in combination
  244. with the "schedule" paremeter.</p>
  245. <p>Example:</p>
  246. <pre>{"tz": "Europe/Riga"}</pre>
  247. </td>
  248. </tr>
  249. <tr>
  250. <th>channels</th>
  251. <td>
  252. <p>string, optional.</p>
  253. <p>Set this field to a special value "*"
  254. to automatically assign all existing notification channels.
  255. </p>
  256. <p>Set this field to a special value "" (empty string)
  257. to automatically <em>unassign</em> all notification channels.
  258. </p>
  259. </td>
  260. </tr>
  261. </table>
  262. <h3 class="api-section">Response Codes</h3>
  263. <table class="table">
  264. <tr>
  265. <th>200 OK</th>
  266. <td>Returned if the check was successfully updated.</td>
  267. </tr>
  268. </table>
  269. <h3 class="api-section">Example Request</h3>
  270. {% include "front/snippets/update_check_request_a.html" %}
  271. <br>
  272. <p>Or, alternatively:</p>
  273. {% include "front/snippets/update_check_request_b.html" %}
  274. <h3 class="api-section">Example Response</h3>
  275. {% include "front/snippets/create_check_response.html" %}
  276. <!-- ********************************************************************** /-->
  277. <a class="section" name="pause-check">
  278. <h2 class="rule">Pause Monitoring of a Check</h2>
  279. </a>
  280. <div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/&lt;uuid&gt;/pause</div>
  281. <strong></strong>
  282. <p>
  283. Disables monitoring for a check, without removing it. The check goes
  284. into a "paused" state. You can resume monitoring of the check by pinging
  285. it.
  286. </p>
  287. <p>
  288. This API call has no request parameters.
  289. </p>
  290. <h3 class="api-section">Example Request</h3>
  291. {% include "front/snippets/pause_check_request.html" %}
  292. <p>Note: the <code>--data ""</code> argument forces curl to send a
  293. <code>Content-Length</code> request header even though the request body
  294. is empty. For HTTP POST requests, the <code>Content-Length</code> header
  295. is sometimes required by some network proxies and web servers.
  296. </p>
  297. <h3 class="api-section">Example Response</h3>
  298. {% include "front/snippets/pause_check_response.html" %}
  299. {% endblock %}
  300. {% block scripts %}
  301. {% compress js %}
  302. <script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
  303. <script src="{% static 'js/bootstrap.min.js' %}"></script>
  304. <script src="{% static 'js/clipboard.min.js' %}"></script>
  305. <script src="{% static 'js/snippet-copy.js' %}"></script>
  306. {% endcompress %}
  307. {% endblock %}