I'm trying to send a trigger to a Zapier webhook in the form of a POST request containing JSON. It works fine if I just send the POST request through a local python script.
What I want to do is create a RESTful API which makes the trigger to the Zapier webhook when the create-row-in-gs endpoint is called.
As you can see, I'm sending a POST request API call to the Hasura cluster. But instead of getting the response as '200 OK SUCCESS', I'm getting a '200 OK failure' which means that the request is being treated as a GET request instead of a POST request.
test.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 (Running on Hasura cluster)
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
Have been struggling with this for weeks. What am I doing wrong? Would appreciate any help.
requests.post
withallow_redirects=False
– Angiologytest.py
? – Reiterate