0

I am trying to send a post request to submit the form data on HubSpot. API returns a success message with code 200 and a message 'Form has been submitted'.

Here is the `

$("#basicForm").submit(function(e) {

        e.preventDefault(); // avoid to execute the actual submit of the form.
        var data = new FormData($('#basicForm')[0]);
        var form = $(this);


        $.ajax({
            type: "POST",
            url: 'https://api.hsforms.com/submissions/v3/integration/submit/4848030/3d98fe1e-278b-4915-9c81-5b69206a4b4f',
            cache: false,
            contentType: false,
            processData: false,
            headers: {
                 'Content-Type':'application/json'
             },

             data: JSON.stringify(data),

            success: function(data) {
                console.log(data);

            },
            error:function(e){
                console.log(e);
            }
        });


    });

`

Here is HTML Form:

<form id = "basicForm">
    Name: <input type = "text" value = "ss@hh.com" placeholder="Name" name = "name">
    Email: <input type = "email"  value = "ss@hh.com" name = "email" placeholder="Email">

    <input type = "submit">
</form>

I get a success message in return but HubSpot shows 'No fields were submitted.'

Julien Bourdic
  • 1,398
  • 1
  • 12
  • 29
  • Did you check request headers send on submit ? Can you edit your post with these ? – Julien Bourdic Aug 28 '18 at 12:36
  • Accept: */* Content-Type: application/json Origin: http://example.com Referer: http://example.com User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_13_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/68.0.3440.106 Safari/537.36 – Chirag Kohli Aug 28 '18 at 12:55
  • Do I need to send something else in headers? – Chirag Kohli Aug 28 '18 at 12:56
  • My bad, I wanted to ask for the request body (I answered too fast, it is in the same view in chrome dev tools). Edit your anwer rather than put these things in comment. – Julien Bourdic Aug 29 '18 at 08:14

0 Answers0