Fetch post form data using API

I am trying to set up my website so that when a customer fills out a form, it sends their submission via API to another source I have. I am having a hard time getting the post api set up properly. I have the form-data module installed. I think I have the back end set up properly, but I’m not sure how to get it working with the front end and actually send the info I need.

Front end code:

import {sendQuote} from ‘backend/test.jsw’ ;

export function button8_click(event) {
sendQuote (
$w( ‘#input4’ ).value,
$w( ‘#input3’ ).value,
$w( ‘#input2’ ).value,
$w( ‘#input1’ ).value)
.then( function () {
console.log( “Form information was sent” );
}
);
}

Back end code:

import {fetch} from ‘wix-fetch’ ;
import FormData from ‘form-data’ ;

function createBody(name, phone, email, state) {
const form = new FormData();

form.append( ‘name’ , name);
form.append( ‘phone’ , phone);
form.append( ‘email’ , email);
form.append( ‘state’ , state);

return form
}

export function sendQuote(name, phone, email, state) {
return fetch( “https://myurl” , {
“method” : “post” ,
“headers” : {
“Content-Type” : “application/x-www-form-urlencoded”
},
“body” : createBody(name, phone, email, state)
}).then( (httpResponse) => {
if (httpResponse.ok) {
return httpResponse.json();
} else {
return Promise.reject( “Fetch did not succeed” );
}
} )
.then( (json) => console.log(json.someKey) )
. catch (err => console.log(err));
}

@jscholes did you get this working, I am trying to send video to my external API, please let me know.

Please add your own issue into a new post instead of bumping up an old post. Explain what you are trying to do, what works, and what doesn’t. Also, add any code in a code block as stated in the Forum Guidelines .

This is an old post and is being closed.