Api url setup

Hi
How do I create a url such as http://hassio.local:8123/api/script/turn_on
I have looked at RESTApi which doesn’t make much sense I’m trying to make amazon dash buttons work.
Thanks

you dont need to create it.
its just there if you have hass running.

you need to use the url that you use to look at hass in your browser

if http://hassio.local:8123 shows your hass then you can use:
http://hassio.local:8123/api/ … to reach the api
turn_on is a service so you need something like:
http://hassio.local:8123/api/services/script/turn_on
and after that you need to give your password (if set and the script that you want to turn on.

Do I need like a config.json with some code in so when that url is entered it runs config.json or something

no you dont need anything.
the API is part of the server you are running (homeassistant)

if you enter the correct url it gets to your homeassistant ver and tht server knows what to do with that url.

but you need to provide the correct data in the url.

So
http://hassio.local:8123/api/services/script/turn_on
How do I make that turn on a light from scratch
Do I create a script?

you use script if you want to turn on a script, or switch if you want to turn on a switch or any other service which you want to use.

services and what data to provide can be found in you homeassistant developer tools

Could I have
http://hassio.local:8123/api/services/switch.monster_plug/turn_on
Or how would I get a switch to change state from off to on

What is a domain if it’s not an entity id

domains are the part before the dot.

so in switch.myswitch
the entity = switch.myswitch
the entity_id = myswitch
the domain = switch

Is the “/api” always there with Hassio?
I’m having trouble setting up the Google Assistant component only because “https://HA_Installation/api/google_assistant/auth” gives me a 404 error. So does /api and /api/google_assistant

Do I put what script I need to us after the /turn_on

Hi
So if I were to turn on 'scene.night’
it would be
http://hassio.local:8123/api/services/scene/turn_on
then what next
Thank you for your help by the way it is really helpful.

You must also append your HA Password by putting
“?api_password=MyHAPassword”

something like ?enity=night or entity_id=night and a password if you have set one.
but i am quite sure that if you search the forum you will find out what you need to use exactly.

thank you very much for your help I’ve figured it out

make it easy for the next who is searching and post what is working for you.

I used Dasher for amazon dash and this was my config including the entity_id in the body separate from the url02

1 Like

Hi,
For anyone else who encounters this - you need to append a “/” to the end.
so that will be: http://your hass ip/api/

good luck! :slight_smile:

<Holy thread resurrection, Batman!>

… and just to make it really clear for beginners like me, the following;

    http://192.168.0.2:8123/api/?api_password=password

should return

    {"message": "API running."}

where

  • the ip address will be the IP of the computer running home assistant, and
  • the password is the value of ‘http_password:’ in your configuration.yaml

Any additional URL parts required will go between …/api/ and ?api_password

Hope this helps,

1 Like