Last active
August 13, 2024 08:54
-
-
Save LightSystem/89f555abb7c06cf109932647bd10349f to your computer and use it in GitHub Desktop.
Odoo JSON-RPC
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
import requests | |
base_url = "http://localhost:8069" | |
api_url = f"{base_url}/jsonrpc" | |
db = "people_solutions_odoo" | |
uid = 6 | |
password = "be4707627f4c1e07320e32442b08de6f2aef267c" | |
def odoo_json_rpc(*args): | |
payload = { | |
"method": "call", | |
"params": {"service": "object", "method": "execute", "args": [db, uid, password] + list(args)}, | |
"jsonrpc": "2.0", | |
"id": random.randint(0, 1000000000) | |
} | |
response = requests.post(api_url, json=payload, headers={"content-type": "application/json"}).json() | |
error = response.get("error") | |
if error: | |
raise Exception(error) | |
return response["result"] | |
surveys = odoo_json_rpc("survey.survey", "search_read", [], {"title": {}}) | |
print(surveys) | |
for survey in surveys: | |
survey_invite = odoo_json_rpc("survey.survey", "get_start_url", survey["id"]) | |
print(f"{base_url}{survey_invite}") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment