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!
Thanks!
KL
Here is the function that gets called onSubmit of the form:
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