Shopify webhook request verification for `orders/create` topic returning False in python project

Shopify Partner
4 0 0

I am trying to verify a Shopify webhook request for the topic orders/create, but the verification is returning False, I am not able to figure out the reason. Here's the code snippet I am using to verify the request.

class ShopifyWebhookOrderCreate(APIView):
    def post(self, request):
        verified = verify_webhook(request.body, request.META.get('HTTP_X_SHOPIFY_HMAC_SHA256'))
        if not verified:
            return Response(status=status.HTTP_401_UNAUTHORIZED)

and for verifying the request I am doing this:-

def verify_webhook(data, hmac_header):
    digest ='utf-8'), data, digestmod=hashlib.sha256).digest()
    computed_hmac = base64.b64encode(digest)
    return hmac.compare_digest(computed_hmac, hmac_header.encode('utf-8'))

request.body format is b'{'the': 'data'}'

I verified the SECRET with the Shopify app.

Replies 3 (3)

10 0 2

Were you able to solve this? I'm having the same problem

Shopify Partner
4 0 0

hi @GustavoTofolo Yes, I was able to solve this with the same above code. 

Shopify Partner
9 0 2

my verify class is returning False. Not sure why.