Listening webhooks in Python

Hi @tomasfd ,
Please enlighten regarding the MIB and SIB picks have to performed from where and how?

Moreover I wanted to know the webhooks are correctly created? I am working on 4 different webhooks (Tote Complete , Tote Cleared , Order Packed , Package Added) and just wanted to know as suggested by the Account Holder(Jake) that concerned account is 3PL account and as mentioned in the documentation

“If you are using a 3PL account, webhooks need to be registered on the Customer account and not the 3PL account to trigger correctly.”

For this I tried to fetch ID for the customer in the 3PL account using the query mentioned in documentation and received a response that

“GraphQLError: Cannot query field ‘customers’ on type ‘AccountQueryResult’”

So just wanted to validate the correctness of webhooks paths and are they perfectly created?

Thank you

Hello @RohitArora.202!

They seem to be set up correctly. You can use the following query to recheck the URLs:

query{
  webhooks{
    request_id
    complexity
    data{
      edges{
        node{
          name
          shop_name
          url
        }
      }
    }
  }
}

I just updated the Docs. There was a mistake with the query, and this is the correct one:

query {
  account {
    data {
      customers {
        edges {
          node {
            id
          }
        }
      }
    }
  }
}

Best,
TomasFD

Hi Tomas, do these web hooks need to be registered at each client account or can we set them up at the 3PL account level? I believe they’re currently at the 3PL level so that could be why it’s not showing any?

Also, from your experience how often will the web hooks fail to trigger on ShipHero’s end (i.e. server overload)? We’re building this for reporting purposes, so it’s important that we capture the transaction information with a timestamp for all of these to accurately see how long certain tasks are taking in the warehouse.

Hello @jake_shiplab!

I’ve been running some tests on my end and there is something wrong with that webhook. Let me take the matter to our engineering team.

Are you using our API or just webhooks? There are 2 queries that might be of use to you: picks_per_day and packs_per_day. Let me know if you would like to dive deeper into these.

We do not have metrics on it. All I can tell you is, in my tests, which do not add up to what a real account manages in volume, I have not had any webhook not firing.

Have a great day,
TomasFD

Thanks for looking into it. The reason that we can’t just rely on picks_per_day and pack_per_day via the API is that it doesn’t offer much granularity to then drill down by client, actual hours worked on batches, etc.

For example, it would show that User A picked 200 pieces that day, but we can’t see the breakdown of that by client and then beyond that, we don’t know if User A worked a full 8 hours on picking. By using the webhooks with all the transactional information we can run queries on start/finish times of batches, clients, etc.

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

Hello @RohitArora.202!

The problem at the moment with the webhooks is that the servers are returning a 500 error. Have you tried querying your registered webhooks with our API to check the endpoint URLs are correct?

Kind regards,
TomasFD

Hi @tomasfd ,

Yes , I have cross checked the URL and they are correct , I have created that application that will listen to webhook from scratch that’s why I wanted some guidance over the python code as shared in the earlier response in there you can notice that we are using request module to GET data in return it’s sending a jsonified response for that. So please if you can guide over how exactly the shiphero webhook is expecting a response we can make it work then.

Moreover this application is made using flask web framework and deployed on heroku cloud platform.

Hello @RohitArora.202!

Unfortunately, we cannot help you with the code in your backend as we do not provide that kind of support here in the community…

What I can tell you is we expect a code 200 and a message like {'success': True} or {'code': '200', 'Status': 'Success'}

Kind regards,
TomasFD

Hi @tomasfd ,
We were able to make webhooks work and out of those 4 webhooks we are receiving data for only two of them i.e Tote Cleared and Order Packed Out
The other two doesn’t seem to work i.e Tote Complete and Package Added

Hi Tomas, it seems strange that the two webhook events are being received, but the most common ones, tote complete and package added are not triggering. We should have plenty of those events triggering each day in the account. Are you able to see if they are successfully firing on your end?

Hello @jake_shiplab and @RohitArora.202!

I’m looking into that now.

Have a nice day,
TomasFD

Hi @tomasfd ,
Any updates on the issue regarding tote complete and package added webhooks?

Hi @tomasfd, we had a call this morning to review the project and it seems like we’re just waiting on answers regarding these 2 web hooks not firing. Do you happen to have any updates for your team? Thanks so much

Hello @jake_shiplab!

I’m working first on the tote complete. I will update you tomorrow morning on the status of both.

Kind regards,
TomasFD

Hello @RohitArora.202

Could you re-register the “Tote Complete” webhook and test if you are receiving the payloads?

Kind regards,
TomasFD

Hi @tomasfd ,
Yes , Tote Complete seem to work now , Now it’s just “Package Added” left to be look upon. Thanks

Hi @tomasfd ,
Do we have any updates on the “Package Added” webhook?

Thanks

Hello @RohitArora.202!

I just noticed you are not using shipping containers. That is why you were not receiving them. Are you planning on using those?

Also, what information were you expecting to receive from this webhook?

Kind regards,
TomasFD

Hi @tomasfd , thanks for the response. I’m sorry, this is my fault, I misunderstood the definition of that Webhook. You’re correct, it’s not functionality that we use. With that being said, are you able to define the triggers for Order Packed Out vs. Shipment Update a bit more? The end result that we are trying to accomplish is a start and end time stamp for a given order when it is being packed.

For example, the first item in order ABC was scanned at time X, and the shipping label for order ABC was then created at time Y. Therefore, Y-X = total time to pack order.