0
我有一個簡單的查詢API的Python腳本(使用requests
庫),解析返回的JSON,並基於從API返回的數據構建重定向URL。該腳本作爲從本機運行的本地python腳本運行。Zapier代碼:Python Http
我的目標是讓用戶在其瀏覽器中打開一個URL,該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