Input_select and curl command line - problem

Hi all,
I have a problem to set a specific state of input_select, my command looks like:
curl -X POST -H "x-ha-access: APIPASS" \ -H "Content-Type: application/json" \.-d '{"entity_id": "input_select.amplituner_input", "state": "CD"}' \ http://192.168.1.5:8123/api/services/input_select/select_option

but id doesn’t work.

btw. command to set next option works fine:

curl -X POST -H "x-ha-access: APIPASS" \ -H "Content-Type: application/json" \.-d '{"entity_id": "input_select.amplituner_input"}' \ http://192.168.1.5:8123/api/services/input_select/select_next

Please help, i’m sure that something is wrong.

You should be using “option” not “state” in your JSON

1 Like

Ok, so I used this command:
curl -X POST -H "x-ha-access: APIPASS" \ -H "Content-Type: application/json" \.-d '{"entity_id": "input_select.amplituner_input", "option": "CD"}' \ http://192.168.1.5:8123/api/services/input_select/select_option
and… it doesn’t work :frowning:
code of input_select is:

input_select:
  amplituner_input:
    name: amplituner input
    options:
     - Select
     - CD
     - DVD
    initial: Select

I don’t know what is wrong :frowning:

Can’t see much wrong with that, would try removing any spaces in the JSON data

The data looks the same as from my http shortcuts app, which works successfully every day. What response code are you getting?

This is the situation:
Code:

curl -X POST -H "x-ha-access: APIPASS" http://localhost:8123/api/services/input_select/select_next

This command works for all input_select and it is ok.

Code:

curl -X POST -H "x-ha-access: APIPASS" -H "Content-Type: application/json" -d '{"entity_id": "input_select.amplituner_input", "option": "CD"}' http://192.168.1.5:8123/api/services/input_select/select_option

Response from CMD:

curl: (6) Could not resolve host: input_select.amplituner_input,
curl: (6) Could not resolve host: option
curl: (3) [globbing] unmatched close brace/bracket in column 3
{"message": "Data should be valid JSON"}

Ok, I figured out this, on Windows it should like to be like: -d “{ “key1”: “value1” }”

Windows (command prompt) also requires triple quotes around the JSON items e.g.

"""entity_id""":

Escaping with a \ doesn’t work and neither does turning on globbing (-g).

For Powershell you need to run curl with the —% (dash dash percent) parameter and use \ to escape the quotes :


\"entity_id\": 

Excuse the weird quotes. Apple goes their own way.