Rest API
  • Odoo REST API: Version 1.0 documentation
  • Connection
    • Configuration
    • Demo
    • Logging In
      • How you can do
        • Odoo Version Information
        • Oauth1 Authentication
        • OAuth2 Authentication
        • Basic Authentication
  • Calling Methods
    • Check Access Rights
    • List Records
      • Pagination
    • Count Records
    • Read Records
      • Read Single Record
      • Read List Records
      • Read Filter Records
    • Listing Record Fields
    • Create Records
    • Update Records
      • Update Single Record
      • Update List Records
    • Delete Records
      • Delete Single Record
      • Delete List Records
  • Report Printing
    • Print Single Report
    • Print List Reports
  • Inspection and Introspection
    • ir.model
    • ir.model.fields
Powered by GitBook
On this page
  1. Calling Methods

Create Records

PreviousListing Record FieldsNextUpdate Records

Last updated 1 year ago

Records of a model are created using .

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 , a string for or ),

  • , and Binary fields use string values

  • and use a special command protocol detailed in the documentation for the 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>

JSON 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'],
      ...
      ...
      ...
  }
}

XML Response:

HTTP/1.1 200 OK

<res.partner type="dict">
	<id type="int">20</id>
	<name type="str">Peter Mitchell</name>
	<street type="str">31 Hong Kong street</street>
	<street2 type="bool">false</street2>
	<city type="str">Taipei</city>
	<state_id type="bool">false</state_id>
	<zip type="str">106</zip>
	<country_id type="list">
		<item type="int">482</item>
		<item type="str">Taiwan</item>
	</country_id>
	<create_date type="str">2017-07-12 13:34:22</create_date>
	<create_uid type="list">
		<item type="int">1</item>
		<item type="str">Administrator</item>
	</create_uid>
	<write_date type="str">2017-07-12 13:34:22</write_date>
	<write_uid type="list">
		<item type="int">1</item>
		<item type="str">Administrator</item>
	</write_uid>
</res.partner>

Query Parameters:

Headers and Status Codes
Description

Request Headers

Response Headers

Status Codes

vals – values for the object’s fields, as a dictionary:: {'field_name': field_value, ...} see for details.

– the response content type depends on Accept header

– The OAuth protocol parameters to authenticate.

– this depends on Accept header of the request

– no error

– there’s no resource

– authentication failed

– if any error raise

create()
Integer
Char
Text
Date
Datetime
One2many
Many2many
write
write()
Accept
Authorization
Content-Type
200 OK
404 Not Found
401 Unauthorized
403 Forbidden