首页 > 解决方案 > 如何将 odoo 与 IMDb 集成?

问题描述

我正在尝试将 odoo 与imdb.com集成,它在omdbapi.com上有自己的 API 我需要将电影作为产品在 odoo 上进行购买,然后在网站上说要搜索我应该使用这个 api http://www .omdbapi.com/?apikey= "我必须,但我的钥匙在这里"&t="我要搜索的电影名称"

我试图通过这种方式做到这一点

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

它返回一个带有电影 hello 数据的 json 但这里它是一个静态参数我怎样才能使它动态并从字段或数据输入中获取电影名称然后我需要在 product.tempalte 的方法 create 上获取 json 参数

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

非常感谢任何帮助

标签: pythonapiweb-servicesintegrationodoo

解决方案


我使用 Postman 生成此代码,这将使您了解如何处理来自链接的查询字符串参数

import requests
url = "http://www.omdbapi.com/"

querystring = {"apikey":"15439843","t":"hello"} # your parameters here in query string

headers = { 'Cache-Control': "no-cache", 'Connection': "keep-alive", 'cache-control': "no-cache" }

response = requests.request("GET", url, headers=headers, params=querystring)

print(response.text)

推荐阅读