【问题标题】:Zapier Code: Python HttpZapier 代码:Python Http
【发布时间】: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

【问题讨论】:

    标签: python zapier


    【解决方案1】:

    Zapier 无法将浏览器“GET”请求重定向到另一个 URL。 Zapier 只接受发送给它的数据,并运行您在 zap 幕后设置的任何操作。

    但是,减去重定向,您仍然可以实现大部分所需:

    对“GET”请求使用“Catch Raw Hook”选项,当有人访问 Zapier 提供的 URL 时发生的请求,即:https://hooks.zapier.com/hooks/catch/....

    然后,“Zapier 编写代码”操作允许您运行 Python 代码。

    【讨论】:

      猜你喜欢
      • 2018-12-27
      • 2017-06-09
      • 1970-01-01
      • 2023-04-05
      • 2022-12-09
      • 2018-07-04
      • 2017-01-31
      • 2018-08-14
      • 1970-01-01
      相关资源
      最近更新 更多