API GET request error with AWAIR sensor

Hello everyone

I have been trying to call an API using a GET request for one of my sensors, without success. Everything works with curl or using requests in python, but I can’t seem to do it in the HA environment. The sensor in my dashboard shows the following:

{'code': 5, 'message': 'Not Found', 'details': []}

Here is my configuration.yaml file:

sensor:
  - platform: rest
    resource: !secret awair-resource
    headers:
      x-api-key: !secret awair-api-key
    name: Awair_raw
    value_template: "{{ value_json }}"

and here is how I wrote my secret.yaml file:

awair-api-key: "a1a1a1a1a1a1a1a"
awair-resource: https://developer-apis.awair.is/v1/orgs/[a random id]/devices/awair-omni/[a random id]/air-data/latest"

When I do the following command w/ cURL, it returns my .json file of interest:

curl --location 'https://developer-apis.awair.is/v1/orgs/[a random id]/devices/awair-omni/[a random id]/air-data/latest' \
--header 'x-api-key: a1a1a1a1a1a1a1a'

Thanks a bunch for your help!

After doing some research, I figured that my json file was longer than 255 characters and couldn’t be used as a value_template. Value attributes, however, seem find to handle +255 characters. Here is the code I wrote:

sensor:
  - platform: rest
    resource: !secret awair-resource
    method: GET
    headers:
      x-api-key: !secret awair-api-key
    name: awair_raw
    value_template: "OK"
    json_attributes_path: "$"
    json_attributes:
      - data

Now I get this error:

WARNING (MainThread) [homeassistant.components.rest.util] JSON result was not a dictionary or list with 0th element a dictionary

I am super confused since my API calls work just fine in any other platform… Here is what the json file looks like usually:

{"data": 
    [
        {"timestamp": "2024-06-19T00:30:25.000Z",
        "score": 90,
        "sensors": 
            [
                {"comp": "spl_a", "value": 53.7},
                {"comp": "voc", "value": 99},
                {"comp": "humid", "value": 55.68},
                {"comp": "co2", "value": 594},
                {"comp": "lux", "value": 233.6},
                {"comp": "pm10_est", "value": 2.2175000000000002},
                {"comp": "pm25", "value": 1},
                {"comp": "score", "value": 90},
                {"comp": "temp", "value": 24.23}
            ],
        "indices": 
            [
                {"comp": "humid", "value": 1},
                {"comp": "temp", "value": 0},
                {"comp": "pm10_est", "value": 1.2054},
                {"comp": "pm25", "value": 0},
                {"comp": "co2", "value": 0},
                {"comp": "voc", "value": 0}
            ]
        }
    ]
}

Thanks a bunch

Ok I found out a workaround. I use the command line function instead of the RESTful sensor to retrieve my sensor’s data. Here is the code I use:

command_line:
  - sensor:
      name: awair_test
      command:
        "curl --location 'url' \
        --header 'x-api-key: api_key'"
      value_template: "OK"
      json_attributes:
        - data

sensor:
  - platform: template
    sensors:
      awair_score:
        friendly_name: "awair_score"
        value_template: "{{ states.sensor.awair_test.attributes.data[0].score }}"
        unit_of_measurement: "%"
      awair_temp:
        friendly_name: "awair_temp"
        value_template: "{{ states.sensor.awair_test.attributes.data[0].sensors | selectattr('comp', 'equalto', 'temp') | map(attribute='value') | first }}"
        unit_of_measurement: "ºC"

I am going to flag this as the solution and I hope it helps anyone that runs into similar issues in the future!
Cheers