> For the complete documentation index, see [llms.txt](https://synconics.gitbook.io/rest-api/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://synconics.gitbook.io/rest-api/calling-methods/create-records.md).

# Create Records

Records of a model are created using [create()](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.models.Model.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.

<mark style="background-color:orange;">**Warning**</mark>

<mark style="background-color:orange;">while most value types are what would be expected (integer for</mark> [<mark style="background-color:orange;">Integer</mark>](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.fields.Integer)<mark style="background-color:orange;">, a string for</mark> [<mark style="background-color:orange;">Char</mark>](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.fields.Char) <mark style="background-color:orange;">or</mark> [<mark style="background-color:orange;">Text</mark>](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.fields.text)<mark style="background-color:orange;">),</mark>

* [<mark style="background-color:orange;">Date</mark>](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.fields.Date)<mark style="background-color:orange;">,</mark> [Datetime](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.fields.Datetime) <mark style="background-color:orange;">and</mark> <mark style="background-color:orange;"></mark><mark style="background-color:orange;">`Binary`</mark> <mark style="background-color:orange;"></mark><mark style="background-color:orange;">fields use string values</mark>
* [<mark style="background-color:orange;">One2many</mark>](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.fields.One2many) <mark style="background-color:orange;">and</mark> [<mark style="background-color:orange;">Many2many</mark>](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.fields.Many2many) <mark style="background-color:orange;">use a special command protocol detailed in the documentation for the</mark> [<mark style="background-color:orange;">write</mark>](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.models.Model.write) <mark style="background-color:orange;">method.</mark>

**`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:**

* **vals** – values for the object’s fields, as a dictionary:: `{'field_name': field_value, ...}` see [write()](https://www.odoo.com/documentation/16.0/developer/reference/backend/orm.html#odoo.models.Model.write) for details.

| Headers and Status Codes | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                 |
| ------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Request Headers          | <ul><li><a href="https://www.rfc-editor.org/rfc/rfc9110.html#name-accept">Accept</a> – the response content type depends on <em>Accept</em> header</li><li><a href="https://www.rfc-editor.org/rfc/rfc9110.html#name-authorization">Authorization</a> – The OAuth protocol parameters to authenticate.</li></ul>                                                                                                                                                                            |
| Response Headers         | <ul><li><a href="https://www.rfc-editor.org/rfc/rfc9110.html#name-content-type">Content-Type</a> – this depends on <em>Accept</em> header of the request</li></ul>                                                                                                                                                                                                                                                                                                                          |
| Status Codes             | <ul><li><a href="https://www.rfc-editor.org/rfc/rfc9110.html#name-200-ok">200 OK</a> – no error</li><li><a href="https://www.rfc-editor.org/rfc/rfc9110.html#name-404-not-found">404 Not Found</a> – there’s no resource</li><li><a href="https://www.rfc-editor.org/rfc/rfc9110.html#name-401-unauthorized">401 Unauthorized</a> – authentication failed</li><li><a href="https://www.rfc-editor.org/rfc/rfc9110.html#name-403-forbidden">403 Forbidden</a> – if any error raise</li></ul> |
