I am testing a shipstation webhook and I can't seem to get data from the POST request they are sending.
Their webhook docs say that their POST request will contain a body that looks like this:
{"resource_url":"https://ssapiX.shipstation.com/orders?storeID=123456&importBatch=1ab23c4d-12ab-1abc-a1bc-a12b12cdabcd","resource_type":"ORDER_NOTIFY"}
To debug the issue, I went into the Firefox and tried to send this:
And got the same result; req.method = 'POST'
and req.POST = False
View controller for myNgrokAddress.ngrok.io/bot/shipstation
:
@csrf_exempt
def vc(req):
print(req.META) //this works but it looks like meta-data for my browser and not from shipstation
print(req.POST.get('resource_url')) //prints false
print(req.POST) //prints false
return HttpResponse('')
When I go to localhost:4040
(the ngrok inspector) the POST body shows up, so something must be incorrectly configured on my django server.
I set ALLOWED_HOSTS = ['myNgrokAdress.ngrok.io', 'localhost']
in my settings.py. Is there something else I need to do?
What am I missing here?
The problem is with the req.POST
method.
From the Django docs :
HttpRequest.POST:
A dictionary-like object containing all given HTTP POST parameters, providing that the request contains form data. See the QueryDict documentation below. If you need to access raw or non-form data posted in the request, access this through the HttpRequest.body attribute instead.
Since the data-type being sent is non-form data, you will need to use req.body
instead.