Listening webhooks in Python

Hi @tomasfd ,

We are using both the methods to extract data i.e webhooks and API . We are extracting packs_per_day , picks_per_day , warehouse_products from shiphero database using API and Tote Complete, Tote Cleared , Order Packed , Package Added using webhook.

We are using python language to extract data both from API and webhook , we are able to extract through API but stuck with webhook.

As mentioned by you that webhooks are firing and the URL’s doesn’t seem to listen to them can you guide the right way to create the code to listen webhook in python, we are using flask framework to create decorators with different end points for 4 different webhook as mentioned above and this application is deployed on heroku cloud where it accepts POST requests. The snippet of one decorator(Tote complete) is mentioned below

@app.route('/Tote_Complete', methods=['POST'])
def totecomp():
    if request.method == 'POST':
        client = pymongo.MongoClient("mongodb+srv://**************:*********@cluster0.c2pfk.mongodb.net/webhooksdata?retryWrites=true&w=majority") #MongoDB code
        db = client.webhooksdata #MongoDB code 
        x= datetime.datetime.now() 
        testing=db['tote_complete'] #MongoDB code
        a=request.get_json() #getting post data from webhook 
        a=json.loads(a) #converting it into dictionary
        a['time_webhook']=str(x)
        testing.insert_one(a) #Inserting into mongodb database
        response = make_response(jsonify({"code": "200","Message": "Success"}),200) #Creating a json format reply
        response.headers['Content-Type']='application/json' #Setting header for response format
        return response
    else:
        response = make_response(jsonify({"code": "500","Status": "Failure"}),500)
        response.headers['Content-Type']='application/json'
        return response

This is just a basic code I created to get started with webhook listening , I tried doing manual POST requests on these decorator and they seem to work fine . Can you please validate the code mentioned above in concerned with shiphero webhook method.

Thank you