Go to file
root 484f621ebf Charge 10% more for party 'PUBLICO' 2023-10-01 22:05:40 +00:00
.gitignore Add table GET and PUT endpoints 2023-05-12 21:23:58 +00:00
INSTALL.md adding / removing information libraries on install 2023-01-23 09:46:41 -05:00
README.md add cors in readme for config file api-fast.ini 2022-12-06 09:05:28 -05:00
TODO.md Add version and minor fixes 2022-12-07 09:12:12 -05:00
api-fast.ini Charge 10% more for party 'PUBLICO' 2023-10-01 22:05:40 +00:00
api-fast.service Fix 2022-08-12 15:16:20 -05:00
api.py Charge 10% more for party 'PUBLICO' 2023-10-01 22:05:40 +00:00
main.py The total amount of the sale lines is the amount with tax, fixed discount for sale line with quantity different to 1, minor fixes for integration with frontend 2023-05-22 05:37:26 +00:00
run.py minor fix 2022-11-03 20:45:03 -05:00
testing.py update conexion with api 2023-05-04 04:34:09 +00:00
tools.py update conexion with api 2023-05-04 04:34:09 +00:00
version.py Add fastlogin 2023-01-10 09:24:58 -05:00

README.md

PREDASH API

This guide show how config API Fast in server

Get Started

Configuration FastAPI Tryton enviroment

Create a config file

In Home you must create a new file for example in '/home/user/.fastapi':

nano /home/user/.fastapi/api-fast.ini

Add General Section information

Add all info required.

[General]
databases=['MYDB']
host=0.0.0.0
trytond_config=/home/user/.trytond/trytond.conf

Add Auth Section (Optional)

Add api_key and secret section if you want share API with parties.

[Auth]
api_key=XXXXXXXXXXXXXXXXXXXXXXX
secret_key=mysupersecretkey
user=admin

Activate SSL (Optional)

Creating Private Key and Certificate, so in console type:

openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365

Next add this section:

[SSL]
cert_file = /home/user/.fastapi/cert.pem
key_file = /home/user/.fastapi/key.pem

Activate CORS

# add domain with first item list
[CORS]
origins = ["http://localhost", "http://localhost:3100", "http://localhost:3100/login"] 

Endpoints

Test Running server using uWSGI

gunicorn -c gun_config.py wsgi:app

Example connection to API


import logging
import requests
import simplejson as json

# The port is 8010 by default
api_url = 'localhost:8010'
database = 'MYDATABASE'

api = '/'.join(['http:/', api_url, database])
ctx = {
    'company': 1,
    'user': 1,
}

args_ = {
    'model': 'party.party',
    'domain': '[
      ('city', '!=', '15'),
    ]',
    'order': None,
    'limit': 13,
    'fields': ['name', 'id_number'], # Here you can add more fields
    'context': ctx,
}

data = json.dumps(args_)

# Test for search
route = api + '/search'
result = requests.post(route, data=data)

for r in result.json():
    print(r)

Endpoints

Context

Context is a dict with next keys:

company: id user: id

This route return a query as Select, as List of dicts (records) :

uri: /DB/search
type: POST

args_ = {
    'model': 'mymodel',  # ex, 'gnuhealth.inpatient'
    'domain': 'domain', # optional : see tryton docs
    'fields': ['field1', 'field2', ...]
    'order': number,  # optional
    'limit': limit, # optional
    'context': ctx, # Context Dict object
}

Create

This route is used for a create a record (just one), return created record data:


uri: /DB/create
type: POST

args = {
    'model': 'mymodel',
    'record': {field1: value, field2: value}, # Dict
    'context': ctx, # Context Dict object
}


Write / Save

This route is used for a modify a record (just one), return updated record data as Dict:


uri: /DB/save
type: PUT

args = {
    'model': 'mymodel',
    'record': {field1: value, field2: value}, # Dict
    'context': ctx, # Context Dict object
}

Write / Save

This route is used for a modify a record (just one), return updated record data as Dict:


uri: /DB/save
type: PUT

args = {
    'model': 'mymodel',
    'record': {field1: value, field2: value}, # Dict
    'context': ctx, # Context Dict object
}