5
edits
Tag: 2017 source edit |
(python example) |
||
| Line 123: | Line 123: | ||
with one of the 4 following methods : GET, POST, PUT, DELETE, replacing <action> by the action you want to use. Ex : <nowiki>http://<my_server>/api/index.php/invoices</nowiki> | with one of the 4 following methods : GET, POST, PUT, DELETE, replacing <action> by the action you want to use. Ex : <nowiki>http://<my_server>/api/index.php/invoices</nowiki> | ||
== Client code example == | ==Client code example== | ||
=== PHP === | ===PHP=== | ||
There's different ways to do so. Here's a piece of code but you can also use libraries such as phphttpclient.com | There's different ways to do so. Here's a piece of code but you can also use libraries such as phphttpclient.com | ||
| Line 182: | Line 182: | ||
*$data : string, datas in json format. This parameter is not mandatory. | *$data : string, datas in json format. This parameter is not mandatory. | ||
=== Javascript Ajax === | ===Javascript Ajax=== | ||
<syntaxhighlight lang="javascript"> | <syntaxhighlight lang="javascript"> | ||
| Line 412: | Line 412: | ||
=Examples with Python= | =Examples with Python= | ||
See https://pypi.org/project/dolipy/ and https://pypi.org/project/dolibarr/ | See https://pypi.org/project/dolipy/ and https://pypi.org/project/dolibarr/ | ||
[[File:Dolibarr user for api.png|thumb|334x334px]] | |||
To get a custom API-key, you have to create a new user and | |||
generate a "Key for API". | |||
Then you can install the python-module with "pip install dolibarr". | |||
from dolibarr import Dolibarr | |||
api_url = 'http://your-url<nowiki/>/dolibarr/htdocs/api/index.php/' | |||
api_key = 'custom_API-Key' | |||
# Connection to dolibarr | |||
dolibarr_inst = Dolibarr(api_url, api_key) | |||
# create Product | |||
params = {'ref': 'Product_Reference', 'status': '1', 'barcode_type': '6', 'note_public': None, | |||
'note_private': <nowiki>''</nowiki>, 'specimen': 0, 'label': 'Product_Label', | |||
'description': <nowiki>''</nowiki>, 'type': '0', 'price': <nowiki>''</nowiki>, 'price_ttc': '15.6000000', 'price_base_type': 'TTC', # excl. tax = HT, incl. tax = TTC | |||
'tva_tx': '19.0000', 'seuil_stock_alerte': '0', 'desiredstock': '0', 'status_buy': '1', 'barcode': 'barcode'} | |||
ret_val = dolibarr_inst.call_create_api('products', params) | |||
print(ret_val) | |||
# get product list | |||
product_dict = dolibarr_inst.call_list_api('products') | |||
print(product_dict) | |||
=Develop your own service / API= | =Develop your own service / API= | ||
edits