Reputation: 639
I am working on an integration of Ruby on Rails application with BigCommerce. I have registered callbacks for receiving notification on order creation or shipment creation. When an order is placed it is sending a callback to my server, then I do some processing and acknowledge that request sender with HTTP status code 200 which is same as mentioned in documentation. But still webhook is firing callbacks with some time period. Can anyone tell me how to acknowledge webhook and stop receiving callbacks from webhook?
Here is my sample code to handle it.
order_id =params['data']["orderId"].to_i
store_hash = params['producer'].split('/').last
store = Store.find_by(store_hash: store_hash)
connection = prepare_connection(store, store_hash)
vars = prepare_variable_hash(order_id, connection)
send_notification_email(vars['email'],
store.email,
q_subject.html_safe,
q_body.html_safe
)
render nothing: true, status: 200
In my server console I am getting log given below.
Rendered text template (0.0ms)
Completed 200 OK in 11883ms (Views: 0.6ms | ActiveRecord: 0.7ms)
Do we have to set any header while responding back? or just status code 200 is fine?
Upvotes: 3
Views: 825
Reputation: 315
Sending back a 200 response is what you are suppose to do to alert the BigCommerce side that you have received the webhook. The problem you are having is that you are exceeding the 10 second timeout limit on the BigCommerce side.
Completed 200 OK in 11883ms (Views: 0.6ms | ActiveRecord: 0.7ms)
According to the above it is taking your system more than 10 seconds to get your response back to BigCommerce. As a result the webhook server is closing the connection before receiving your response and placing the webhook into the retry queue.
I suggest not trying to do so much processing of the webhook at the time of reception. A queue system is much better suited to handling the BigCommerce webhooks. Meaning when you receive a webhook you should place it into a queue on your end and give the 200 response immediately. You will then have a separate set of workers that are processing the webhook messages from the queue you have setup.
It is not possible to increase the timeout limit enforced on the BigCommerce server.
Upvotes: 2