POST form to external API

Hi, hoping someone can help me post form data to an external API. This is the demo contact form method from the gatsby-starter-netlify-cms which handles the submission:

handleSubmit = e => {
e.preventDefault()
const form = e.target
fetch('/', {
  method: 'POST',
  headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
  body: encode({
    'form-name': form.getAttribute('name'),
    ...this.state,
  }),
})
  .then(() => navigate(form.getAttribute('action')))
  .catch(error => alert(error))

}

I’ve set the action of the form to https://crm.zoho.eu/crm/WebToLeadForm however, the form is posting to http://localhost:8000/https:/crm.zoho.eu/crm/WebToLeadForm

<form
 name="WebToLeads"
 method="post"
 action="https://crm.zoho.eu/crm/WebToLeadForm"
 data-netlify="true"
 data-netlify-honeypot="bot-field"
 onSubmit={this.handleSubmit}

Hey and welcome :slight_smile: Is this when you test locally or in production? If it’s up and running, could you please share a link to your Netlify URL so we can take a look? If it’s local, I would try pushing to Netlify to see if works there- there might be a local dev step that is prepending localhost to your form action but won’t in production.

Let me know how it goes and we can go from there!

Hey,

Thanks for your reply. I’ve tried it in Production and it’s the same too. Inspecting the page, the form action is Zoho | Cloud Software Suite for Businesses so that’s correct.

Unless you are POSting to Netlify, don’t use that plugin would be my advice. It’s intended to setup a form to POST to us, not to somewhere else. You should write a “normal” form to post elsewhere :slight_smile: