Problem with rest_command and a get request

Hi, i’m trying to learn about rest_command for a project that i’m trying to do. I read the documentation but i cant see how to attach more info to the request url. In the code below i’m trying to call the api of a video game website.
The basic idea is get the cover of a game getting the name before with a sensor in home assistant and send it with the api request.
If i add all the keys and data to the url works well but i will need to use the value of a sensor (the name of the videogame) to send with the request. If i understood the documentation correctly you can send data in the payload but not working in my case. Any clue will be appreciated. Thanks in advance

rest_command:
  trigger_mobygames_service:
    url: "https://api.mobygames.com/v1/games"
    method: get
    headers:
      accept: 'application/json; charset=UTF-8'
      content_type: 'application/json; charset=utf-8'
    content_type: 'application/x-www-form-urlencoded'
    payload: '{api_key=SECRETKEY&title=Starfield&platform=289&format=brief}'

You can template the URL. So, avoid using payload and just add your template to URL:

rest_command:
  trigger_mobygames_service:
    url: "https://api.mobygames.com/v1/games/api_key=SECRETKEY&title={{ states('sensor.sensor') }}&platform=289&format=brief"
    method: get
    headers:
      accept: 'application/json; charset=UTF-8'
      content_type: 'application/json; charset=utf-8'
    content_type: 'application/x-www-form-urlencoded'

Oh! That’s great. :smiley: thank you very much

1 Like