'Send data to API: jQuery Ajax POST with Contact Form 7 returns 500 error

I am trying to send my Wordpress Contact form 7 form data to an API after the form has been submitted with Ajax. The code is as follows:

$('body').on('wpcf7mailsent', function (event) {
        if (event.detail.contactFormId == '1233') {
            var $form = $('.wpcf7-form');

            var formData = new FormData($form[0]);
            formData.append('submittingForm', '1');
            formData.append('submittingAjax', '1');

            $.ajax({
                type: "POST",
                url: window.location.href,
                data: formData,
                processData: false,
                contentType: false,
                async: true,
              success: function(data) {
                console.log('success',data);
              },
              error: function(data) {
                console.log('error',data);
              },
            }).done(function () {
               
            });
        }
});

Then trying to catch this in my Wordpress functions.php file to run a function if we have the data and run a cURL after that:

if (isset($_POST['submittingForm'])) {
   $this->contactFormTest();
}

For some reason my Ajax call results in an Internal 500 error (on localhost). Anything to suggest I'm doing wrong here or how to debug this? Is this the correct way to catch the form data here because I suspect its something regarding that but not sure how to do this elseway.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source