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

# Create

## **(Create) -- Using API to create resources**

**\[POST]** *https\://\<server-url>/api/\<model\_name>*

You have the possibility to create simple objects, but you can also create objects with internal relationships (in other words with related fields Many2one, Many2many and One2many). Suppose you need to create a "*hr.employee*" record but you need to define by creation, its job (Many2one => res.country) and its categories (One2many => category\_ids).

{% tabs %}
{% tab title="Request" %}

```
curl --location --request POST 'https://<server_url>/api/hr.employee' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer <token>' \
--data-raw '{
    "name": "Alejandro Cora Glez",
    "mobile_phone": "+5354137760",
    "notes": "Testing employee creation...",
    "identification_id": "0000000000",
    "passport_id": "X00000",
    "work_location": "Central Park",
    "work_email": "alek.cora.glez@gmail.com",
    "work_phone": "+5858355581",
    "gender": "male",
    "marital": "married",
    "category_ids": [
        1
    ],
    "country_id": {
        "name": "NewCountry"
    },
    "job_id": {
        "name": "Some Job"
    }
}'
```

{% endtab %}

{% tab title="Response" %}

```
{
    "jsonrpc": "2.0",
    "id": null,
    "result": {
        "status_code": 201,
        "data": {
            "id": <record_id>
        }
    }
}
```

{% endtab %}
{% endtabs %}

**Important:** *Relational fields could be created only once, the second time, an error will be raised!*

| Type                 | **Details**                                                                                                                                                                  |
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| Many2one             | **If you know the id of the resource use it.** *("country\_id": 50 instead "country\_id": {"name": "Country Test"})*                                                         |
| Many2many & One2many | **You can use both: resource id or resource creation in place. (Remember this is a list of elements).** *\["child\_ids": \[3, {"name": "Contact 1", "phone": "+000000111"}]* |
