我得到了一个简单的python脚本,它查询一个应用程序接口(使用JSON库),解析返回的requests
,并根据从该应用程序接口返回的数据构建一个重定向URL。这个脚本是从我的机器上运行的一个本地python脚本。
我的目标是让用户在浏览器中打开一个URL,这会触发python代码运行,构建重定向URL,并将用户重定向到这个新的URL。
我可以使用Zapier Webhooks + Zapier Code来实现这一点吗?
Python如下所示(细节已更改):
# A constant for the API query
query_str = "123"
# A constant in the redirect URL
resultant_constant = "93093"
# Personal Access Tokenfor this service
app_id = "the_app_id"
secret = "the_secret_key"
# Make API call and get a the JSON response
resp = requests.get('https://api.example.com/path/to/endpoint/'+ query_str +'/endpoint?filter=theFilter&order=sort_date', auth=(app_id,secret))
# Gets the id of the object I want
my_id = resp.json()['data'][0]['id']
report_url = "https://subdomain.example.com/path/"+resultant_constant+".ext?&object_id="+my_id
return report_url
发布于 2017-07-03 19:38:10
不可能让Zapier将浏览器"GET“请求重定向到另一个URL。Zapier只接受发送给它的数据,并在后台运行您在zap中设置的任何操作。
但是,除去重定向,您仍然可以实现所需的大部分内容:
使用"Catch Raw Hook“选项处理"GET”请求,该请求在有人访问Zapier提供的网址时发生,IE:https://hooks.zapier.com/hooks/catch/....
然后,"Code by Zapier“操作允许您运行Python代码。
https://stackoverflow.com/questions/44889487
复制