我正在尝试以包含 JSON 的 POST 请求的形式向 Zapier webhook 发送触发器。如果我只是通过本地 python 脚本发送 POST 请求,它工作正常。
我想要做的是创建一个 RESTful API,它在调用 create-row-in-gs 端点时触发 Zapier webhook。
如您所见,我正在向 Hasura 集群发送一个 POST 请求 API 调用。但是,我得到的响应不是“200 OK SUCCESS”,而是“200 OK failure”,这意味着该请求被视为 GET 请求而不是 POST 请求。
测试.py
#Python 3 Script to send a POST request containing JSON
import json
import requests
api_url = 'http://app.catercorner16.hasura-app.io/create-row-in-gs'
create_row_data = {'id': '1235','name':'Joel','created-on':'27/01/2018','modified-on':'27/01/2018','desc':'This is Joel!!'}
r = requests.post(url=api_url, data=create_row_data)
print(r.status_code, r.reason, r.text)
server.py(在 Hasura 集群上运行)
from src import app
from flask import jsonify,request,make_response,url_for,redirect
from json import dumps
from requests import post
url = 'https://hooks.zapier.com/hooks/catch/xxxxx/yyyyy/'
@app.route('/create-row-in-gs', methods=['GET','POST'])
def create_row_in_gs():
if request.method == 'GET':
return make_response('failure')
if request.method == 'POST':
t_id = request.json['id']
t_name = request.json['name']
created_on = request.json['created_on']
modified_on = request.json['modified_on']
desc = request.json['desc']
create_row_data = {'id': str(t_id),'name':str(t_name),'created-on':str(created_on),'modified-on':str(modified_on),'desc':str(desc)}
response = requests.post(
url, data=json.dumps(create_row_data),
headers={'Content-Type': 'application/json'}
)
return response
几周来一直在为此苦苦挣扎。我究竟做错了什么?将不胜感激任何帮助。