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:

  - platform: rest
    resource: !secret awair-resource
      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:

  - platform: rest
    resource: !secret awair-resource
    method: GET
      x-api-key: !secret awair-api-key
    name: awair_raw
    value_template: "OK"
    json_attributes_path: "$"
      - 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:

        {"timestamp": "2024-06-19T00:30:25.000Z",
        "score": 90,
                {"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}
                {"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:

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

  - platform: template
        friendly_name: "awair_score"
        value_template: "{{ states.sensor.awair_test.attributes.data[0].score }}"
        unit_of_measurement: "%"
        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!