Create new Records in Products throuth api

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 — trytond latest documentation” 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

There is some code in the timesheet module that creates / updates timesheet lines using an API defined for use by User Applications: modules/timesheet: d5bd5090b474 routes.py

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

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.

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

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

Tryton is using version 1.0 from the JSON-RPC spec.
Take a look at Log in with external script fails You have there two examples:

  1. complete external script where you need to make your JSON-RPC request yourself
  2. use Proteus

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()

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