Create Records¶
Records of a model are created using create().
It takes a mapping of fields to values, used to initialize the record. For any field which has a default value and is not set through the mapping argument, the default value will be used.
Warning
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 detailed in the documentation to the write method.
-
POST
/restapi/1.0/object/{object_name}?vals={values_for_the_object's_fields}
¶ Request:
POST /restapi/1.0/object/res.partner?vals={'name':'Peter Mitchell','street':'31 Hong Kong street','city':'Taipei','zip':'106','country_id':482} HTTP/1.1 Host: <your Odoo server url>
Response:
HTTP/1.1 200 OK { 'Partner': { 'id': 20, 'name': 'Peter Mitchell', 'street': '31 Hong Kong street', 'street2': false, 'city': 'Taipei', 'state_id': false, 'zip': '106', 'country_id': [482, 'Taiwan'], 'create_date': '2017-07-12 13:34:22', 'create_uid': [1, 'Administrator'], 'write_date': '2017-07-12 13:34:22', 'write_uid': [1, 'Administrator'], ... ... ... } }
Query Parameters: - vals – values for the object’s fields, as a dictionary::
{'field_name': field_value, ...}
see write() for details.
Request Headers: - Accept – the response content type depends on Accept header
- Authorization – The OAuth protocol parameters to authenticate.
Response Headers: - Content-Type – this depends on Accept header of request
Status Codes: - 200 OK – no error
- 404 Not Found – there’s no resource
- 401 Unauthorized – authentication failed
- 403 Forbidden – if any error raise
- vals – values for the object’s fields, as a dictionary::