Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Connecting

Configuration

...

Code Block
languagepy
titlePython
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
languagepy
titlePython
common = xmlrpclib.ServerProxy('{}/xmlrpc/2/common'.format(url))
common.version()

The version() call will output the data below.

Code Block
languagexml
titleResult
{
	"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
languagepy
titlePython
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
languagepy
titlePython
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
languagexml
titleResult
"78"

...

Note
titleWarning

While most value types are what would be expected (integer for Integer, string for Char or Text),

  • Date, Datetime and Binary fields use string values
  • One2many and Many2many use a special command protocol

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
languagexml
titleResult
[[78, "Lead Edited"]]

Upload Large Batches

When uploading large amounts of data on a regular basis, it is preferred to use the "load" method.

...