Skip to Content
Menu
This question has been flagged

i'am trying to integare odoo with  imdb.com which have it's own APIs on omdbapi.com 

i  need to fictch movies as products on odoo then make apurchase orders on it the site says\for searching i should use this api

\\\http://www.omdbapi.com/?apikey="i must but my key here"&t="the movie Name i want to search"

i'am tried to do it by this way

class Api(http.Controller):
@http.route('/api', auth='public', methods=["get"])
def index(self, **kw):
    url = 'http://www.omdbapi.com/?apikey=15439843&t=hello'
    r = requests.get(url)
    return r.text

it return a json with data of the movie hello but here it's a static parameter how can i make it dynamic and get the movie name from field or data input then i need to get the json parameters on method create of product.tempalte

add_product = http.request.env['product.template'].sudo().create({
         'name': "movie name form json"
         })
return add_product

any help well be very appreciated

Avatar
Discard
Best Answer
there is no need to create controller. just override create method of your model like

def create(self, vals):
name = vals.get('name')
if name:
url = 'http://www.omdbapi.com/?apikey=15439843&t=%s' % name
response = requests.get(url)
movies = response.json()
# formate movi list
self.env['product.template'].sudo().create({
'director': movies.get('Director')
})
Avatar
Discard
Related Posts Replies Views Activity
0
Jun 21
1695
0
Mar 21
1720
4
Feb 17
20666
1
Aug 24
737
1
Sep 23
829