From c0c7416a233d1bf1ed197b8f383aca74bc27c3f0 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Tue, 17 Apr 2018 11:11:25 +0200 Subject: [PATCH] Add rest api quickstart --- README.md | 4 ++- support/doc/api/quickstart.md | 47 +++++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) create mode 100644 support/doc/api/quickstart.md diff --git a/README.md b/README.md index 19233307c..c49d5a27d 100644 --- a/README.md +++ b/README.md @@ -119,7 +119,9 @@ coder to help! ## API REST documentation -For now only on Github: +Quick Start: [/support/doc/api/quickstart.md](/support/doc/api/quickstart.md) + +Endpoints documentation: * HTML version: [/support/doc/api/html/index.html](https://htmlpreview.github.io/?https://github.com/Chocobozzz/PeerTube/blob/develop/support/doc/api/html/index.html) * Swagger/OpenAPI schema: [/support/doc/api/openapi.yaml](/support/doc/api/openapi.yaml) diff --git a/support/doc/api/quickstart.md b/support/doc/api/quickstart.md new file mode 100644 index 000000000..5ebcd4f47 --- /dev/null +++ b/support/doc/api/quickstart.md @@ -0,0 +1,47 @@ +# REST API quick start + +## Authentication + +### Get client + +Some endpoints need authentication. We use OAuth 2.0 so first fetch the client tokens: + +``` +$ curl https://peertube.example.com/api/v1/oauth-clients/local +``` + +Response example: + +``` +{ + "client_id": "v1ikx5hnfop4mdpnci8nsqh93c45rldf", + "client_secret": "AjWiOapPltI6EnsWQwlFarRtLh4u8tDt" +} +``` + +### Get user token + +Now you can fetch the user token: + +``` +$ curl -X POST \ + -d "client_id=v1ikx5hnfop4mdpnci8nsqh93c45rldf&client_secret=AjWiOapPltI6EnsWQwlFarRtLh4u8tDt&grant_type=password&response_type=code&username=your_user&password=your_password" \ + https://peertube.example.com/api/v1/users/token +``` + +Response example: + +``` +{ + "access_token": "90286a0bdf0f7315d9d3fe8dabf9e1d2be9c97d0", + "token_type": "Bearer", + "expires_in": 14399, + "refresh_token": "2e0d675df9fc96d2e4ec8a3ebbbf45eca9137bb7" +} +``` + +Just use the `access_token` in the `Authorization` header: + +``` +$ curl -H 'Authorization: Bearer 90286a0bdf0f7315d9d3fe8dabf9e1d2be9c97d0' https://peertube.example.com/api/v1/jobs/complete +``` \ No newline at end of file -- 2.25.1