SJ19
SJ19

Reputation: 2123

Django CSRF verification failed. Webhook payment system

I'm trying to implement a webhook for my payment system. I have a path to my webhook view, which is a simple definition where the provided id is printed.

The usage is like this

http://localhost:8000/api/mollie-webhook/?id=ExampleId

Path

# mollie webhook
path('api/mollie-webhook/', mollie_webhook, name='mollie_webhook'),

View

def mollie_webhook(request):
    id = request.POST['id']
    print(id)
    return JsonResponse(data={"response": "Success!"})

I'm getting the following error

CSRF verification failed. Request aborted.

Upvotes: 2

Views: 481

Answers (1)

Iain Shelvington
Iain Shelvington

Reputation: 32294

Use the csrf_exempt decorator to mark the view as exempt from CSRF checks

from django.views.decorators.csrf import csrf_exempt

@csrf_exempt
def mollie_webhook(request):
    id = request.POST['id']
    print(id)
    return JsonResponse(data={"response": "Success!"})

Upvotes: 5

Related Questions