# Based on: https://www.odoo.com/documentation/15.0/developer/howtos/backend.html#json-rpc-library
HOST = "mycompanyname.odoo.com"
PORT = 443 # Default port for the Odoo.sh cloud version.
url = f"https://{HOST}:{PORT}/jsonrpc"
PASSWORD = "some secret PW"
def json_rpc(url, method, params):
"id": random.randint(0, 1000000000),
"Content-Type":"application/json",
reply = requests.get(url=url, data=json.dumps(data).encode(), headers=headers)
json_response = reply.json()
error = json_response.get("error")
raise Exception(json_response["error"])
return json_response["result"]
def make_request(url, service, method, *args):
return json_rpc(url, "call", {"service": service, "method": method, "args": args})
# Get the user is for further calls.
uid = make_request(url, "common", "login", DB, USER, PASS)