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.

134 lines
5.5 KiB

  1. <?
  2. use \Michelf\MarkdownExtra;
  3. $this->layout('layout-loggedin', ['title' => $title, 'accounts' => $accounts, 'user' => $user, 'return_to' => $return_to]);
  4. ?>
  5. <div class="ui main text container api-docs" style="margin-top: 80px;">
  6. <h1>Telegraph API</h1>
  7. <? ob_start(); ?>
  8. <h2 class="ui dividing header">Send a webmention to a specific page</h2>
  9. Post to `https://telegraph.p3k.io/webmention`
  10. * `token` - your API key obtained after signing up
  11. * `source` - the URL of your post
  12. * `target` - the URL you linked to
  13. * `callback` - (optional) - a URL that will receive a web hook when new information about this webmention is available
  14. The Telegraph API will validate the parameters and then queue the webmention for sending. If there was a problem with the request, you will get an error response immediately.
  15. The API will first make an HTTP request to the source URL, and look for a link to the target on the page. This happens synchronously so you will get this error reply immediately.
  16. #### Errors
  17. * `authentication_required` - the token parameter was missing
  18. * `invalid_token` - the token was invalid or expired
  19. * `missing_parameters` - one or more of the three parameters were not in the request
  20. * `invalid_parameter` - one or more of the parameters were invalid, e.g. the target was not a valid URL
  21. * `source_not_html` - the source document could not be parsed as HTML (only in extreme cases, most of the time it just accepts whatever)
  22. * `no_link_found` - the link to the target URL was not found on the source document
  23. An error response in this case will be returned with an HTTP 400 status code an a JSON body:
  24. ```
  25. HTTP/1.1 400 Bad Request
  26. Content-type: application/json
  27. {
  28. "error": "missing_parameters",
  29. "error_description": "The source or target parameters were missing"
  30. }
  31. ```
  32. #### Success
  33. If the initial validation succeeds, Telegraph will queue the webmention for sending and return a success response, including a URL you can check for status updates. This URL will be returned even if you also provide a callback URL. The URL will be available in both the `Location` header as well as in the JSON response.
  34. ```
  35. HTTP/1.1 201 Created
  36. Content-type: application/json
  37. Location: https://telegraph.p3k.io/webmention/xxxxxxxx
  38. {
  39. "status": "queued",
  40. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  41. }
  42. ```
  43. <h2 class="ui dividing header">Status API</h2>
  44. You can poll the status URL returned after queuing a webmention for more information on the progress of sending the webmention. The response will look like the following:
  45. ```
  46. HTTP/1.1 200 OK
  47. Content-Type: application/json
  48. {
  49. "status": "queued",
  50. "summary": "The webmention is still in the processing queue.",
  51. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  52. }
  53. ```
  54. ```
  55. HTTP/1.1 200 OK
  56. Content-Type: application/json
  57. {
  58. "status": "no_link_found",
  59. "summary": "No link was found from source to target"
  60. }
  61. ```
  62. ```
  63. HTTP/1.1 200 OK
  64. Content-Type: application/json
  65. {
  66. "status": "success",
  67. "type": "webmention",
  68. "endpoint":
  69. "summary": "The webmention request was accepted.",
  70. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  71. }
  72. ```
  73. The possible fields that are returned are as follows:
  74. * `status` - One of the status codes listed below
  75. * `type` - optional - "webmention" or "pingback", depending on what was discovered at the target
  76. * `endpoint` - optional - The webmention or pingback endpoint that was discovered
  77. * `http_code` - optional - The HTTP code that the webmention or pingback endpoint returned
  78. * `summary` - optional - A human-readable summary of the status
  79. * `location` - optional - If present, you can continue checking this URL for status updates. If not present, no further information will be available about this request.
  80. Other possible status codes are listed below.
  81. * `accepted` - the webmention or pingback request was accepted (pingback does not differentiate between when a request is queued or processed immediately)
  82. * `success` - the webmention status endpoint indicated the webmention was successful after processing it
  83. * `not_supported` - no webmention or pingback endpoint was found at the target
  84. * `no_link_found` - no link was found from source to target
  85. Other status codes may be returned depending on the receiver's status endpoint. You should only assume a webmention was successfully sent if the status is `success` or `accepted`. If the response does not contain a `location` parameter you should not continue polling the endpoint.
  86. <h2 class="ui dividing header">Callback Events</h2>
  87. After Telegraph processes your request, you will receive a post to the callback URL. The initial callback you receive will be one of the status codes returned by the status API.
  88. Typically, webmention endpoints defer processing until later, so normally the first callback received will indicate that the webmention was queued. This callback will normally be sent relatively quickly after you make the initial request, typically within a few seconds.
  89. If the webmention endpoint provides status updates, either through a status URL or web hook, then Telegraph will deliver follow-up notifications when it gets updated information.
  90. A callback from Telegraph will include the following post body parameters:
  91. * `source` - the URL of your post
  92. * `target` - the URL you linked to
  93. * `type` - "pingback" or "webmention" depending on what was discovered at the target
  94. * `status` - one of the status codes above, e.g. `accepted`
  95. * `location` - if further updates will be available, the status URL where you can check again in the future
  96. <?
  97. $source=ob_get_clean();
  98. echo MarkdownExtra::defaultTransform($source);
  99. ?>
  100. </div>