erplibre/script/restful/restful_example.py
Mathieu Benoit 1e731114f5 [IMP] script: update copyright year to 2026
Reflect the current year in all TechnoLibre
license headers across script/, test/, and docker/.

Generated by Claude Code 2.1.74 model claude-sonnet-4-6

Co-Authored-By: Mathieu Benoit <mathben@technolibre.ca>
2026-03-11 23:16:05 -04:00

46 lines
1,009 B
Python
Executable file

#!/usr/bin/env python3
# © 2021-2026 TechnoLibre (http://www.technolibre.ca)
# License AGPL-3.0 or later (http://www.gnu.org/licenses/agpl)
import json
import requests
headers = {
"content-type": "application/x-www-form-urlencoded",
"charset": "utf-8",
}
data = {"login": "admin", "password": "admin", "db": "test"}
base_url = "http://127.0.0.1:8069"
req = requests.get(f"{base_url}/api/auth/token", data=data, headers=headers)
response = req.content.decode("utf-8")
print(response)
content = json.loads(response)
headers["access-token"] = content.get("access_token")
# add the access token to the header
print(headers)
model_name = "helpdesk.ticket"
req = requests.get(
f"{base_url}/api/{model_name}/",
headers=headers,
data={"limit": 10, "domain": []},
)
# ***Pass optional parameter like this, with data = ***
# {
# "limit": 10,
# "domain": "[('supplier','=',True),('parent_id','=', False)]",
# "order": "name asc",
# "offset": 10,
# }
print(req.content)