From 258d4172d86957e3a7948c0aa38d45a985021170 Mon Sep 17 00:00:00 2001 From: Fabian Affolter Date: Sat, 4 Jun 2016 17:38:33 +0200 Subject: [PATCH] Add content-type to curl (#531) --- .../_components/binary_sensor.http.markdown | 5 ++- source/_components/notify.mqtt.markdown | 1 + source/_components/sensor.http.markdown | 6 ++- source/_components/switch.mystrom.markdown | 2 +- source/developers/rest_api.markdown | 45 +++++++++++++------ source/developers/server_sent_events.markdown | 3 +- 6 files changed, 42 insertions(+), 20 deletions(-) diff --git a/source/_components/binary_sensor.http.markdown b/source/_components/binary_sensor.http.markdown index aa279efb200..dff711e5709 100644 --- a/source/_components/binary_sensor.http.markdown +++ b/source/_components/binary_sensor.http.markdown @@ -40,7 +40,8 @@ To check if the sensor is working, use again `curl` to retrieve the [current sta ```bash $ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ - http://localhost:8123/api/states/binary_sensor.radio + -H "Content-Type: application/json" \ + http://localhost:8123/api/states/binary_sensor.radio { "attributes": { "friendly_name": "Radio" @@ -74,6 +75,6 @@ print(response.text) ```bash $ http -v POST http://localhost:8123/api/states/binary_sensor.radio \ - x-ha-access:YOUR_PASSWORD state=off \ + x-ha-access:YOUR_PASSWORD content-type:application/json state=off \ attributes:='{"friendly_name": "Radio"}' ``` diff --git a/source/_components/notify.mqtt.markdown b/source/_components/notify.mqtt.markdown index 1f42e72e43d..ff768f99dc7 100644 --- a/source/_components/notify.mqtt.markdown +++ b/source/_components/notify.mqtt.markdown @@ -27,6 +27,7 @@ Using the [REST API](/developers/rest_api/#post-apiservicesltdomainltservice) to ```bash $ curl -X POST -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ -d '{"payload": "Test message from HA", "topic": "home/notification"}' \ http://IP_ADDRESS:8123/api/services/mqtt/publish ``` diff --git a/source/_components/sensor.http.markdown b/source/_components/sensor.http.markdown index b9586d01fe6..fc294d49470 100644 --- a/source/_components/sensor.http.markdown +++ b/source/_components/sensor.http.markdown @@ -31,7 +31,8 @@ You should choose a unique device name (DEVICE_NAME) to avoid clashes with other For a quick test `curl` can be useful to "simulate" a device. ```bash -$ curl -XPOST -H "x-ha-access: YOUR_PASSWORD" \ +$ curl -X POST -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ -d '{"state": "20", "attributes": {"unit_of_measurement": "°C", "friendly_name": "Bathroom Temp"}}' \ http://localhost:8123/api/states/sensor.bathroom_temperature ``` @@ -40,7 +41,8 @@ Use again `curl` to retrieve the [current state](/developers/rest_api/#get-apist ```bash $ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ - http://localhost:8123/api/states/sensor.bathroom_temperature + -H "Content-Type: application/json" \ + http://localhost:8123/api/states/sensor.bathroom_temperature { "attributes": { "friendly_name": "Bathroom Temp", diff --git a/source/_components/switch.mystrom.markdown b/source/_components/switch.mystrom.markdown index e5bdac5b17d..ce1652662b6 100644 --- a/source/_components/switch.mystrom.markdown +++ b/source/_components/switch.mystrom.markdown @@ -32,7 +32,7 @@ Configuration variables: Check if you are able to access the device located at `http://IP_ADRRESS`. The details about your switch is provided as a JSON response. ```bash -$ curl -X GET http://IP_ADDRESS/report +$ curl -X GET -H "Content-Type: application/json" http://IP_ADDRESS/report { "power": 0, "relay": false diff --git a/source/developers/rest_api.markdown b/source/developers/rest_api.markdown index 1d6fb5b62b8..4f4020fa032 100644 --- a/source/developers/rest_api.markdown +++ b/source/developers/rest_api.markdown @@ -21,6 +21,7 @@ There are multiple ways to consume the Home Assistant Rest API. One is with `cur ```bash curl -X GET \ -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ http://IP_ADDRESS:8123/ENDPOINT ``` @@ -64,7 +65,8 @@ Returns message if API is up and running. Sample `curl` command: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/ +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" http://localhost:8123/api/ ``` #### {% linkable_title GET /api/config %} @@ -96,7 +98,8 @@ Returns the current configuration as JSON. Sample `curl` command: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/config +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" http://localhost:8123/api/config ``` #### {% linkable_title GET /api/discovery_info %} @@ -114,7 +117,8 @@ Returns basic information about the Home Assistant instance as JSON. Sample `curl` command: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/discovery_info +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" http://localhost:8123/api/discovery_info ``` #### {% linkable_title GET /api/bootstrap %} @@ -132,7 +136,8 @@ Returns all data needed to bootstrap Home Assistant. Sample `curl` command: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/bootstrap +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" http://localhost:8123/api/bootstrap ``` #### {% linkable_title GET /api/events %} @@ -154,7 +159,8 @@ Returns an array of event objects. Each event object contain event name and list Sample `curl` command: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/events +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" http://localhost:8123/api/events ``` #### {% linkable_title GET /api/services %} @@ -181,7 +187,8 @@ Returns an array of service objects. Each object contains the domain and which s Sample `curl` command: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/services +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" http://localhost:8123/api/services ``` #### {% linkable_title GET /api/history %} @@ -217,11 +224,15 @@ Returns an array of state changes in the past. Each object contains further deta Sample `curl` commands: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/history/period/2016-02-06 +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ + http://localhost:8123/api/history/period/2016-02-06 ``` ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/history/period/2016-02-06?filter_entity_id=sensor.temperature +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ + http://localhost:8123/api/history/period/2016-02-06?filter_entity_id=sensor.temperature ``` #### {% linkable_title GET /api/states %} @@ -247,7 +258,8 @@ Returns an array of state objects. Each state has the following attributes: enti Sample `curl` command: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/states +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" http://localhost:8123/api/states ``` #### {% linkable_title GET /api/states/<entity_id> %} @@ -273,7 +285,8 @@ Sample `curl` command: ```bash $ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ - http://localhost:8123/api/states/sensor.kitchen_temperature + -H "Content-Type: application/json" \ + http://localhost:8123/api/states/sensor.kitchen_temperature ``` #### {% linkable_title GET /api/error_log %} @@ -289,6 +302,7 @@ Sample `curl` command: ```bash $ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ http://localhost:8123/api/error_log ``` @@ -298,8 +312,9 @@ Returns the data (image) from the specified camera entity_id. Sample `curl` command: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD"\ - http://localhost:8123/api/camera_proxy/camera.my_sample_camera?time=1462653861261 -o image.jpg +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ + http://localhost:8123/api/camera_proxy/camera.my_sample_camera?time=1462653861261 -o image.jpg ``` #### {% linkable_title POST /api/states/<entity_id> %} @@ -336,6 +351,7 @@ Sample `curl` command: ```bash $ curl -X POST -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ -d '{"state": "25", "attributes": {"unit_of_measurement": "°C"}}' \ http://localhost:8123/api/states/sensor.kitchen_temperature ``` @@ -393,6 +409,7 @@ Sample `curl` command: ```bash $ curl -X POST -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" \ -d '{"entity_id": "switch.christmas_lights", "state": "on"}' \ http://localhost:8123/api/services/switch/turn_on ``` @@ -420,8 +437,8 @@ Sample `curl` command: ```bash $ curl -X POST -H "x-ha-access: YOUR_PASSWORD" \ - -d '{"template": "It is {{ now }}!"}' \ - http://localhost:8123/api/template + -H "Content-Type: application/json" \ + -d '{"template": "It is {{ now }}!"}' http://localhost:8123/api/template ``` #### {% linkable_title POST /api/event_forwarding %} diff --git a/source/developers/server_sent_events.markdown b/source/developers/server_sent_events.markdown index 972d3e76992..dd88245ce9e 100644 --- a/source/developers/server_sent_events.markdown +++ b/source/developers/server_sent_events.markdown @@ -18,7 +18,8 @@ A requirement on the client-side is existing support for the [EventSource](https There are various ways to access the stream. One is `curl`: ```bash -$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" http://localhost:8123/api/stream +$ curl -X GET -H "x-ha-access: YOUR_PASSWORD" \ + -H "Content-Type: application/json" http://localhost:8123/api/stream ``` For more comfort put the HTML snippet below in a file `sse.html` in your `www` folder of your Home Assistant configuration directory (`.homeassistant`)