JSON call behind Nginx reverse proxy Topic is solved

Topics (not sure which fora)
when not sure where to post, post here and mods will move it to right forum.

Moderators: leecollings, remb0

Post Reply
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

JSON call behind Nginx reverse proxy

Post by ressof »

Hi

I have setup domoticz to run behind a reverse proxy and followed this guide

https://www.domoticz.com/wiki/WebServer_Proxy

I have setup nginx as the guide and also added my proxys ip to trusted networks.
I can access domoticz from everywhere and I have to enter credentials and OTP to login. This works great.

But I want to do a JSON call to toggle a switch from remote.

I paste this command in safari to test it when I on 4G
https://user:password@domain/json.htm?t ... cmd=Toggle
but then I get 401 Unauthorized

I have added the device in "Set devices" under user, and the user have user rights.

I get this in my logs

Code: Select all

2024-09-03 12:45:00.299  Debug: [web:8080] Host:192.168.x.x Uri:/json.htm?type=command&param=switchlight&idx=775&switchcmd=Toggle
2024-09-03 12:45:00.299  Debug: [web:8080] Request Headers:
Host: [domain]
X-Real-IP: [4G IP]
X-Forwarded-For: [4G IP]
X-Forwarded-Proto: https
X-Scheme: https
Connection: close
accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
sec-fetch-site: none
accept-encoding: gzip, deflate, br
sec-fetch-mode: navigate
user-agent: Mozilla/5.0 (iPhone; CPU iPhone OS 17_6 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/128.0.6613.34 Mobile/15E148 Safari/604.1
accept-language: sv-SE,sv;q=0.9
sec-fetch-dest: document

2024-09-03 12:45:00.299  Debug: [web:8080] IP (192.168.x.x) is within Trusted network range!
2024-09-03 12:45:00.299  Debug: [web:8080] Did not find suitable Authorization!
2024-09-03 12:45:00.299  Debug: Web ACLF: [4G IP] - - [03/Sep/2024:12:45:00.299 +0200] "GET /json.htm?type=command&param=switchlight&idx=775&switchcmd=Toggle HTTP/1.1" 401 91 - "M>
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: JSON call behind Nginx reverse proxy

Post by waltervl »

Some browsers do not support user:password in an url. So you have to test this with tools like curl or postman
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

Is there a way to use the API with POST or GET with headers and body instead of having the username and password in the URL? I'm using HTTPS
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

I tried with https://reqbin.com/post-online

I used this post:

Code: Select all

POST /json.htm HTTP/1.1
Authorization: Basic [Base64 encoded uername:password]
Host: [domain]
Accept: application/json
Content-Type: application/json
Content-Length: 88

{
  "type": "command",
  "param": "switchlight",
  "idx": 775,
  "switchcmd": "Toggle"
}
but I get this in domoticz log:

Code: Select all

[WebServer] Deprecated RType () for API request. Call ignored, please use correct API Command! (192.168.x.x)
User avatar
habahabahaba
Posts: 192
Joined: Saturday 18 March 2023 14:44
Target OS: Windows
Domoticz version: 2024.4
Contact:

Re: JSON call behind Nginx reverse proxy

Post by habahabahaba »

Hi.
Are you using zigbee plugin and what is the version of Domoticz?

https://zigbeefordomoticz.github.io/wik ... pi-command
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: JSON call behind Nginx reverse proxy

Post by waltervl »

ressof wrote: Wednesday 04 September 2024 8:47 I tried with https://reqbin.com/post-online

I used this post:

Code: Select all

POST /json.htm HTTP/1.1
Authorization: Basic [Base64 encoded uername:password]
Host: [domain]
Accept: application/json
Content-Type: application/json
Content-Length: 88

{
  "type": "command",
  "param": "switchlight",
  "idx": 775,
  "switchcmd": "Toggle"
}
but I get this in domoticz log:

Code: Select all

[WebServer] Deprecated RType () for API request. Call ignored, please use correct API Command! (192.168.x.x)
Better try the html version. But I am not sure it will work with this application. From what remote application do you want to send the JSON command in the end?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

In the end I want to use my Amazfit Watch that has a html app that looks like this

Image
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

habahabahaba wrote: Wednesday 04 September 2024 9:51 Hi.
Are you using zigbee plugin and what is the version of Domoticz?

https://zigbeefordomoticz.github.io/wik ... pi-command
I dont use zigbeefordomoticz, I use zigbee2mqtt
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

I have tested with some different online json post tester and it seems that when the content is in this form it works:

Code: Select all

type=command&param=switchlight&idx=775&switchcmd=Toggle
but when it is json formatted like this it does not work

Code: Select all

{"type":"command","param":"switchlight","idx":"775","switchcmd":"Toggle"}
Is this something that can be fixed?
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: JSON call behind Nginx reverse proxy

Post by waltervl »

In the app you cannot use as URL the complete URL (so empty body in the app)?

Code: Select all

https://yourdomain/json.htm?type=command&param=switchlight&idx=775&switchcmd=Toggle
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

That worked when I added

Code: Select all

Content-Type: application/x-www-form-urlencoded
in header.

Thank you
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

But when I try to change a selector switch I get this error

Code: Select all

{
	"message" : "Error sending switch command, check device/hardware (idx=193) !",
	"status" : "ERROR",
	"title" : "SwitchLight"
}
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: JSON call behind Nginx reverse proxy

Post by waltervl »

Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

I think so, this i the command I ran:

Code: Select all

/json.htm?type=command&param=switchlight&idx=193&switchcmd=Set%20Level&level=40
User avatar
waltervl
Posts: 5148
Joined: Monday 28 January 2019 18:48
Target OS: Linux
Domoticz version: 2024.7
Location: NL
Contact:

Re: JSON call behind Nginx reverse proxy

Post by waltervl »

From a browser it works? Level 40 is a valid level number?
Domoticz running on Udoo X86 (on Ubuntu)
Devices/plugins: ZigbeeforDomoticz (with Xiaomi, Ikea, Tuya devices), Nefit Easy, Midea Airco, Omnik Solar, Goodwe Solar
ressof
Posts: 60
Joined: Thursday 20 April 2017 7:20
Target OS: Linux
Domoticz version: Latest
Contact:

Re: JSON call behind Nginx reverse proxy

Post by ressof »

From a browser it worked. But from the logs in Domoticz it lead me to try this from the app instead of last command

Code: Select all

/json.htm?type=command&param=switchlight&idx=193&switchcmd=Set Level&level=40
a space between "Set Level" instead of %20 and now it works

Thank you for your help.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest