...
Connecting
Configuration
...
Code Block | ||||
---|---|---|---|---|
| ||||
url = "https://demo.taskflow.co.za" db = "demo.taskflow.co.za" username = "demo" password = "demo" |
Logging in
Authentication is required before data manipulation is allowed on most data.
The xmlrpc/2/common endpoint provides meta-calls which don't require authentication, such as the authentication itself or fetching version information. To verify if the connection information is correct before trying to authenticate, the simplest call is to ask for the server's version. The authentication itself is done through the authenticate function and returns a user identifier (uid) used in authenticated calls instead of the login.
...
Code Block | ||||
---|---|---|---|---|
| ||||
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url)) common.version() |
The version() call will output the data below.
Code Block | ||||
---|---|---|---|---|
| ||||
{ "server_version": "9.0", "server_version_info": [9, 0, 0, "final", 0], "server_serie": "9.0", "protocol_version": 1, } |
...
Use the authenticate() method to retrieve the uid which you will use in later calls.
Code Block | ||||
---|---|---|---|---|
| ||||
uid = common.authenticate(db, username, password, {}) |
Manipulating Data
Create Record
Records of a model are created using create(). The method will create a single record and return its database identifier.
...
Code Block | ||||
---|---|---|---|---|
| ||||
models = xmlrpclib.ServerProxy('{}/xmlrpc/2/object'.format(url)) id = models.execute_kw(db, uid, password, 'crm.lead', 'create', [{ 'name': "New Lead", }]) |
The create() method will return the database ID of the newly created record.
Code Block | ||||
---|---|---|---|---|
| ||||
"78" |
...
Note | ||
---|---|---|
| ||
While most value types are what would be expected (integer for Integer, string for Char or Text),
|
Edit Record
Records can be updated using write(), it takes a list of records to update and a mapping of updated fields to values similar to create().
...
Code Block | ||||
---|---|---|---|---|
| ||||
[[78, "Lead Edited"]] |
Upload Large Batches
When uploading large amounts of data on a regular basis, it is preferred to use the "load" method.
...