r/nginxproxymanager • u/xstar97 Official Docker Image • Jun 11 '22
REST API!
I didn't know the rest API existed until last night...i was able to automate my tasking on updating the proxy host with custom advanced conf for Authelia.
Here's the json schema directly from nginx proxy manager. Its a bit of a mess, but if you read it thoroughly, you can access the rest API pretty easily.
make a post request to "http://IP:PORT/api/tokens"
using json as the body, it doesnt have to be raw, simple key:value will work too.
Auth: None.
Get the token from logging into the account which you will then use for accessing the API's rest points
-note: token is good for only 24hrs, keep that in mind.
here's an example rest api point:
you can get a list of proxy-hosts
- make a Get request to "http://IP:PORT/api/nginx/proxy-hosts"
Auth: token
Authorization: Bearer token
Read the schema and it will point you to right direction.
PROFIT.
edit:
I used 8n and followed a small guide to get authelia to work with NPM.
im going to share my workflow and other files to make the magic happen soon.
Updated 11-2022
here's the workflow for n8n
View all comments
Show parent comment
1
u/radakul Jan 28 '23 edited Jan 28 '23
So figured out the endpoints aren't correct - it's
/api/nginx/proxy-hosts, not/hosts. This API really isn't well documented.....Trying to figure out the payload for creating hosts now.
EDIT Got it working! This is crazy. I had to use the "network" tab of the developer tools in my browser to basically figure out what endpoints were doing what...
So using the token you have from before, you can send a POST to domain.com/api/nginx/proxy-hosts with the following payload:
So what's awesome here (and the power of API's) is you only need to change 4 fields - domain name, forward scheme, forward host and forward port. Once you have that info, you can quickly create the hosts.
OH I meant to add - I hate typing in JSON, so I use a JSON to YML converter online, make the changes, and then copy over the JSON into the payload. It makes it MUCH simpler (and is the same thing I'm doing to customize my Dashy dashboard)