API Calls from outside network

Hi,

This may be a stupid question, but I can’t figure it out… I installed AppDaemon on HASSio as a plug-in and configured the API to listen on port 3030. NGINX can forward calls to this port from outside (exposed as 443). How do I make remote calls to the AppDaemon API from outside my network? And how do I passs on authentication info to the app? The documentation says:

"To call into a specific App, construct a URL, use the regular HADashboard URL, and append /api/appdaemon, then add the name of the endpoint as registered by the app on the end, for example:

http://192.168.1.20:5050/api/appdaemon/hello_endpoint

This URL will call into an App that registered an endpoint named hello_endpoint."

That is obviously wrong and doesn’t work, even from inside my network using port 3030 as configured. Any clue?

BTW, everything else seems to work, including the Dashboard.

Thanks!

you cant just do it from your browser, but you can do it from a curl statement out of a terminal.

the url would work from a browser if you didnt set a pwd.

from the outside you did expose 443?
and what port for HA?
and what for the dashboard?

obviously nginx needs to be setup to listen for 3 different things to forward to 3 different servers.
could be helpfull for other when you show how you did setup nginx.

Can’t do it using HTTPS from outside my network? I’m surprised… Is that really the case? I thought that’s why the API was built for.

Yes, API port 3030 is exposed on 443 on the outside using NGINX. On my router, I simply forward 443 to 443 on NGINX. Here is my config:

> {
>   "vhosts": [
>     {
>       "vhost": "mydomain1.duckdns.org",
>       "port": "8123",
>       "default_server": true,
>       "certname": "hass"
>     },
>     {
>       "vhost": "mydomain2.duckdns.org",
>       "port": "3030",
>       "default_server": false,
>       "certname": "API"
>     }
>   ]
> }

I don’t really use the AppDaemon dashboard, at least outside my network, so I did not forward it. I installed AppDeamon to use the API outside my network and run Python scripts that way. In particular, to interact with Amazon Alexa/Echo.

Thanks!

You can, you just need to make sure the forwarding is setup correctly in NGINX - you configure the port the API listens on in the config file, and, the IP address is the Internal IP address of AD, you need to a to that from NGINX

I already have that configured. The API port is configured as 3030 and NGINX exposes that port as 443 on the Internet (with its own name and valid SSL certificate as seen above in my config). Now, what is the URL I need to use?

https://myPublicName/whatElse

Like I said, https://myPublicName/api/appdaemon/myApp does not work

Thanks!

i might be mistaken, but to me it seems that you configured it the way that NGINX listens to port 8123 and port 3030. and not to port 443.

you cant have 2 ports in 1 url.

Two different URLs: mydomain1.duckdns.org AND mydomain2.duckdns.org Two different virtual hosts…

but you let nginx listen to 8123 for mydomain1 and to 3030 for mydomain2.

so as i see it you should use

http://mydomain1.duckdns.org:8123 and
http://mydomain2.duckdns.org:3030

to tell nginx where to go to.

No. Unless I don’t understand how NGINX and Virtual hosts work. NGINX and HASS are installed on the same host. It should be (all SSL/443 port):

https://mydomain1.duckdns.org - NGINX forwards this to HASS local 8123 port (and works!)
https://mydomain2.duckdns.org - NGINX forwards this to the same host as HASS but on port 3030 (and I can’t make it work)

then i guess it is my lack of knowledge from nginx. :wink:

you say it doesnt work, but how do you test if it works? you cant use a browser for that.
try a curl command from a terminal.

I’m sure I can use a browser. That’s what the API is for! cURL command does not work. At least, I can’t make it work. Do you have an example of a cURL command? I tried variations of:

curl -i -X POST -H "Content-Type: application/json" http://myLocalIP:3030/api/appdaemon/myApp -d '{"type": "Hello World Test"}'

to no avail. It’s like the server was not listening on 3030. But logs says that the API is running.

i know that when api just arrived in AD i did try it and it didnt work from a browser (and andrew said that wouldnt work)
i did try some curl commands and finally got it to work.

now i only use it for alexa.

but whats in the app?

Would you mind sharing your configuration and how you use it? Do you have Alexa interactions/dialogs working to fill in slots when they are not provided?

yeah i have complete interaction working.


class alexa_api(appapi.AppDaemon):

    def initialize(self):
        self.register_endpoint(self.api_call)        

    def api_call(self, data):
      self.log(data)

Thanks. And how do you use cRUL commands to AppDaemon in all of this?

im a total dep with curl, but i did look at the curl commands that are in the rest api docs from HA and did change them to use with AD.

i only used it to test if it was working before i started with alexa.

i really didnt see any usecase for it other then that in the moment.

Ok, let me ask this differently… When you built your Alexa skill using the Amazon Developer console, how did you configure your Endpoint? Do you call your own instance (which is what I wanted to use AppDaemon for) or do you use Lambda? If you use your own instance, what HTTPS address are you calling?

i never used lambda because you need a creditcard which i dont own.

in the skill kit i used this url:

https://mydomain.duckdns.org/api/appdaemon/alexa_api?api_password=mypasword

Ah, great… That’s what I was looking for. Did you activate the API at all (ie, did you set it to a different port than the dashboard)? If I don’t put in a port for the API in the Appdaemon configuration file, the log tells me that the API is not started.

Also, which HASS intall do you use? I use HASSio, along with the Community AppDaemon plug-in. Thanks!

i have 2 different ports set for the dashboard and for the API.
obviously when you dont give a port for the API it isnt reachable.

i have HA just with a normal (pip) install
hassio could make it difficult to setup these kind of complicated setups, but it should be possible.