Skip to Content
Menu
This question has been flagged
1 Atsakyti
397 Rodiniai

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)



Portretas
Atmesti
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

Portretas
Atmesti
Related Posts Replies Rodiniai Veikla
3
liep. 20
11806
2
kov. 15
4975
0
kov. 15
3206
0
vas. 25
685
3
rugs. 24
4948