Add content-type to curl (#531)

This commit is contained in:
Fabian Affolter 2016-06-04 17:38:33 +02:00
parent 36f0192053
commit 258d4172d8
6 changed files with 42 additions and 20 deletions

View File

@ -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"}'
```

View File

@ -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
```

View File

@ -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",

View File

@ -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

View File

@ -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 %}

View File

@ -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`)