-
Couldn't load subscription status.
- Fork 3.3k
Use REST API for configure proxy host #3265
-
How it use REST API for configure proxy host. Can it possible?
Beta Was this translation helpful? Give feedback.
All reactions
Replies: 12 comments 14 replies
-
Hey, I have been investigating solutions for adding custom domain functionality to my hobby project app and came across the possibility of using NGINX Proxy Manager for this purpose. Since I've been using proxy manager for years and already was using it to forward the main domain I thought I'd take a closer look. Basically, it seems like even though there is an API available for use it is undocumented.
Essentially, after a bit of tinkering and feeding the schemas from https://github.com/NginxProxyManager/nginx-proxy-manager/tree/develop/backend/schema to chatGPT, I was able to get a basic integration between the backend of my app and a running instance of the Proxy Manager. I also used Insomnia to learn about how to interact with the API through POST and GET requests.
Essentially, you will need to submit {"identity": "your@email.com", "secret": "yoUrPassWord1!"} to http://nginxaddress:PORT/api/tokens . That will return a Bearer token. If you are in insomnia, you can insert this token via the Auth > bearer token tab. If you're writing a node app like I am you might need to use Axios to first post to get the bearer token, and then another post to actually create a new proxy host.
Hope this helps you get started. Would love to hear how other people are approaching integrating NGINX Proxy Manager into their apps, and whether or not it seems like a good solution at higher scale.
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 5
-
There's an OpenApi available
Beta Was this translation helpful? Give feedback.
All reactions
-
FYI you can create a token that will last as long as you want, (so you dont have to keep using you actually password)
Beta Was this translation helpful? Give feedback.
All reactions
-
FYI you can create a token that will last as long as you want, (so you dont have to keep using you actually password)
How can you do that ?
Beta Was this translation helpful? Give feedback.
All reactions
-
+1 here - coming back to setting up NPM in my home lab and the tokens currently returning from a POST to {{url/api/tokens}} using a key:value body of : returns a 24 hour lifetime token. I'd love to make this last longer if possible.
Beta Was this translation helpful? Give feedback.
All reactions
-
you can request a longer term, like this for EG...
curl "http://192.168.0.100/api/tokens" -H "Content-Type: application/json; charset=UTF-8" --data-raw '{"identity":"your@email.com","secret":"PASSWORD","expiry":"1y"}'
changing that expiry will alter the length ...
Beta Was this translation helpful? Give feedback.
All reactions
-
🎉 8
-
I'd like to know too since I'm writing a tool using this API lol
It's really hard to find documentation on it, I guess the best way is to feed ChatGPT with it 😂
Anyway, lemme know if you find something interesting please
Regards,
Beta Was this translation helpful? Give feedback.
All reactions
-
ChatGPT failed me (initially, at least) - there is no "access" sidebar? ChatGPT response below:
To request a 30 day access token for nginx proxy manager's API, follow these steps:
1. Log in to your nginx proxy manager dashboard.
2. Navigate to the "Access" tab in the sidebar menu.
3. Click on the "API Tokens" section.
4. Click on the "Create" button to generate a new access token.
5. In the popup window, enter a name for the token and select the desired expiration date (in this case, choose 30 days).
6. Click on the "Create" button to generate the access token.
7. Copy the generated access token and store it in a secure location.
8. You can now use this token to authenticate your API requests for the next 30 days.
Note: Make sure to keep your access token secure and do not share it with anyone else. It is recommended to regenerate the token after it expires for security purposes.
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
Thank you! This isn't documented anywhere that I can find (at least not in the schema obtained from mynpmurl.com/api/schema -- how'd you find this tidbit?
Beta Was this translation helpful? Give feedback.
All reactions
-
I was able to test this out and had success with a few different values:
1d
3m
10y
I'm not sure if you can (or would even want to) request a shorter-lived API token; maybe that might be useful for some sort of CI/CD pipeline, but this certainly meets my needs. I've used this to create an API-only user with limited permissions, so I'm very happy. Thanks again for sharing this tidbit of knowledge!
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
i have done a bash script for that ;)
Verify and manage token validation and also managing NPM settings via API
https://github.com/Erreur32/nginx-proxy-manager-API
Let me know ;)
Beta Was this translation helpful? Give feedback.
All reactions
-
Very nicely done! Much better than the attempt I made to do this (in Python). If you're curious - https://github.com/kmanwar89/nginx_proxy_manager_automation
What I did is make use of a .csv file for bulk-uploads, though it does not feature as many command-line arguments as yours (something I might, one day, eventually, work on :) )
Beta Was this translation helpful? Give feedback.
All reactions
-
Thanks @kmanwar89 .
Your idea is good to have a file locally ;)
This makes me think of adding an NPM backup/restore functionality, to have a file and doing it like you did for export.
Good luck
Beta Was this translation helpful? Give feedback.
All reactions
-
I was getting {"error":{"code":400,"message":"data must NOT have additional properties"}} with expiry in the request body. Looks like it's been changed to a query parameter instead.
See: #3417 (comment)
Beta Was this translation helpful? Give feedback.
All reactions
-
First get a token for a day, then use the /api/tokens?expiry=1y with authorization headers
curl 'http://172.16.5.7:81/api/tokens' -H 'Content-Type: application/json; charset=UTF-8' --data-raw '{"identity":"youremail","secret":"yourpass"}' --compressed
then with the token:
curl -X GET 'http://172.16.5.7:81/api/tokens?expiry=10y' -H 'Authorization: Bearer YOUR TOKEN HERE' -H 'Accept: application/json'
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1 -
❤️ 1
-
Ty for sharing this - wish this would be documented by the author! I'll have to adjust the code I wrote around this as well.
Beta Was this translation helpful? Give feedback.
All reactions
-
👍 1
-
@kmanwar89 Thanks you saved my day ;)
Beta Was this translation helpful? Give feedback.
All reactions
-
@Erreur32 not sure what I did, but happy to help I suppose!
I just validated and I'm not seeing where using a POST to the /api/tokens endpoint has stopped working - in fact, I was still able to request a 10y certificate without using a query argument.
If you send a POST to <your_npm_url.com>/api/tokens with the following payload, it should work. For my testing, I used Postman and sent a raw body containing the following:
{
"identity": "adminuser@domain.com",
"secret": "<superstrongpassword>",
"expiry": "10y"
}
For expiry, I tested values of 1y, 10y, 999y, everything seemed to work up to 999y - anything >1000 would cause it to error, but that probably won't matter since 100y is essentially a non-expiring token.
I hope this helps someone else (and possibly myself when I inevitably come back to reference this comment in <months/years> time!
I'm also updating my NPM Python automation repo that I developed to interact with the API
Beta Was this translation helpful? Give feedback.
All reactions
-
It works perfectly, I haven't tried to put more than 1 year for now.
yes 100 years ... haha
I have updated my code also ;)
Beta Was this translation helpful? Give feedback.
All reactions
-
For anyone else stumbling across this thread
https://github.com/Erreur32/nginx-proxy-manager-Bash-API?tab=readme-ov-file#reference-api
https://github.com/BlwAvg/helpers/blob/main/Nginx%20Proxy%20Manager%20(NPM)%20API.md
Beta Was this translation helpful? Give feedback.
All reactions
-
curl -X POST ^
http://manage.wonderiot.cc/api/tokens?expiry=10y ^
-H "Content-Type: application/json" ^
-d "{"identity":"asif.uz.az@gmail.com","secret":"Asif@00000000001"}"
And it is not working:
C:\Users\asifu>curl -X POST ^
More? http://manage.wonderiot.cc/api/tokens?expiry=10y ^
More? -H "Content-Type: application/json" ^
More? -d "{"identity":"asif.uz.az@gmail.com","secret":"Asif@00000000001"}"
{"token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcGkiLCJhdHRycyI6eyJpZCI6MX0sInNjb3BlIjpbInVzZXIiXSwiZXhwaXJlc0luIjoiMWQiLCJqdGkiOiJhdU5CUTlNSWg5L0owaFRrIiwiaWF0IjoxNzQ2MjYwMjkzLCJleHAiOjE3NDYzNDY2OTN9.If7Ch-RIquU28jfRyJX82_O-Gth9YyGaYibsWAurmkomkojkgjnTvoE1hJzLQf-CMwr_3n7xkh-MYPmIziTv0JJ4CvesaAytHqZrzIeoR1XuepDzT5OFXO79y1jESr8nalZaAmhZOfsy_baty1PeUGuhgR_qLT9qDFAKaxPwlfU3lk1XQUTM-zUngF42N92YDIsMwPMFgt_Xa_N7f31-G0dVy_gr8BTQw57awnIXJlLxmzHZUIewJg6iG0tCb9uScKZSpyuGGNHm4bRlmYxVUhvv2BiD0KKvOwqkoip-OzbxuSengfhu6Ok8rQHwg5SWPzxbp5yWF825LTmScsiv9Pnw","expires":"2025-05-04T08:18:13.919Z"}
See this: "expires":"2025-05-04T08:18:13.919Z" so what is the solution?
Beta Was this translation helpful? Give feedback.
All reactions
-
Sorry my mistake:
I read the @yonstorm solution again and I make it correct.
I have the short time token then I use that token and using like:
-H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcGkiLCJhdHRycyI6eyJpZCI6MX0sInNjb3BlIjpbInVzZXIiXSwiZXhwaXJlc0luIjoiMWQiLCJqdGkiOiJhdU5CUTlNSWg5L0owaFRrIiwiaWF0IjoxNzQ2MjYwMjkzLCJleHAiOjE3NDYzNDY2OTN9.If7Ch-RIquU28jfRyJX82_O-Gth9YyGaYibsWAurmkomkojkgjnTvoE1hJzLQf-CMwr_3n7xkh-MYPmIziTv0JJ4CvesaAytHqZrzIeoR1XuepDzT5OFXO79y1jESr8nalZaAmhZOfsy_baty1PeUGuhgR_qLT9qDFAKaxPwlfU3lk1XQUTM-zUngF42N92YDIsMwPMFgt_Xa_N7f31-G0dVy_gr8BTQw57awnIXJlLxmzHZUIewJg6iG0tCb9uScKZSpyuGGNHm4bRlmYxVUhvv2BiD0KKvOwqkoip-OzbxuSengfhu6Ok8rQHwg5SWPzxbp5yWF825LTmScsiv9Pnw" ^
-H "Accept: application/json"```
Message response:
```C:\Users\asifu>curl -X GET "http://manage.wonderiot.cc/api/tokens?expiry=10y" ^
More? -H "Authorization: Bearer eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcGkiLCJhdHRycyI6eyJpZCI6MX0sInNjb3BlIjpbInVzZXIiXSwiZXhwaXJlc0luIjoiMWQiLCJqdGkiOiJhdU5CUTlNSWg5L0owaFRrIiwiaWF0IjoxNzQ2MjYwMjkzLCJleHAiOjE3NDYzNDY2OTN9.If7Ch-RIquU28jfRyJX82_O-Gth9YyGaYibsWAurmkomkojkgjnTvoE1hJzLQf-CMwr_3n7xkh-MYPmIziTv0JJ4CvesaAytHqZrzIeoR1XuepDzT5OFXO79y1jESr8nalZaAmhZOfsy_baty1PeUGuhgR_qLT9qDFAKaxPwlfU3lk1XQUTM-zUngF42N92YDIsMwPMFgt_Xa_N7f31-G0dVy_gr8BTQw57awnIXJlLxmzHZUIewJg6iG0tCb9uScKZSpyuGGNHm4bRlmYxVUhvv2BiD0KKvOwqkoip-OzbxuSengfhu6Ok8rQHwg5SWPzxbp5yWF825LTmScsiv9Pnw" ^
More? -H "Accept: application/json"
{"token":"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJhcGkiLCJzY29wZSI6WyJ1c2VyIl0sImF0dHJzIjp7ImlkIjoxfSwiZXhwaXJlc0luIjoiMTB5IiwianRpIjoiVHlBMU5HT1p5dkVwZCtRciIsImlhdCI6MTc0NjI2MDk3MCwiZXhwIjoyMDYxODM2OTcwfQ.bbjsTojBKjsYPBCXpXMC1RB9R2ujukookjojiMqkvaC2jd48LU0MB3sb-LuPyMc2lrjnnfHQhFWVPMMdzUNPuWjPjVKD6Hs_V0DtyKlwTd_tHXKKUmr2KQFKdAf_224zcJ6be-OHdVRokxM1pKOfZKEjlQl4Apl2JTLYXrJJVeG317sAFHPoGunyULSwYVmAztMloj0INI_8wXiGvCuB9OY9AUePFgEnuse0CK36lBeMNRs_3ljTenF1Kl7dNcCkSUQMe5LEhz3PANLJqaVZbuqITkJeXmgLIQvko67CYajjdytWi315yKVnA1ooo0iWU79RxELcG2uU3gCFPIT__XNwiKg","expires":"2035-05-03T08:29:30.164Z"}
C:\Users\asifu>```
see : "expires":"2035-05-03T08:29:30.164Z" that is very very much easy way to solve the issue for a production level work. So Thank you @yonstorm sir.............. Love you....
Beta Was this translation helpful? Give feedback.
All reactions
-
The difference here is curl for windows vs curl done via linux or WSL.
Beta Was this translation helpful? Give feedback.
All reactions
-
Beta Was this translation helpful? Give feedback.
All reactions
-
The aforementioned Open API spec has a lot of structural errors:
Structural error at openapi
should match pattern "^3.0.\d(-.+)?$"
pattern: ^3.0.\d(-.+)?$
Jump to line 1
Structural error at paths./nginx/proxy-hosts.get.responses.200.content.application/json.schema.items.properties.locations.items.properties.id.type
should be string
Jump to line 1917
Structural error at paths./nginx/proxy-hosts.get.responses.200.content.application/json.schema.items.properties.locations.items.properties.id.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 1917
Structural error at paths./nginx/proxy-hosts.get.responses.200.content.application/json.schema.items.properties.certificate.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 1947
Structural error at paths./nginx/proxy-hosts.get.responses.200.content.application/json.schema.items.properties.access_list.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 2138
Structural error at paths./nginx/proxy-hosts.post.requestBody.content.application/json.schema.properties.locations.items.properties.id.type
should be string
Jump to line 2291
Structural error at paths./nginx/proxy-hosts.post.requestBody.content.application/json.schema.properties.locations.items.properties.id.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 2291
Structural error at paths./nginx/proxy-hosts.post.responses.201.content.application/json.schema.properties.locations.items.properties.id.type
should be string
Jump to line 2470
Structural error at paths./nginx/proxy-hosts.post.responses.201.content.application/json.schema.properties.locations.items.properties.id.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 2470
Structural error at paths./nginx/proxy-hosts.post.responses.201.content.application/json.schema.properties.certificate.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 2500
Structural error at paths./nginx/proxy-hosts.post.responses.201.content.application/json.schema.properties.access_list.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 2691
Structural error at paths./nginx/proxy-hosts/{hostID}.get.responses.200.content.application/json.schema.properties.locations.items.properties.id.type
should be string
Jump to line 2909
Structural error at paths./nginx/proxy-hosts/{hostID}.get.responses.200.content.application/json.schema.properties.locations.items.properties.id.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 2909
Structural error at paths./nginx/proxy-hosts/{hostID}.get.responses.200.content.application/json.schema.properties.certificate.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 2939
Structural error at paths./nginx/proxy-hosts/{hostID}.get.responses.200.content.application/json.schema.properties.access_list.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 3130
Structural error at paths./nginx/proxy-hosts/{hostID}.put.requestBody.content.application/json.schema.properties.locations.items.properties.id.type
should be string
Jump to line 3287
Structural error at paths./nginx/proxy-hosts/{hostID}.put.requestBody.content.application/json.schema.properties.locations.items.properties.id.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 3287
Structural error at paths./nginx/proxy-hosts/{hostID}.put.responses.200.content.application/json.schema.properties.locations.items.properties.id.type
should be string
Jump to line 3468
Structural error at paths./nginx/proxy-hosts/{hostID}.put.responses.200.content.application/json.schema.properties.locations.items.properties.id.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 3468
Structural error at paths./nginx/proxy-hosts/{hostID}.put.responses.200.content.application/json.schema.properties.certificate.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 3498
Structural error at paths./nginx/proxy-hosts/{hostID}.put.responses.200.content.application/json.schema.properties.access_list.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 3689
Structural error at paths./nginx/streams.get.responses.200.content.application/json.schema.items.properties.certificate.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 5599
Structural error at paths./nginx/streams.post.responses.201.content.application/json.schema.properties.certificate.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 5944
Structural error at paths./nginx/streams/{streamID}.get.responses.200.content.application/json.schema.properties.certificate.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 6242
Structural error at paths./nginx/streams/{streamID}.put.responses.200.content.application/json.schema.properties.certificate.oneOf.0.type
should be equal to one of the allowed values
allowedValues: array, boolean, integer, number, object, string
Jump to line 6592
Beta Was this translation helpful? Give feedback.