diff --git a/script/restful/README.md b/script/restful/README.md new file mode 100644 index 0000000..ce073fc --- /dev/null +++ b/script/restful/README.md @@ -0,0 +1,25 @@ +# Restful + +REST (representational state transfer) service in ERPLibre, create a token and get data. + +## Installation + +In your instance, install module `restful`. + +## Example + +The example works with application Helpdesk, install module `helpdesk_mgmt`. + +You need to run with specified database, and you can run the example script. + +```bash +./script/db_restore.py --database test +./script/addons/install_addons.sh test restful,helpdesk_mgmt +./run.sh -d test +``` + +Test with the example while the server is running. You can add data manually. + +```bash +./script/restful/restful_example.py +``` diff --git a/script/restful/restful_example.py b/script/restful/restful_example.py new file mode 100755 index 0000000..bdf0e10 --- /dev/null +++ b/script/restful/restful_example.py @@ -0,0 +1,44 @@ +#!./.venv/bin/python +# License AGPL-3.0 or later (https://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)