Skip to Content
Menú
This question has been flagged
1 Respondre
402 Vistes

I am trying to fetch product images from my Odoo instance using the JSON-RPC method. I am working with the product.image or product.template models, and I want to retrieve the image_1920 field for each product.

product_data = {

"jsonrpc": "2.0",

"method": "call",

"params": {

"service": "object",

"method": "execute_kw",

"args": [

DB, uid, PASSWORD, "product.template", "search_read",

[[]], # Empty list means no filter, fetch all products

{"fields": ["id", "name", "list_price", "image_1920", "description", "categ_id",]}

]

},

"id": 2

}

print("product_data", product_data)



Avatar
Descartar
Best Answer

Hello Uday,

Please have a look following example .

import json
import random
import urllib.request

HOST = 'localhost'
PORT = 8069
DB = 'odoo_v18_all'
USER = 'admin'
PASS = 'admin'

def json_rpc(url, method, params):
data = {
"jsonrpc": "2.0",
"method": method,
"params": params,
"id": random.randint(0, 1000000000),
}
req = urllib.request.Request(url=url, data=json.dumps(data).encode(), headers={
"Content-Type":"application/json",
})
reply = json.loads(urllib.request.urlopen(req).read().decode('UTF-8'))
if reply.get("error"):
raise Exception(reply["error"])
return reply["result"]

def call(url, service, method, *args):
return json_rpc(url, "call", {"service": service, "method": method, "args": args})

# log in the given database
url = "http://%s:%s/jsonrpc" % (HOST, PORT)
uid = call(url, "common", "login", DB, USER, PASS)

partner_data = call(url, "object", "execute", DB, uid, PASS, 'res.partner', 'search_read', [], ['name', 'country_id', 'comment'])

print("-----partner_data-----",partner_data)

Thanks & Regards,

CandidRoot Solutions Pvt. Ltd.

Mobile: (+91) 8849036209

Email: info@candidroot.com

Avatar
Descartar
Related Posts Respostes Vistes Activitat
3
de jul. 20
11813
2
de març 15
4976
0
de març 15
3208
0
de febr. 25
687
3
de set. 24
4963