Hi All,
just getting started with AppDaemon and I’m looking to set up an API Endpoint.
I’m just setting up a dummy one at the moment with the goal being to have Alexa call into the endpoint.
Here is my app
class HelloWorld(appapi.AppDaemon):
def initialize(self):
self.log("Hello from AppDaemon")
self.log("Ian, You are now ready to run Apps!")
self.register_endpoint(self.my_callback,"hello")
def my_callback(self, data):
self.log('api called')
response = {"message": "Hello World"}
return response, 200
2017-08-30 19:42:31.465215 INFO App initialization complete
2017-08-30 19:42:31.466219 INFO Starting dashboard
2017-08-30 19:42:31.484670 INFO Starting API
2017-08-30 19:42:31.678139 INFO Connected to Home Assistant 0.51.2
Ahh, that’s the problem - you are tyring to use a GET method by hitting it with your browser, only the POST method is supported. You can use CURL to test it like in the docs.
curl -i -X POST -H "Content-Type: application/json" http://192.168.0.20:5050/api/appdaemon/hello -d '{"type": "Hello World Test"}'
HTTP/1.1 404 Not Found
Content-Type: text/plain; charset=utf-8
Content-Length: 14
Date: Wed, 30 Aug 2017 20:09:02 GMT
Server: Python/3.6 aiohttp/2.2.5
404: Not Found
Still getting a 404, I can see the request is definately hitting the aiohttp server alright…
yeah they were on the same port (the docs say to use the regular HADashboard URL though) , I moved it to port 5555 (nothing else is using that) and restarted appdaemon and now I get this…
curl -i -X POST -H "Content-Type: application/json" http://192.168.0.20:5555/api/appdaemon/alexa -d '{"type":
"Test"}'
curl: (7) Failed to connect to 192.168.0.20 port 5555: Connection refused
I’m running on docker if that makes a difference, i don’t think it does.
When I run netstat -lntu I dont see any processes listening on port 5555 so it looks like the API server isnt coming up.
If you’re running in a docker container, make sure you mapped the container port to the host, otherwise you can’t communicate with the API running inside the container.
You set the host to container port mapping when you’re instantiating the container with a “docker run” command or you need to set it as a parameter in your docker-compose.yml file if you’re using that approach.