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.

427 lines
13 KiB

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