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.

486 lines
15 KiB

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