2

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.
SJ19
  • 1,933
  • 6
  • 35
  • 68

1 Answers1

5

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!"})
Iain Shelvington
  • 31,030
  • 3
  • 31
  • 50