Template sensor issue for rest

hello,
I am trying to get football score from air using the below template but it keep giving me the below error

Invalid config for [sensor.rest]: template value should be a string for dictionary value @ data[‘headers’][‘json_attributes’]. Got [‘api’]. (See ?, line ?).

template sensor is

- platform: rest
 name: Team 2929 Goals
  resource: https://api-football-v1.p.rapidapi.com/v2/statistics/2929/league/4
 method: GET
scan_interval: 3600 # Set the update interval in seconds (e.g., every hour)
 value_template: "{{ value_json[api.statistics[0].team_name] }} Goals: {{ value_json[api.statistics[0].goals.for] }}"
  headers:
    X-RapidAPI-Host: api-football-v1.p.rapidapi.com
   X-RapidAPI-Key: YOUR_API_KEY # Replace with your actual API key
    json_attributes:
     - api 

According to the documentation, the example you posted contains incorrect indentation.

It should look like this:

- platform: rest
  name: Team 2929 Goals
  resource: https://api-football-v1.p.rapidapi.com/v2/statistics/2929/league/4
  method: GET
  scan_interval: 3600 # Set the update interval in seconds (e.g., every hour)
  value_template: "{{ value_json[api.statistics[0].team_name] }} Goals: {{ value_json[api.statistics[0].goals.for] }}"
  headers:
    X-RapidAPI-Host: api-football-v1.p.rapidapi.com
    X-RapidAPI-Key: YOUR_API_KEY # Replace with your actual API key
  json_attributes:
    - api

It may also need the json_attributes_path option

thanks for your feedback, I have used your code and it did not give any error and I shows the sensor but only the sensor name no other attributes,

Then original problem was this:

It was due to incorrect indentation which is solved by the example I posted above.

The sensor’s inability to report “other attributes” is a separate problem. The configuration you created for value_template and/or json_attributes may be incorrect.

In order to help you, I would need to see an example of the JSON data reported by https://api-football-v1.p.rapidapi.com/v2/statistics/2929/league/4. Alternately, is this sensor’s configuration based on an example you saw elsewhere?

@123 this is what I should get from it


* "get": "standings",

* "parameters": {
  * "league": "39",

  * "season": "2019"},

* "errors": [ ],

* "results": 1,

* "paging": {
  * "current": 1,

  * "total": 1},

* "response": [
  * {}]

} ```

You configured the json_attributes option to look for a key named api.

  json_attributes:
    - api

However, you claim the received data looks like this but it doesn’t contain an api key.

{
	"get": "standings",
	"parameters": {
		"league": "39",
		"season": "2019"
	},
	"errors": [],
	"results": 1,
	"paging": {
		"current": 1,
		"total": 1
	},
	"response": [{}]
}

I suggest you remove the json_attributes option from the sensor’s configuration.


EDIT

Are you certain that the data example you posted is correct? It doesn’t even have a statistics key or team_name or goals yet all three are referenced by your value_template option:

{{ value_json[api.statistics[0].team_name] }}
 Goals: {{ value_json[api.statistics[0].goals.for] }}

I don’t think you posted all of the data, only (maybe) the last part of it.