# Create new Records in Products throuth api

**URL:** <https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987>\
**Category:** Developer\
**Created:** [March 29, 2021, 5:53pm UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987 "2021-03-29T17:53:18Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![kiri](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/kiri/32/1492_2.png) [@kiri](https://discuss.tryton.org/u/kiri)\
**Post date:** [March 29, 2021, 5:53pm UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987/1 "2021-03-29T17:53:18Z")

</div>

Hello i would like to add new Records of Products into my Tryton over a API.  
I have read the Articel in the Manual “[User Application — Tryton server](https://docs.tryton.org/projects/server/en/latest/topics/user_application.html)” and had build successful interfaces.

Now i am trying to add an Api to the Products Module, so i can add new Records by an interface. But i cant find the Function i need to manipulate to achieve it.  
When i look into the product.py file i found some Functions but the don t make sense to me.  
Did some tried something like this? How do modules write Information into the Database?

Thank you to all Answers

---

<div class="post-metadata">

**Author:** ![dave](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/d/ee7513/32.png) [@dave](https://discuss.tryton.org/u/dave)\
**Post date:** [March 29, 2021, 9:18pm UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987/2 "2021-03-29T21:18:12Z")

</div>

There is some code in the timesheet module that creates / updates timesheet lines using an API defined for use by User Applications: [https://hg.tryton.org/modules/timesheet/file/d5bd5090b474/routes.py#l84](https://hg.tryton.org/modules/timesheet/file/d5bd5090b474/routes.py#l84)

You should be able to do something similar, but for products instead of timesheet lines.

---

<div class="post-metadata">

**Author:** ![pokoli](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/pokoli/32/22_2.png) [@pokoli](https://discuss.tryton.org/u/pokoli)\
**Post date:** [March 30, 2021, 6:38am UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987/3 "2021-03-30T06:38:45Z")

</div>

> [@kiri](#):
>
> I have read the Articel in the Manual “[User Application — trytond latest documentation](https://docs.tryton.org/projects/server/en/latest/topics/user_application.html)” and had build successful interfaces.

User aplications are for token based autentication APIs.

It is also possible to use the plain JSON-RPC API with standar authentication (user/password+session). This way you can directly call the create method of the product model without requiring to develop any custom code on server side.

---

<div class="post-metadata">

**Author:** ![kiri](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/kiri/32/1492_2.png) [@kiri](https://discuss.tryton.org/u/kiri)\
**Post date:** [March 30, 2021, 2:24pm UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987/4 "2021-03-30T14:24:01Z")

</div>

> [@pokoli](#):
>
> JSON-RPC API

thank you all for your answers. I try the option with JSON-RPC and will post my results.

---

<div class="post-metadata">

**Author:** ![kiri](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/kiri/32/1492_2.png) [@kiri](https://discuss.tryton.org/u/kiri)\
**Post date:** [April 7, 2021, 8:57am UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987/5 "2021-04-07T08:57:27Z")

</div>

The only think i dont unterstand is how to create the payload for the JSON\_RPC. The documentation is a bit empty.  
Here is an example of my python code :

```
   url = "http://www.xxxx.de:48000/training2/"

    payload = {
        "jsonrpc": "2.0",
        "method": "common.db.login",
        "params": { 'kiri': 'kiri', 'password':'password'}, "id":3}

    print(payload)
    response = requests.post(url, json=payload)

    print(str(response))

```

i get 500 oder 401

---

<div class="post-metadata">

**Author:** ![edbo](https://discuss-cdn.tryton.org/letter_avatar_proxy/v4/letter/e/f14d63/32.png) [@edbo](https://discuss.tryton.org/u/edbo)\
**Post date:** [April 7, 2021, 9:19am UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987/6 "2021-04-07T09:19:30Z")

</div>

Tryton is using version 1.0 from the JSON-RPC spec.  
Take a look at [Log in with external script fails](https://discuss.tryton.org/t/log-in-with-external-script-fails/1525) You have there two examples:

1. complete external script where you need to make your JSON-RPC request yourself
2. use [Proteus](https://docs.tryton.org/projects/client-library/en/latest/)

---

<div class="post-metadata">

**Author:** ![kiri](https://discuss-cdn.tryton.org/user_avatar/discuss.tryton.org/kiri/32/1492_2.png) [@kiri](https://discuss.tryton.org/u/kiri)\
**Post date:** [April 19, 2021, 1:57pm UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987/7 "2021-04-19T13:57:14Z")

</div>

Thank you. I could get it running now with Proteus. Thank you vor the Link.  
Here is my solution:

```
from decimal import Decimal
from proteus import Model, config

config.set_xmlrpc('http://USER:PASSWORD@www.LINK.de:PORT/DB/')
Party = Model.get('party.party')
Product = Model.get('product.product')
Uom= Model.get('product.uom')
Template = Model.get('product.template')
#PriceList = Model.get('product.price_list')

allUom=Uom.find()
hektar= allUom[5]

template = Template(
    name='Proteus4',
    default_uom=hektar,
    list_price=Decimal(20),
    producible=True,
    consumable=False,
    type='goods')
template.save()

product = Product(template=template)
product.save()

```

---

<div class="post-metadata">

**Author:** ![system](https://discuss-cdn.tryton.org/uploads/default/original/1X/c6f8ec0a40525cdcd50058c734283450a4b3d38b.png) [@system](https://discuss.tryton.org/u/system)\
**Post date:** [May 19, 2021, 1:57pm UTC](https://discuss.tryton.org/t/create-new-records-in-products-throuth-api/3987/8 "2021-05-19T13:57:27Z")

</div>

Closed on May 19, 2021, 1:57pm UTC

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.
