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.

130 lines
5.3 KiB

9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
9 years ago
8 years ago
  1. # Telegraph
  2. Telegraph is an API for sending [Webmentions](http://webmention.net).
  3. ## Send a webmention to a specific page
  4. Post to `https://telegraph.p3k.io/webmention`
  5. * `token` - your API key obtained after signing up
  6. * `source` - the URL of your post
  7. * `target` - the URL you linked to
  8. * `callback` - (optional) - a URL that will receive a web hook when new information about this webmention is available
  9. 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.
  10. 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.
  11. #### Errors
  12. * `authentication_required` - the token parameter was missing
  13. * `invalid_token` - the token was invalid or expired
  14. * `missing_parameters` - one or more of the three parameters were not in the request
  15. * `invalid_parameter` - one or more of the parameters were invalid, e.g. the target was not a valid URL
  16. * `source_not_html` - the source document could not be parsed as HTML (only in extreme cases, most of the time it just accepts whatever)
  17. * `no_link_found` - the link to the target URL was not found on the source document
  18. An error response in this case will be returned with an HTTP 400 status code an a JSON body:
  19. ```json
  20. HTTP/1.1 400 Bad Request
  21. Content-type: application/json
  22. {
  23. "error": "missing_parameters",
  24. "error_description": "The source or target parameters were missing"
  25. }
  26. ```
  27. #### Success
  28. 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.
  29. ```
  30. HTTP/1.1 201 Created
  31. Content-type: application/json
  32. Location: https://telegraph.p3k.io/webmention/xxxxxxxx
  33. {
  34. "status": "queued",
  35. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  36. }
  37. ```
  38. ### Status API
  39. 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:
  40. ```
  41. HTTP/1.1 200 OK
  42. Content-Type: application/json
  43. {
  44. "status": "queued",
  45. "summary": "The webmention is still in the processing queue.",
  46. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  47. }
  48. ```
  49. ```
  50. HTTP/1.1 200 OK
  51. Content-Type: application/json
  52. {
  53. "status": "no_link_found",
  54. "summary": "No link was found from source to target"
  55. }
  56. ```
  57. ```
  58. HTTP/1.1 200 OK
  59. Content-Type: application/json
  60. {
  61. "status": "success",
  62. "type": "webmention",
  63. "endpoint":
  64. "summary": "The webmention request was accepted.",
  65. "location": "https://telegraph.p3k.io/webmention/xxxxxxxx"
  66. }
  67. ```
  68. The possible fields that are returned are as follows:
  69. * `status` - One of the status codes listed below
  70. * `type` - optional - "webmention" or "pingback", depending on what was discovered at the target
  71. * `endpoint` - optional - The webmention or pingback endpoint that was discovered
  72. * `http_code` - optional - The HTTP code that the webmention or pingback endpoint returned
  73. * `summary` - optional - A human-readable summary of the status
  74. * `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.
  75. Other possible status codes are listed below.
  76. * `accepted` - the webmention or pingback request was accepted (pingback does not differentiate between when a request is queued or processed immediately)
  77. * `success` - the webmention status endpoint indicated the webmention was successful after processing it
  78. * `not_supported` - no webmention or pingback endpoint was found at the target
  79. * `no_link_found` - no link was found from source to target
  80. 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.
  81. ### Callback Events
  82. 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.
  83. 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.
  84. 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.
  85. A callback from Telegraph will include the following post body parameters:
  86. * `source` - the URL of your post
  87. * `target` - the URL you linked to
  88. * `type` - "pingback" or "webmention" depending on what was discovered at the target
  89. * `status` - one of the status codes above, e.g. `accepted`
  90. * `location` - if further updates will be available, the status URL where you can check again in the future
  91. ## Credits
  92. Telegraph photo: https://www.flickr.com/photos/nostri-imago/3407786186
  93. Telegraph icon: https://thenounproject.com/search/?q=telegraph&i=22058