Having Trouble with Form Submission - 415 Error

SOLVE
Highlighted
Occasional Contributor

I am trying to submit data from an html form to a HubSpot form. My html form lives on a hubspot landing page. Whenever I try to submit it, I receive a 415 error, which is described as, "The HTTP 415 Unsupported Media Type client error response code indicates that the server refuses to accept the request because the payload format is in an unsupported format. The format problem might be due to the request's indicated Content-Type or Content-Encoding , or as a result of inspecting the data directly." My best guess on this is that some of the data is not in the format that the HubSpot form is expecting, but I've triple-checked both the html form and the HubSpot form and they are, without a doubt, consistent as far as what is being submitted and accepted for each form field.

Here is the javascript + jquery + ajax that I'm using to try and submit the form data to HubSpot:

$(document).ready(function(){
     $('#auraForm').submit(function (e, data) {
     		console.clear();
         e.preventDefault();
         dataToHubspot();
     });
});

function dataToHubspot() {
 
    var data = {
      'fields': [
        {'name': 'project_name',
        'value': $("input[name='project_name']").val()},
        {'name': 'fixture_type',
        'value': $("input[name='fixture_type']").val()},
        {'name': 'specifying_company',
        'value': $("input[name='specifying_company']").val()},
        {'name': 'project_location',
        'value': $("input[name='project_location']").val()},
        {'name': 'contact',
        'value': $("input[name='contact']").val()},
        {'name': 'quantity',
        'value': $("input[name='quantity']").val()},
        {'name': 'item_number',
        'value': $("input[name='item_number']").val()},
        {'name': 'email',
        'value': $("input[name='email']").val()},
      ],
      "legalConsentOptions": {
        "consent": { // Include this object when GDPR options are enabled
          "consentToProcess": true,
          "text": "I agree to allow Evo-Lite to store and process my personal data.",
          // "communications": [
          //   {
          //     "value": true,
          //     "subscriptionTypeId": 999,
          //     "text": "I agree to receive marketing communications from Example Company."
          //   }
          // ]
        }
      },
      'skipValidation': true,
  
    }; 
  
   $.post('https://api.hsforms.com/submissions/v3/integration/submit/companyID/formID', data)
    .then(function (response) {
      console.log(response);
    }) 

}

Quick note on this code: I have replaced the actual company and form hubspot ID's with companyID and formID, but I have the actual ID's correctly entered in the code I am using, so that is not the issue.

Here is the error that I get in the console:

jquery-1.7.1.js:4 
POST https://api.hsforms.com/submissions/v3/integration/submit/companyID/formID    415
send	        @	jquery-1.7.1.js:4
ajax	        @	jquery-1.7.1.js:4
f.<computed>	@	jquery-1.7.1.js:4
dataToHubspot	@	module_14632068748_A…ec_Sheet_page.js:57
(anonymous)	@	module_14632068748_A…ec_Sheet_page.js:15
dispatch	@	jquery-1.7.1.js:3
i	        @	jquery-1.7.1.js:3


I recently made another html form that correctly submits to a hubspot form so I used the exact same format for this form submission, which is why I'm having such a hard time figuring out why this one won't work. There are only a couple tiny differences between this form submission and the other one that works. The first difference between this one and the other is that the other used axios instead of jquery+ajax (only difference is changing $.post(...) to axios.post(...)). The other difference is that, here, I am using jquery to grab the field values, but in the old successful form submission, I used fieldname.value.

Any help is highly appreciated!

Reply
0 Upvotes
1 Accepted solution

Accepted Solutions
Community Manager

Hi @Kennan_wmk,

 

I hope all is well with you 😄

 

It looks like you have posted a similar issue here: https://community.hubspot.com/t5/APIs-Integrations/Form-Submission-via-Ajax-returning-a-415-error/m-... and Isaac has respond to it. 

 

Glad that all is well now!

1 Reply 1
Community Manager

Hi @Kennan_wmk,

 

I hope all is well with you 😄

 

It looks like you have posted a similar issue here: https://community.hubspot.com/t5/APIs-Integrations/Form-Submission-via-Ajax-returning-a-415-error/m-... and Isaac has respond to it. 

 

Glad that all is well now!