I am trying to create webhook for shopify.I have successfully registered the webhook(see the below code).But i am not able to get data in webhook_receiver.
def
webhook_register(request, organization_pk):
shop = '
gachibowli.myshopify.com'
headers = {
"X-Shopify-Access-Token": SOCIAL_AUTH_ACCESS_TOKEN,
"Accept": "application/json",
"Content-Type": "application/json",
}
payload = {
"webhook": {
"topic": "products/create",
"address": "
https://89a15e36.ngrok.io/shopify/webhook_receiver/",
"format": "json"
}
}
response =
requests.post("https://" + shop
+ "/admin/api/2019-10/webhooks.json",
data=json.dumps(payload), headers=headers)
print (response.content)
return HttpResponse('success')
def verify_webhook(data, hmac_header):
digest =
hmac.new(SOCIAL_AUTH_SHOPIFY_SECRET, data.encode('utf-8'), hashlib.sha256).digest()
computed_hmac = base64.b64encode(digest)
return hmac.compare_digest(computed_hmac, hmac_header.encode('utf-8'))
@require_http_methods(["GET", "POST"])
@csrf_exempt
def
webhook_receiver(request, organization_pk):
print("#####")
data = request.body
print(data)
verified = verify_webhook(data, request.headers.get('X-Shopify-Hmac-SHA256'))
# build a request object
req = json.loads(data)
print(req)
# get action from json
action = req.get('queryResult').get('action')
return HttpResponse('sucessfully received')