【发布时间】:2017-12-06 22:53:12
【问题描述】:
我有一个简单的 Python 脚本,它查询 API(使用 requests 库),解析返回的 JSON,并根据从 API 返回的数据构建重定向 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
【问题讨论】: