Registration form connected to an external API

Hi I am new to wix and have read the documentation regarding Fetch but it is not entirely clear to me.

I need to create a registration form and use the POST method to send the data to an external API. I already have the form but I don’t know how to make the connection to the API, if you could help me with this would be very helpful.

Thank you.

First on button click retrieve the data from the input fields (don’t use a ready-made form which might be limited. Put the input fields yourself).

import {fetch} from 'wix-fetch';
$w.onReady(() => {
$w("#submitButton").onClick(() => {
let data = `name=${$w("#nameInput").value}&email=${$w("#emailInput").value}`;
fetch( "https://third-party.com", {
  "method": "post",
  "headers": {
    "Content-Type": "application/x-www-form-urlencoded"
  },
  "body": encodeURI(data);
} )
  .then( (response) => {
    if (response.ok) {
      //show success message
    } else {
      //show error message
    }
  } )
})
})

For example (maybe they are expecting to json or something else. Look at their documentation.

thanks i will put it into practice