REST sensor url-encoded Payload - Requires brackets

I am attempting to call keycloak’s API to retrieve a JWT in order to auth with an API I am self hosting.

My rest sensor configs are:

  - platform: rest
    resource: http://192.168.1.136:28080/auth/realms/master/protocol/openid-connect/token
    name: rest.HA_LakeFront_Api_Bearer_Token
    method: POST
    scan_interval: 1
    value_template: "{{ value_json }}"
    payload: '{"grant_type=client_credentials&client_id=homeassistant&client_secret=nope"}'
    headers:
      Content-Type: application/x-www-form-urlencoded

I have to include the brackets before and after the url-encoded payload in order for HA to send the request successfully.

The issue, they are sent to keycloak, which makes the request fail.

pcap screenshot:

Is this a limitation/bug with the rest sensor or I am doing something incorrect?

Bumping to hopefully get an answer.

Sorry I don’t have anything where I can try this, so I can only provide unverified guesses:

Can you send the payload as a dict to see if it gets form encoded?

payload: '{"grant_type":"client_credentials", "client_id":"homeassistant", "client_secret":"nope"}'

or perhaps:

payload: '{"grant_type":"client_credentials", "client_id":"homeassistant", "client_secret":"nope"} | tojson'

What is the expected content type ?
It seems you are mixing things.

Have you tried to use the code below ?

payload:
  grant_type: client_credentials
  client_id: homeassistant
  client_secret: nope
headers:
  Content-Type: application/json

I don’t know if it will work.
It depends on the expected content type.

I ended up using curl in a command_line sensor