RestAPI, Bad Request

Hi,

I’m trying to send some text to conversation integration over RestAPI (at the moment using python script), but I’m getting “400: Bad Request”.

import requests
import json

url = 'http://192.168.50.21:8123/api/services/conversation/process'
headers = {
    'Authorization': 'Bearer my_long_lived_token',
    'content-type': 'application/json'
    }
payload = {
    'service_data':{
        "text": "Turn all lights on"
        }
    }

response = requests.post(url, headers=headers, data=json.dumps(payload))
print(response.text)
print(response.status_code)


Can anyone spot the mistake?
PS: I’m quite new to coding so the whole thing might be misunderstood from my side.

Same thing happens to me, i cannot post any message. I even tried with “Curl” commands and i always getting: “Bad Reqeust: 400”

curl -X get -H "Authorization: Bearer ******* " -H “Content-Type: application/json” -d ‘{“entity_id”:“light.salon”}’ http://**********:8123/api/services/light/turn_on

I’m getting the same exact error message when using curl (from windows). I first thought this was a Windows-related issue. However, it looks like it’s caused by something else. Did anyone figure out what to do or did you give up? When I search for a solution on google, this thread pops up people with the same issue without a solution.

There was another person who had this same issue when using javascript to post. He said he had to add a JSON.stringify() to the body of the POST. I have no idea what that means when using curl.

https://www.reddit.com/r/homeassistant/comments/80fd7r/help_using_the_api_to_post/