Form POST call gives back empty response



I am attempting to make a form POST request in a React/Node app. The request gets into Hubspot correctly, but on my React frontend I get a TypeError: Failed to Fetch or I get a failure with an empty response back.

I’m struggling to figure out what is causing that failed request. It also happens when I use ajax and axios instead of fetch. Any suggestions or ideas would be welcome!


Here is the function that gets called onSubmit of the form:

fetch('/careers-submission', {
          method: 'post',
          headers: {
            "Content-type": "application/x-www-form-urlencoded; charset=UTF-8"
          body: 'email=' + email + '&firstname=' + firstName + '&lastname=' + lastName + '&linkedin_profile=' + linkedinUrl + '&careers_job_category=' + jobCategory
        .then(res => {
          res.json() })
        .then(json => {
          .catch(err => {
            console.log('error!', err)

This is my function in Node:

let postData = querystring.stringify({
  'firstname': req.body.firstname,
  'lastname': req.body.lastname,
  'linkedin_profile': req.body.linkedin_profile ,
  'careers_job_category': req.body.careers_job_category,
  'hs_context': JSON.stringify({
    "hutk": req.cookies.hubspotutk,
    "ipAddress": req.headers['x-forwarded-for'] || req.connection.remoteAddress,
    "pageUrl": "",
    "pageName": "Careers Job Category Page"

let options = {
  hostname: '',
  path: '/uploads/form/v2/xxxxxx/xxxxxxxxxxxxxx',
  method: 'POST',
  headers: {
    'Content-Type': 'application/x-www-form-urlencoded',
    'Content-Length': postData.length

let request = https.request(options, function(response){
  response.on('data', function(chunk){
    console.log('Body: ' + chunk)

request.on('error', function(e){
  console.log('Problem with request ' + e.message)



Hey @klyncheski,

The Forms API doesn’t respond with any content so when you are doing a res.json() it’s trying to take an empty response and turn it into a JSON encoded string.

If you update your node endpoint to write back to your React app with the information it sent to HubSpot rather than the response it gets back from HubSpot (which won’t be anything) it should work.



Thanks @zwolfson ! That makes a lot of sense. I’m probably missing this because I’ve been staring at the code too long, but where would I update the endpoint to send the data back?


That depends on the framework (if any) you are using to create your webserver. For example if you were using Express you might have a handler that looks like'/careers-submission'){ (req, res) => {

You would want to adjust that body variable in this case.