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.

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