diff --git a/docs/api.md b/docs/api.md index d34b5f0..f0e4dea 100644 --- a/docs/api.md +++ b/docs/api.md @@ -1,10 +1,79 @@ # :fontawesome-solid-code: API -Portainer exposes an HTTP API that you can use to automate everything you do via the Portainer UI. +Portainer exposes an HTTP API that you can use to automate everything you do via the Portainer UI. You may also use Portainer as a gateway (HTTP queries against the Portainer API) to the underlying Docker/Kubernetes API. -## :fontawesome-solid-file-code: Documentation +## :fontawesome-solid-file-code: API Documentation The API documentation is available on -[Swaggerhub](https://app.swaggerhub.com/apis/deviantony/Portainer/2.0.1){target=_blank} -and you can also find some examples -[here](https://gist.github.com/deviantony/77026d402366b4b43fa5918d41bc42f8){target=_blank}. +[Swaggerhub](https://app.swaggerhub.com/apis/portainer/portainer-ce/2.5.1){target=_blank} + + +## :octicons-code-review-16: Examples + +!!! Note "The following examples use [httpie](https://httpie.org/){target=_blank} to execute API calls against Portainer" + +### Initialize the admin password +On a fresh install of Portainer, you need to create an admin account to initialize Portainer. You will be asked for this when you visit the Portainer url for the very first time. You can acheive the same using the below + +```shell +http POST /api/users/admin/init Username="" Password="" +``` + +### Authenticate against the API using the admin account +```shell +http POST /api/auth Username="" Password="" +``` +The response is a JSON object containing the JWT token inside the jwt field: +```shell +{ + "jwt":"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsInJvbGUiOjEsImV4cCI6MTQ5OTM3NjE1NH0.NJ6vE8FY1WG6jsRQzfMqeatJ4vh2TWAeeYfDhP71YEE" +} +``` +You need to retrieve this token. You will need to pass this token inside the Authorization header when executing an authentication query against the API. + +The value of the Authorization header must be of the form Bearer . +```json +Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpZCI6MSwidXNlcm5hbWUiOiJhZG1pbiIsInJvbGUiOjEsImV4cCI6MTQ5OTM3NjE1NH0.NJ6vE8FY1WG6jsRQzfMqeatJ4vh2TWAeeYfDhP71YEE +``` +**NOTE**: This token has a 8 hour validity, you'll need to generate another token to execute authenticated queries once this one expires. + +### Create a new endpoint +Here, We'll show how to create 3 different types of endpoints: + +* Local endpoint using Docker socket communication +* Remote endpoint using TCP communication +* Remote endpoint using TCP communication secured via TLS + +#### Local endpoint via the Docker socket +This query will create an endpoint called test-local and will use the Docker socket to communicate with this environment. + +**NOTE**: This example requires to you bind-mount the Docker socket when running Portainer. + +```shell http --form POST " \ +Name="" EndpointCreationType=1 +``` +The response is a JSON object representing the endpoint: + +```json +{ + "AuthorizedTeams": [], + "AuthorizedUsers": [], + "Extensions": [], + "GroupId": 1, + "Id": 2, + "Name": "", + "PublicURL": "", + "Type": 1, + "TLSConfig": { + "TLS": false, + "TLSSkipVerify": false + }, + "Type": 1, + "URL": "unix:///var/run/docker.sock" +} +``` +**More Examples to be added soon** \ No newline at end of file diff --git a/mkdocs.yml b/mkdocs.yml index a7da8c5..77ff788 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -1,9 +1,9 @@ site_name: Documentation site_url: https://documentation.portainer.io/ use_directory_urls: true -google_analytics: - - UA-84944922-5 - - auto +# google_analytics: +# - UA-84944922-5 +# - auto nav: - Home: index.md - Quick Start: quickstart.md @@ -348,6 +348,9 @@ plugins: 'v2.0-be/deploy/windowsserver.md': 'quickstart.md' extra: + analytics: + provider: google + property: G-PT7RWG2W49 social: - icon: fontawesome/brands/twitter link: https://twitter.com/portainerio