Send form input to external CRM

HI! I need send the user input data to import into my CRM system. It is nice to have the wix database as a backup but in order for our sales team to work efficiently, I need the data the user enters into the form fields to be sent to our other CRM system. What code would I need to use?

I matched the CRM id names to the Wix Database/field id names, for example:
id=“fname, lname, email, phone, city, state, zip, analyte, analyte2, analyte_text, weight, dob, test_result”

then something like … action=“customer.i” method=“GET” onSubmit=“return checkform()”

Please help me fill in the blanks so that I get this to work. Thank you!

Ok I really need some additional input on this. I have been going through videos and other resource, but none of them tell me how to get the textinput to go into another database outside of wix. What is that command??
Here are some starting points:
1. Define each text input line item to do something
export function qualifyform_ready() {
//Add your code for this event here:
$w(“#fname”).result(where do I send the data? it needs to go directly into the database - located here: h idden );
$w(“#lname”).onChange(would this one read better? where do I send the data? );
$w(“#email”).enable(where/how?..);
$w(“#phone”)
$w(“#city”).toString(where/how?..);
$w(“#state”)
$w(“#zip”)
$w(“#analyte”)
$w(“#analyte2”)
$w(“#anlaytetext”)
$w(“#weight”)
$w(“#dob”)
$w(“#testresult”)
}

**2. ** Define the text input fields all together – not all are required.
export function qualifyform_afterSave() {
//Add your code for this event here:
$w(“#fname”,“lname”,“email”,“phone”,“city”,“state”,“zip”,“analyte”,“weight”,“analyte2”,“dob”,“analytetext”,“testresult”).enable(export? to… * export not recognized );

}
**3. ** Or maybe this is a better one
export function submit_click(event, $w) {
//Add your code for this event here:
$w(“#submit”).toString(" https://biolynk.com. …" this one is showing errors…);
}

what you need is a REST API from your CRM provider that you can send your data to.
there are many ways to achieve that. I think the fastest one would be using the afterInsert API (Hooks - Velo API Reference - Wix.com ) and using fetch API to send to your CRM. (wix-fetch - Velo API Reference - Wix.com)

Thank you Moshe! That got me closer, but still there are holes. After I sent the CRM guys your note, below is what they sent me:
http://www.biolynk.com/customer.i ?
cmd=add&
type=rest&
fname=[fname]&
lname=[lname]&
dob=[dob]&
weight=[weight]&
city=[city]&
state=[state]&
zipcode=[zipcode]&
phone=[phone]&
email=[email]&
analyte=[analyte]&
analyte2=[analyte2]&
analyte_text=[analyte_text]&
testresults=[testresults]&
other=[other]&

They did not put it into code language, so I am guessing the code should something like this, but I do not know where to put these two elements…and so this is obviously not working.
cmd=add&
type=rest&

export function QualifyForm_afterInsert(item, context) {
let hookContext = context;
item.fname=[fname]& + item.lname=[lname]& + item.dob=[dob]& + item.weight=[weight]& + item.city=[city]& + item.state=[state]& + item.zipcode=[zipcode]& + item.phone=[phone]& + item.email=[email]& + item.analyte=[analyte]& + item.analyte2=[analyte2]& + item.analytetext=[analyte_text]& + item.testresult=[testresults]&;
return item;
}

import {fetch} from ‘http://www.biolynk.com/customer.i?’;
// …
fetch(‘http://www.biolynk.com/customer.i?’, {method: ‘get’})
.then( (httpResponse) => {
let url = “http://www.biolynk.com/customer.i?cmd=add&type=rest&]”;

};

PLEASE HELP!

cmd=add&
type=rest&
are just static parameters that specify the command and that it’s a REST protocol.

I must say that the entire code you wrote here will not work, it has a lot of bugs,
I would like to kindly recommend you to seek the help of a pro at the Wix Arena .

Can I hire you?

Moshe is a Wix Employee so I don’t think you can hire him but there are a lot of talented people in wix arena, try

Hi Kim, thanks for your reply. But as shantanukumar847 said, Im a Wix employee so thats not possivle. Please do try the arena!

So I have tried the arena and no one is accepting or responding. What are my options now??

this is important also to me. Is anybody willing to help and make an example? Thank you

Hi Kim:

To start with you need to use the wix-fetch API. wix-fetch - Velo API Reference - Wix.com
When you look at the API you will see that there are two arguments to the fetch function:

function fetch(url: string, [options: WixFetchRequest]):Promise<WixFetchResponse>

The URL is the one your CRM guys gave you - http://www.biolynk.com/customer.i
Now to complete the request per the CRM guy’s recommendation you need to go through each of the CRM properties you want to send and add the key value pairs to the end of the url.

To get you started try building this out:

import {fetch} from 'wix-fetch';

let crmApiURL = 'http://www.biolynk.com/customer.i?cmd=add&type=rest';
let apiQuery = '';
if ($w("#fname").value !== null && $w("#fname").value.length > 0) {
     crmApiURL += addQuery(crmApiURL) + '&fname=['+$w("#fname").value+']';
}
if ($w("#lname").value !== null && $w("#lname").value.length > 0) {
     crmApiURL += addQuery(crmApiURL) + '&lname=['+$w("#lname").value+']';
}
if ($w("#phone").value !== null && $w("#phone").value.length > 0) {
    crmApiURL += addQuery(crmApiURL) + '&phone=['+$w("#phone").value+']';
}
// etc. for each property
fetch(crmApiURL, {method: 'get'})
// Check the result and manage errors - check the documentation for wix-fetch out
.then((fetchResult) => {
    //Check to make sure the request was successful
})
.catch((error) => {
    console.log(error);
});

Hope this helps

Steve

Hi Steve!
Thank you! I was able to start with your code and make a few adjustments and now the URL will properly build!! >> Now I just need this newly constructed URL to send out somehow so that my CRM will pick it up. Right now I can see the URL in my console log (using the code below)

Here is what the code ended up as:


Then the console log reads:


When I publish the site and complete the form, I go to my thank you page, but the data is not inserted into my CRM.

Can you help me push this URL out?

Hi Kim:
Is there an online page with the API spec that you need to use?

Typically if you are sending information to a web application to be stored or updated you need to use the method ‘post’ or ‘put’. Check out this web page .

You might want to try changing the method on line 27 to ‘post’. If that doesn’t work try ‘put’. These verbs are important so if you can get the full specification for the API that will be helpful.

Good luck!
Steve

did you ever get this to work? I need something very similar done

Hello everyone, can anyone help me with my code? I’m unable to send my Form’s input to the external CRM.

$w . onReady ( function () {

});

import { fetch } from ‘wix-fetch’ ;

export function submit_click ( event , $w ){
let crmApiURL = ‘’;
let apiQuery = ‘’ ;
if ( $w ( “#fname” ). value !== null && $w ( “#fname” ). value . length > 0 ) {
crmApiURL += ‘&fname=[’ + $w ( “#fname” ). value + ‘]’ ;
}

if ( $w ( “#phone” ). value !== null && $w ( “#phone” ). value . length > 0 ) {
crmApiURL += ‘&phone=[’ + $w ( “#phone” ). value + ‘]’ ;
}

if ( $w ( “#email” ). value !== null && $w ( “#email” ). value . length > 0 ) {
crmApiURL += ‘&phone=[’ + $w ( “#email” ). value + ‘]’ ;
}

let fullURL = crmApiURL + apiQuery
fetch ( fullURL , { method : ‘post’ })
. then (() => {
})
}

What is the crmApiURL? At the moment it is set to “”.

You need to have an http endpoint to send the queries to :slight_smile:

If you don’t understand this point you probably need to spend a little more time learning advanced JavaScript, the fetch API and the documentation for your external CRM

Ok sir, thanks for your help.