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.

158 lines
6.8 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" id="send">Send a webmention to a specific page</h2>
  9. Post to `https://telegraph.p3k.io/webmention`
  10. ### Required
  11. * `token` - your API key obtained after signing up
  12. * `source` - the URL of your post
  13. * `target` OR `target_domain` - the URL or domain you linked to, respectively
  14. ### Optional
  15. * `callback` - a URL that will receive a web hook when new information about this webmention is available
  16. * `vouch` - see <a href="https://indieweb.org/Vouch">Vouch</a>
  17. * `code` - see <a href="https://indieweb.org/Private-Webmention">Private Webmention</a>
  18. * `realm` - see <a href="https://indieweb.org/Private-Webmention">Private Webmention</a>
  19. 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.
  20. 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. (Note that this verification is not performed for sending private Webmentions.)
  21. If you pass `target_domain` instead of `target`, Telegraph will find and enqueue webmentions for all links to that domain. However, sending a private Webmention requires that you send `target` rather than `target_domain`.
  22. #### Errors
  23. * `authentication_required` - the token parameter was missing
  24. * `invalid_token` - the token was invalid or expired
  25. * `missing_parameters` - one or more of the three parameters were not in the request
  26. * `invalid_parameter` - one or more of the parameters were invalid, e.g. the target was not a valid URL
  27. * `source_not_html` - the source document could not be parsed as HTML (only in extreme cases, most of the time it just accepts whatever)
  28. * `no_link_found` - the link to the target URL was not found on the source document
  29. * `not_supported` - the target URL is known to not accept webmentions, so the request is rejected before even queuing it. If you believe this is in error, please file an issue at [github.com/aaronpk/Telegraph/issues](https://github.com/aaronpk/Telegraph/issues)
  30. An error response in this case will be returned with an HTTP 400 status code an a JSON body:
  31. ```
  32. HTTP/1.1 400 Bad Request
  33. Content-type: application/json
  34. {
  35. "error": "missing_parameters",
  36. "error_description": "The source or target parameters were missing"
  37. }
  38. ```
  39. #### Success
  40. 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.
  41. ```
  42. HTTP/1.1 201 Created
  43. Content-type: application/json
  44. Location: https://telegraph.p3k.io/webmention/xxxxxxxx
  45. {
  46. "status": "queued",
  47. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  48. }
  49. ```
  50. If you use `target_domain` instead of `target`, the `location` field will be a list containing the status URLs for each webmention that was queued. The `Location` header will be omitted.
  51. ```
  52. HTTP/1.1 201 Created
  53. Content-type: application/json
  54. {
  55. "status": "queued",
  56. "location": [
  57. "https://telegraph.p3k.io/webmention/xxxxxxxx",
  58. "https://telegraph.p3k.io/webmention/yyyyyyyy"
  59. ]
  60. }
  61. ```
  62. <h2 class="ui dividing header" id="status">Status API</h2>
  63. 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:
  64. ```
  65. HTTP/1.1 200 OK
  66. Content-Type: application/json
  67. {
  68. "status": "queued",
  69. "summary": "The webmention is still in the processing queue.",
  70. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  71. }
  72. ```
  73. ```
  74. HTTP/1.1 200 OK
  75. Content-Type: application/json
  76. {
  77. "status": "no_link_found",
  78. "summary": "No link was found from source to target"
  79. }
  80. ```
  81. ```
  82. HTTP/1.1 200 OK
  83. Content-Type: application/json
  84. {
  85. "status": "success",
  86. "type": "webmention",
  87. "endpoint":
  88. "summary": "The webmention request was accepted.",
  89. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  90. }
  91. ```
  92. The possible fields that are returned are as follows:
  93. * `status` - One of the status codes listed below
  94. * `type` - optional - "webmention" or "pingback", depending on what was discovered at the target
  95. * `endpoint` - optional - The webmention or pingback endpoint that was discovered
  96. * `http_code` - optional - The HTTP code that the webmention or pingback endpoint returned
  97. * `summary` - optional - A human-readable summary of the status
  98. * `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.
  99. Other possible status codes are listed below.
  100. * `accepted` - the webmention or pingback request was accepted (pingback does not differentiate between when a request is queued or processed immediately)
  101. * `success` - the webmention status endpoint indicated the webmention was successful after processing it
  102. * `not_supported` - no webmention or pingback endpoint was found at the target
  103. * `no_link_found` - no link was found from source to target
  104. 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.
  105. <h2 class="ui dividing header" id="callbacks">Callback Events</h2>
  106. 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.
  107. 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.
  108. 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.
  109. A callback from Telegraph will include the following post body parameters:
  110. * `source` - the URL of your post
  111. * `target` - the URL you linked to
  112. * `type` - "pingback" or "webmention" depending on what was discovered at the target
  113. * `status` - one of the status codes above, e.g. `accepted`
  114. * `location` - if further updates will be available, the status URL where you can check again in the future
  115. <?
  116. $source=ob_get_clean();
  117. echo MarkdownExtra::defaultTransform($source);
  118. ?>
  119. </div>