İçereği Atla
Menü
Bu soru işaretlendi
2 Cevaplar
939 Görünümler

I try to transfer product from one database to another locally 

using API ... 

i write code below but i get RESPONSE 404

import requests
import xmlrpc.client

# Connection parameters for the source Odoo database (assuming XML-RPC)
source_url = 'http://localhost:8069'
source_db = 'odoo17'
source_username = 'admin'
source_password = '00000'

# Connection parameters for the target database (assuming RESTful API)
target_api_url = 'http://localhost:8069/api/v1'
target_api_token = '3cf574f7a79bb78534169d209fbd9f86141267c9'

# Create a session for making API requests to the target database
session = requests.Session()
session.headers.update({'Authorization': 'Bearer {}'.format(target_api_token)})

# Define model and fields for product data
model_name = 'product.product'
fields = ['name', 'list_price', 'default_code']

# Retrieve product data from source Odoo database (assuming XML-RPC)
common_endpoint = '{}/xmlrpc/2/common'.format(source_url)
models_endpoint = '{}/xmlrpc/2/object'.format(source_url)
common = xmlrpc.client.ServerProxy(common_endpoint)
source_uid = common.authenticate(source_db, source_username, source_password, {})
source_models = xmlrpc.client.ServerProxy(models_endpoint)

product_ids = source_models.execute_kw(source_db, source_uid, source_password, model_name, 'search', [[]])
products = source_models.execute_kw(source_db, source_uid, source_password, model_name, 'read', [product_ids], {'fields': fields})

# Insert product data into target database using its API
for product in products:
product_data = {
'name': product['name'],
'list_price': product['list_price'],
'default_code': product['default_code']
}
response = session.post(target_api_url + '/products', json=product_data)
if response.status_code == 201:
print("Product inserted successfully:", product['name'])
else:
print("Failed to insert product:", product['name'])

IT is first Time i work with API 

why i can not insert product to tagdet databse

Avatar
Vazgeç
Üretici En İyi Yanıt

I don't write any code for route .... please explain more what must i do 

Avatar
Vazgeç
En İyi Yanıt

Hi,
It seems in the target you are looking for a route named /api/v1/products , is it custom created route or you are using any third party app for it ?

Thanks

Avatar
Vazgeç