Config checkwx command_line syntax help

Hi - trying to get a simple command to checkwx.com to get aviation weather details. I have searched and played a lot on the syntax but can’t get it to work. Any help or pointers would be great. So syntax I have (in configuration.yaml) is:

  - platform: command_line
    name: checkwx_metar
    command: >-
      "curl 'https://api.checkwx.com/metar/egsc' -H 'X-API-Key: my key'"
    value_template: "{{ value_json['data'][0] }}"

The error in the log file is:
2019-08-25 11:36:46 ERROR (SyncWorker_1) [homeassistant.components.command_line.sensor] Command failed: “curl ‘https://api.checkwx.com/metar/egsc’ -H ‘X-API-Key: my key’”

Interestingly if I try the command line in Chrome browser I get an error:
:
{“statusCode”:400,“error”:“Bad Request”,“message”:“headers should have required property ‘x-api-key’”}

Would be great to get this working - many thanks for any ideas… Then I will need to pick up my api from my secrets.yaml file. Again any pointers for this would also be a great help…

John

Have you tried with a trailing / on the url?

Thanks Andrew - amazing what you don’t see in the documentation - clearly needs one. Added but still no joy. log shows “command failed” and if I try using Chrome - different error 404 “not found” but tried a range of major airport codes.

Any more ideas…?

John

Not really. Try the header parameters before the url?

Thanks Andrew - still no joy.

Regards

John

For anyone interested, here was the final curl command that worked for him:

curl “https://api.checkwx.com/metar/egll/” -H “X-API-Key:my key”

curl “https://api.checkwx.com/metar/YBBN” --ssl-no-revoke -H “X-API-Key: myapikey”

gives

{“data”:[“YBBN 100600Z 12010KT CAVOK 20/14 Q1021”],“results”:1}

How do you get this into a card ?

For anyone else who comes across this post who is trying to get this working.

I was also able to get it working using REST with the configuration below.
This creates two sensors with TAF and METAR information.

Update the sensor name, URL for your airport and the API key with your key. You can customise the scan interval depending on how often you want to update the sensor.

sensor:
    - platform: rest
    name: yssy_metar
    resource: https://api.checkwx.com/metar/yssy/decoded
    headers:
      X-API-Key: "myapikey"
    value_template: '{{ value_json.data[0].raw_text }}'
    scan_interval: 300

  - platform: rest
    name: yssy_taf
    resource: https://api.checkwx.com/taf/yssy/decoded
    headers:
      X-API-Key: "myapikey"
    value_template: '{{ value_json.data[0].raw_text }}'
    scan_interval: 1800