Is it possible to Add/Delete User by API? #836
-
I am currently deploying Photoview on my Synology NAS using Docker Compose. version: "3"
services:
db:
image: mariadb:10.5
restart: unless-stopped
environment:
- MYSQL_DATABASE=photoview
- MYSQL_USER=photoview
- MYSQL_PASSWORD=paver001958
- MYSQL_RANDOM_ROOT_PASSWORD=1
volumes:
- ./db:/var/lib/mysql
photoview:
image: viktorstrate/photoview:2
restart: unless-stopped
ports:
- "8888:80"
depends_on:
- db
environment:
- PHOTOVIEW_DATABASE_DRIVER=mysql
- PHOTOVIEW_MYSQL_URL=photoview:paver001958@tcp(db)/photoview
- PHOTOVIEW_LISTEN_IP=photoview
- PHOTOVIEW_LISTEN_PORT=80
- PHOTOVIEW_MEDIA_CACHE=/app/cache
volumes:
- ./cache:/app/cache
- /volume1/photoserver/photobook:/photos:ro As I have a requirement to add multiple users recently, I am considering using the API method instead of manual addition.
response:
Is there anyway to utilizing the API within my deployed environment? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
To use the Web API, you need to provide an def photoview_api_call(body):
url = "http://127.0.0.1/api/graphql"
headers = {
"Content-Type": "application/json",
"Cookie": "auth-token=AAAABBBBCCCC"
}
response = requests.post(url, headers=headers, data=body)
#print(f"API Request: {response.request.body})
return response You can get an Here's an example body = json.dumps({
"operationName":"createUser",
"variables":{"username":username, "admin":False},
"query":"mutation createUser($username: String!, $admin: Boolean!) {\n createUser(username: $username, admin: $admin) {\n id\n username\n admin\n __typename\n }\n}\n"
}) |
Beta Was this translation helpful? Give feedback.
To use the Web API, you need to provide an
auth-token
in your HTTP request. Here's an example Python function which takes a JSON body to POST to the graphql endpoint.You can get an
auth-token
by checking what is sent by your web browser however those tokens will expire after a few weeks. For a more permanent solution, edit one of the entries in theaccess_tokens
MySQL tabl…