Update api.md

This commit is contained in:
Stefan Pejcic 2024-03-14 19:20:56 +01:00 committed by GitHub
parent 9b6e850882
commit 0f433dc2aa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -8,113 +8,9 @@ sidebar_position: 9
THIS FEATURE IS STILL EXPERIMENTAL AND NOT YET PRODUCTION READY!
:::
## Basic Authentication
On *OpenAdmin > API* you can generate a JWT token and then make some API calls for testing to familiarize yourself with the API.
OpenPanel API uses JWT tokens for authentication.
Below each command, you'll find the corresponding curl command, which you can copy and paste onto another server to execute the API call, along with the actual response returned by the API endpoint.
### Generate access token
Send POST request to /api with your username and password:
```bash
curl -X POST -H "Content-Type: application/json" -d '{"username":"USERNAME_HERE", "password":"PASSWORD_HERE"}' https://OPENPANEL:2087/api
```
Example response:
```json
{
"name": "string"
}
```
### Check if token is valid
```bash
curl -H "Authorization: Bearer JWT_TOKEN" https://OPENPANEL:2087/api/whoami
```
Example response:
```json
{
"logged_in_as": "user"
}
```
## Users
### List All Users
```bash
curl -H "Authorization: Bearer JWT_TOKEN" https://OPENPANEL:2087/api/users
```
Example response:
```json
{
{
"users": [
[
12,
"SUSPENDED_20240103122300_jasta",
"pbkdf2:sha256:260000$G26Nw1zBQ6yywbiG$6a0d321490842b58068ad44e6e21b96e89f42cb6daecebe3afc06ad447ef3785",
"jasta",
"1,2,3,4,5,6,7,8,9,10,11,12",
"",
0,
null,
null,
"Tue, 02 Jan 2024 19:44:25 GMT",
2,
"cloud_4_nginx"
],
[
13,
"example_user",
"pbkdf2:sha256:260000$EIkp3AkT9OBPDtr1$956594ccc6aaa2c24c528f98eacadee7ac35193578b32dc415b2402fa9a22595",
"user@example.com",
"1,2,3,4,5,6,7,8,9,10,11,12",
"",
0,
null,
null,
"Tue, 09 Jan 2024 14:18:56 GMT",
2,
"cloud_4_apache"
]
]
}
}
```
### List Single User
```bash
curl -H "Authorization: Bearer JWT_TOKEN" https://OPENPANEL:2087/api/users/stefan
```
Example response:
```json
{
{
"users": [
[
15,
"stefan",
"pbkdf2:sha256:260000$EIkp3AkT9OBPDtr1$956594ccc6aaa2c24c528f98eacadee7ac35193578b32dc415b2402fa9a22595",
"user@example.com",
"1,2,3,4,5,6,7,8,9,10,11,12",
"",
0,
null,
null,
"Tue, 09 Jan 2024 14:18:56 GMT",
2,
"cloud_4_apache"
]
]
}
}
```
### Create User
At the bottom, there's a section where you can view the API log, which records every request and response made to the API.