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.

500 lines
16 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>desc</th>
  162. <td>
  163. <p>string, optional.</p>
  164. <p>Description for the check.</p>
  165. </td>
  166. </tr>
  167. <tr>
  168. <th>timeout</th>
  169. <td>
  170. <p>number, optional, default value: {{ default_timeout }}.</p>
  171. <p>A number of seconds, the expected period of this check.</p>
  172. <p>Minimum: 60 (one minute), maximum: 2592000 (30 days).</p>
  173. <p>Example for 5 minute timeout:</p>
  174. <pre>{"kind": "simple", "timeout": 300}</pre>
  175. </td>
  176. </tr>
  177. <tr>
  178. <th>grace</th>
  179. <td>
  180. <p>number, optional, default value: {{ default_grace }}.</p>
  181. <p>A number of seconds, the grace period for this check.</p>
  182. <p>Minimum: 60 (one minute), maximum: 2592000 (30 days).</p>
  183. </td>
  184. </tr>
  185. <tr>
  186. <th>schedule</th>
  187. <td>
  188. <p>string, optional, default value: "* * * * *".</p>
  189. <p>A cron expression defining this check's schedule.</p>
  190. <p>If you specify both "timeout" and "schedule" parameters,
  191. "timeout" will be ignored and "schedule" will be used.</p>
  192. <p>Example for a check running every half-hour:</p>
  193. <pre>{"schedule": "0,30 * * * *"}</pre>
  194. </td>
  195. </tr>
  196. <tr>
  197. <th>tz</th>
  198. <td>
  199. <p>string, optional, default value: "UTC".</p>
  200. <p>Server's timezone. This setting only has effect in combination
  201. with the "schedule" paremeter.</p>
  202. <p>Example:</p>
  203. <pre>{"tz": "Europe/Riga"}</pre>
  204. </td>
  205. </tr>
  206. <tr>
  207. <th>channels</th>
  208. <td>
  209. <p>string, optional</p>
  210. <p>By default, if a check is created through API, no notification
  211. channels (integrations) are assigned to it.
  212. So, when the check goes up or down, no notifications will get
  213. sent.</p>
  214. <p>Set this field to a special value "*"
  215. to automatically assign all existing integrations.</p>
  216. <p>To assign specific integrations, use a comma-separated
  217. list of integration identifiers. Use the
  218. <a href="#list-channels">Get a List of Existing Integrations</a>
  219. call to look up integration identifiers.
  220. </p>
  221. </td>
  222. </tr>
  223. <tr>
  224. <th>unique</th>
  225. <td>
  226. <p>array of string values, optional, default value: [].</p>
  227. <p>Before creating a check, look for existing checks, filtered
  228. by fields listed in <code>unique</code>. If a matching check is
  229. found, return it with HTTP status code 200. If no matching check is
  230. found, proceed as normal: create a check and return it
  231. with HTTP status code 201.</p>
  232. <p>The accepted values are: <code>name</code>,
  233. <code>tags</code>, <code>timeout</code> and <code>grace</code>.</p>
  234. <p>Example:</p>
  235. <pre>{"name": "Backups", unique: ["name"]}</pre>
  236. <p>In this example, if a check named "Backups" exists, it will
  237. be returned. Otherwise, a new check will be created and
  238. returned.</p>
  239. </td>
  240. </tr>
  241. </table>
  242. <h3 class="api-section">Response Codes</h3>
  243. <table class="table">
  244. <tr>
  245. <th>201 Created</th>
  246. <td>Returned if the check was successfully created.</td>
  247. </tr>
  248. <tr>
  249. <th>200 OK</th>
  250. <td>Returned if the <code>unique</code> parameter was used and an
  251. existing check was matched.</td>
  252. </tr>
  253. <tr>
  254. <th>403 Forbidden</th>
  255. <td>Returned if the account's check limit has been reached.
  256. For free accounts, the limit is 20 checks per account.</td>
  257. </tr>
  258. </table>
  259. <h3 class="api-section">Example Request</h3>
  260. {% include "front/snippets/create_check_request_a.html" %}
  261. <br>
  262. <p>Or, alternatively:</p>
  263. {% include "front/snippets/create_check_request_b.html" %}
  264. <h3 class="api-section">Example Response</h3>
  265. {% include "front/snippets/create_check_response.html" %}
  266. <!-- ********************************************************************** /-->
  267. <a class="section" name="update-check">
  268. <h2 class="rule">Update an Existing Check</h2>
  269. </a>
  270. <div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/&lt;code&gt;</div>
  271. <strong></strong>
  272. <p>
  273. Updates an existing check. All request parameters are optional. The
  274. check is updated only with the supplied request parameters.
  275. If any parameter is omitted, its value is left unchanged.
  276. </p>
  277. <h3 class="api-section">Request Parameters</h3>
  278. <table class="table">
  279. <tr>
  280. <th>name</th>
  281. <td>
  282. <p>string, optional.</p>
  283. <p>Name for the check.</p>
  284. </td>
  285. </tr>
  286. <tr>
  287. <th>tags</th>
  288. <td>
  289. <p>string, optional.</p>
  290. <p>A space-delimited list of tags for the check.</p>
  291. <p>Example:</p>
  292. <pre>{"tags": "reports staging"}</pre>
  293. </td>
  294. </tr>
  295. <tr>
  296. <th>desc</th>
  297. <td>
  298. <p>string, optional.</p>
  299. <p>Description for the check.</p>
  300. </td>
  301. </tr>
  302. <tr>
  303. <th>timeout</th>
  304. <td>
  305. <p>number, optional.</p>
  306. <p>A number of seconds, the expected period of this check.</p>
  307. <p>Minimum: 60 (one minute), maximum: 2592000 (30 days).</p>
  308. <p>Example for 5 minute timeout:</p>
  309. <pre>{"kind": "simple", "timeout": 300}</pre>
  310. </td>
  311. </tr>
  312. <tr>
  313. <th>grace</th>
  314. <td>
  315. <p>number, optional.</p>
  316. <p>A number of seconds, the grace period for this check.</p>
  317. <p>Minimum: 60 (one minute), maximum: 2592000 (30 days).</p>
  318. </td>
  319. </tr>
  320. <tr>
  321. <th>schedule</th>
  322. <td>
  323. <p>string, optional.</p>
  324. <p>A cron expression defining this check's schedule.</p>
  325. <p>If you specify both "timeout" and "schedule" parameters,
  326. "timeout" will be ignored and "schedule" will be used.</p>
  327. <p>Example for a check running every half-hour:</p>
  328. <pre>{"schedule": "0,30 * * * *"}</pre>
  329. </td>
  330. </tr>
  331. <tr>
  332. <th>tz</th>
  333. <td>
  334. <p>string, optional.</p>
  335. <p>Server's timezone. This setting only has effect in combination
  336. with the "schedule" paremeter.</p>
  337. <p>Example:</p>
  338. <pre>{"tz": "Europe/Riga"}</pre>
  339. </td>
  340. </tr>
  341. <tr>
  342. <th>channels</th>
  343. <td>
  344. <p>string, optional.</p>
  345. <p>Set this field to a special value "*"
  346. to automatically assign all existing notification channels.
  347. </p>
  348. <p>Set this field to a special value "" (empty string)
  349. to automatically <em>unassign</em> all notification channels.
  350. </p>
  351. <p>Set this field to a comma-separated list of channel identifiers
  352. to assign specific notification channels.
  353. </p>
  354. <p>Example:</p>
  355. <pre>{"channels": "4ec5a071-2d08-4baa-898a-eb4eb3cd6941,746a083e-f542-4554-be1a-707ce16d3acc"}</pre>
  356. </td>
  357. </tr>
  358. </table>
  359. <h3 class="api-section">Response Codes</h3>
  360. <table class="table">
  361. <tr>
  362. <th>200 OK</th>
  363. <td>Returned if the check was successfully updated.</td>
  364. </tr>
  365. </table>
  366. <h3 class="api-section">Example Request</h3>
  367. {% include "front/snippets/update_check_request_a.html" %}
  368. <br>
  369. <p>Or, alternatively:</p>
  370. {% include "front/snippets/update_check_request_b.html" %}
  371. <h3 class="api-section">Example Response</h3>
  372. {% include "front/snippets/create_check_response.html" %}
  373. <!-- ********************************************************************** /-->
  374. <a class="section" name="pause-check">
  375. <h2 class="rule">Pause Monitoring of a Check</h2>
  376. </a>
  377. <div class="api-path">POST {{ SITE_ROOT }}/api/v1/checks/&lt;uuid&gt;/pause</div>
  378. <p>
  379. Disables monitoring for a check, without removing it. The check goes
  380. into a "paused" state. You can resume monitoring of the check by pinging
  381. it.
  382. </p>
  383. <p>
  384. This API call has no request parameters.
  385. </p>
  386. <h3 class="api-section">Example Request</h3>
  387. {% include "front/snippets/pause_check_request.html" %}
  388. <p>Note: the <code>--data ""</code> argument forces curl to send a
  389. <code>Content-Length</code> request header even though the request body
  390. is empty. For HTTP POST requests, the <code>Content-Length</code> header
  391. is sometimes required by some network proxies and web servers.
  392. </p>
  393. <h3 class="api-section">Example Response</h3>
  394. {% include "front/snippets/pause_check_response.html" %}
  395. <!-- ********************************************************************** /-->
  396. <a class="section" name="delete-check">
  397. <h2 class="rule">Delete Check</h2>
  398. </a>
  399. <div class="api-path">DELETE {{ SITE_ROOT }}/api/v1/checks/&lt;uuid&gt;</div>
  400. <p>
  401. Permanently deletes the check from user's account. Returns JSON
  402. representation of the check that was just deleted.
  403. </p>
  404. <p>
  405. This API call has no request parameters.
  406. </p>
  407. <h3 class="api-section">Example Request</h3>
  408. {% include "front/snippets/delete_check_request.html" %}
  409. <h3 class="api-section">Example Response</h3>
  410. {% include "front/snippets/create_check_response.html" %}
  411. <!-- ********************************************************************** /-->
  412. <a class="section" name="list-channels">
  413. <h2 class="rule">Get a List of Existing Integrations</h2>
  414. </a>
  415. <div class="api-path">GET {{ SITE_ROOT }}/api/v1/channels/</div>
  416. <p>Returns a list of integrations belonging to the user.</p>
  417. <h3 class="api-section">Example Request</h3>
  418. {% include "front/snippets/list_channels_request.html" %}
  419. <h3 class="api-section">Example Response</h3>
  420. {% include "front/snippets/list_channels_response.html" %}
  421. {% endblock %}
  422. {% block scripts %}
  423. {% compress js %}
  424. <script src="{% static 'js/jquery-2.1.4.min.js' %}"></script>
  425. <script src="{% static 'js/bootstrap.min.js' %}"></script>
  426. <script src="{% static 'js/clipboard.min.js' %}"></script>
  427. <script src="{% static 'js/snippet-copy.js' %}"></script>
  428. {% endcompress %}
  429. {% endblock %}